summaryrefslogtreecommitdiff
path: root/tests/basics/smallint_array_overflow.py
diff options
context:
space:
mode:
authorDan Halbert <halbert@halwitz.org>2019-05-12 11:17:29 -0400
committerDan Halbert <halbert@halwitz.org>2019-05-12 11:17:29 -0400
commit8664a6574b4cb448df26bfaa0e12eb203cc5d759 (patch)
tree3fbbb02abd779ccb7e34f53b0b20d37a25b3e27c /tests/basics/smallint_array_overflow.py
parentd103ac1d6325a075be3fafe812858584435f3144 (diff)
use approx of original @godlygeek code for smallints; add tests
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)