summaryrefslogtreecommitdiff
path: root/tests/basics/smallint_array_overflow.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/basics/smallint_array_overflow.py')
-rw-r--r--tests/basics/smallint_array_overflow.py52
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/basics/smallint_array_overflow.py b/tests/basics/smallint_array_overflow.py
new file mode 100644
index 000000000..25b457cca
--- /dev/null
+++ b/tests/basics/smallint_array_overflow.py
@@ -0,0 +1,52 @@
+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')
+
+def test_bytearray_overflow(val):
+ try:
+ print(bytearray([val]))
+ except (OverflowError, ValueError):
+ # CircuitPython always does OverflowError
+ print('(OverflowError, ValueError)')
+
+
+# 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)
+
+# 0 ok
+test_array_overflow('Q', 0)
+test_array_overflow('L', 0)
+test_array_overflow('I', 0)
+test_array_overflow('H', 0)
+test_array_overflow('B', 0)
+
+# 1 ok
+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)
+
+# truth value conversions
+test_array_overflow('b', True)
+test_array_overflow('b', False)
+
+# similar tests for bytearrays
+test_bytearray_overflow(0)
+test_bytearray_overflow(1)
+test_bytearray_overflow(-1)
+test_bytearray_overflow(256)
+test_bytearray_overflow(True)
+test_bytearray_overflow(False)