From e041df73bb7bf424bcf571f25e3459359c4f36ed Mon Sep 17 00:00:00 2001 From: Matt Wozniski Date: Thu, 9 May 2019 03:19:29 -0400 Subject: Add tests for overflows converting ints to bytes --- tests/basics/int_bytes_intbig.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'tests/basics/int_bytes_intbig.py') diff --git a/tests/basics/int_bytes_intbig.py b/tests/basics/int_bytes_intbig.py index ce6fec40a..b19c8ae53 100644 --- a/tests/basics/int_bytes_intbig.py +++ b/tests/basics/int_bytes_intbig.py @@ -15,3 +15,15 @@ print(ib.to_bytes(20, "big")) # check that extra zero bytes don't change the internal int value print(int.from_bytes(b + bytes(10), "little") == int.from_bytes(b, "little")) + +# too small buffer should raise an error +try: + (2**64).to_bytes(8, "little") +except OverflowError: + print("OverflowError") + +# negative numbers should raise an error +try: + (-2**64).to_bytes(9, "little") +except OverflowError: + print("OverflowError") -- cgit v1.2.3