summaryrefslogtreecommitdiff
path: root/tests/basics/smallint_array_overflow.py
blob: 25b457cca1d978f1e9598ab64da74c35fd397370 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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)