summaryrefslogtreecommitdiff
path: root/tests/basics/array_overflow.py
diff options
context:
space:
mode:
authorScott Shawcroft <scott@adafruit.com>2019-05-10 12:23:31 -0700
committerGitHub <noreply@github.com>2019-05-10 12:23:31 -0700
commitda2c88eaacf9c859cdda452a88ad5e552df98466 (patch)
treec4cd5e8110b976d5c74747e390fa067f8e01694a /tests/basics/array_overflow.py
parent46164c6ec6d6bc23feafbfce5b08e5307daac1f7 (diff)
parent67007282c9036cc81e6cea0fab5a4378bc3ae743 (diff)
Merge pull request #1860 from godlygeek/int_to_bytes_overflow_checks
Add overflow checks for int to bytes conversions
Diffstat (limited to 'tests/basics/array_overflow.py')
-rw-r--r--tests/basics/array_overflow.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/basics/array_overflow.py b/tests/basics/array_overflow.py
new file mode 100644
index 000000000..ba3eb7f06
--- /dev/null
+++ b/tests/basics/array_overflow.py
@@ -0,0 +1,35 @@
+import skip_if
+skip_if.no_bigint()
+
+try:
+ from array import array
+except ImportError:
+ print("SKIP")
+ raise SystemExit
+
+def test_array_overflow(typecode, val):
+ try:
+ print(array(typecode, [val]))
+ except OverflowError:
+ print('OverflowError')
+
+# small int -1
+test_array_overflow('Q', -1)
+test_array_overflow('L', -1)
+test_array_overflow('I', -1)
+test_array_overflow('H', -1)
+test_array_overflow('B', -1)
+
+# big int -1
+test_array_overflow('Q', -2**64 // 2**64)
+test_array_overflow('L', -2**64 // 2**64)
+test_array_overflow('I', -2**64 // 2**64)
+test_array_overflow('H', -2**64 // 2**64)
+test_array_overflow('B', -2**64 // 2**64)
+
+# big int 2**63
+test_array_overflow('q', 2**63)
+test_array_overflow('l', 2**63)
+test_array_overflow('i', 2**63)
+test_array_overflow('h', 2**63)
+test_array_overflow('b', 2**63)