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.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'tests/basics/int_bytes.py') diff --git a/tests/basics/int_bytes.py b/tests/basics/int_bytes.py index 059c16d3f..8c0c9a82f 100644 --- a/tests/basics/int_bytes.py +++ b/tests/basics/int_bytes.py @@ -17,3 +17,15 @@ try: (1).to_bytes(-1, "little") except ValueError: print("ValueError") + +# too small buffer should raise an error +try: + (256).to_bytes(1, "little") +except OverflowError: + print("OverflowError") + +# negative numbers should raise an error +try: + (-256).to_bytes(2, "little") +except OverflowError: + print("OverflowError") -- cgit v1.2.3