Skip to content

Commit e9404e5

Browse files
committed
tests: Improve coverage of array, range, dict, slice, exc, unicode.
1 parent 453c2e8 commit e9404e5

File tree

9 files changed

+87
-2
lines changed

9 files changed

+87
-2
lines changed

tests/basics/array1.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
print(bool(array.array('i')))
2222
print(bool(array.array('i', [1])))
2323

24+
# containment, with incorrect type
25+
print('12' in array.array('B', b'12'))
26+
print([] in array.array('B', b'12'))
27+
2428
# bad typecode
2529
try:
2630
array.array('X')

tests/basics/builtin_range.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,9 @@
5050
range(1)[0] = 1
5151
except TypeError:
5252
print("TypeError")
53+
54+
# bad attr (can't store)
55+
try:
56+
range(4).start = 0
57+
except AttributeError:
58+
print('AttributeError')

tests/basics/dict1.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,27 @@
1616
d[x] = x
1717
x += 1
1818
print(d[50])
19+
20+
# equality operator on dicts of different size
21+
print({} == {1:1})
22+
23+
# equality operator on dicts of same size but with different keys
24+
print({1:1} == {2:1})
25+
26+
# value not found
27+
try:
28+
{}[0]
29+
except KeyError:
30+
print('KeyError')
31+
32+
# unsupported unary op
33+
try:
34+
+{}
35+
except TypeError:
36+
print('TypeError')
37+
38+
# unsupported binary op
39+
try:
40+
{} + {}
41+
except TypeError:
42+
print('TypeError')

tests/basics/dict_views.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,19 @@
33
print(m())
44
print(list(m()))
55

6+
# print a view with more than one item
7+
print({1:1, 2:1}.values())
8+
9+
# unsupported binary op on a dict values view
10+
try:
11+
{1:1}.values() + 1
12+
except TypeError:
13+
print('TypeError')
14+
15+
# unsupported binary op on a dict keys view
16+
try:
17+
{1:1}.keys() + 1
18+
except TypeError:
19+
print('TypeError')
20+
621
# set operations still to come

tests/basics/int_constfolding.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,8 @@
3838
print(123 // -7, 123 % -7)
3939
print(-123 // -7, -123 % -7)
4040

41+
# zero big-num on rhs
42+
print(1 + ((1 << 65) - (1 << 65)))
43+
44+
# negative big-num on rhs
45+
print(1 + (-(1 << 65)))

tests/basics/slice_attrs.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,12 @@ def __getitem__(self, idx):
1414

1515

1616
A()[1:2:3]
17+
18+
# test storing to attr (shouldn't be allowed)
19+
class B:
20+
def __getitem__(self, idx):
21+
try:
22+
idx.start = 0
23+
except AttributeError:
24+
print('AttributeError')
25+
B()[:]

tests/misc/non_compliant.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
except SyntaxError:
1010
print('SyntaxError')
1111

12+
# store to exception attribute is not allowed
13+
try:
14+
ValueError().x = 0
15+
except AttributeError:
16+
print('AttributeError')
17+
1218
# array deletion not implemented
1319
try:
1420
a = array.array('b', (1, 2, 3))
@@ -23,6 +29,12 @@
2329
except NotImplementedError:
2430
print('NotImplementedError')
2531

32+
# containment, looking for integer not implemented
33+
try:
34+
print(1 in array.array('B', b'12'))
35+
except NotImplementedError:
36+
print('NotImplementedError')
37+
2638
# should raise type error
2739
try:
2840
print(set('12') >= '1')
@@ -65,6 +77,12 @@
6577
except NotImplementedError:
6678
print('NotImplementedError')
6779

80+
# str subscr with step!=1 not implemented
81+
try:
82+
print('abc'[1:2:3])
83+
except NotImplementedError:
84+
print('NotImplementedError')
85+
6886
# bytes(...) with keywords not implemented
6987
try:
7088
bytes('abc', encoding='utf8')

tests/misc/non_compliant.py.exp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
SyntaxError
2+
AttributeError
23
TypeError
34
NotImplementedError
5+
NotImplementedError
46
True
57
True
68
TypeError, ValueError
@@ -13,5 +15,6 @@ NotImplementedError
1315
NotImplementedError
1416
NotImplementedError
1517
NotImplementedError
18+
NotImplementedError
1619
b'\x01\x02'
1720
b'\x01\x00'

tests/unicode/unicode.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@
1818
print(enc, enc.decode() == s)
1919

2020
# printing of unicode chars using repr
21-
# TODO we don't do this correctly
22-
#print(repr(s))
21+
# NOTE: for some characters (eg \u10ff) we differ to CPython
22+
print(repr('a\uffff'))
23+
print(repr('a\U0001ffff'))
2324

2425
# test invalid escape code
2526
try:

0 commit comments

Comments
 (0)