Skip to content

Commit e5c4362

Browse files
committed
tests: Add some more tests to improve code coverage of corner cases.
1 parent 97abe22 commit e5c4362

6 files changed

Lines changed: 53 additions & 3 deletions

File tree

tests/basics/builtin_range.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
# print
44
print(range(4))
55

6+
# bool
7+
print(bool(range(0)))
8+
print(bool(range(10)))
9+
610
# len
711
print(len(range(0)))
812
print(len(range(4)))
@@ -29,3 +33,15 @@
2933
print(range(1, 2, 3).start)
3034
print(range(1, 2, 3).stop)
3135
print(range(1, 2, 3).step)
36+
37+
# bad unary op
38+
try:
39+
-range(1)
40+
except TypeError:
41+
print("TypeError")
42+
43+
# bad subscription (can't store)
44+
try:
45+
range(1)[0] = 1
46+
except TypeError:
47+
print("TypeError")

tests/basics/fun_error.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,6 @@ def test_exc(code, exc):
2929

3030
# function with keyword args not given a specific keyword arg
3131
test_exc("enumerate()", TypeError)
32+
33+
# kw given for positional, but a different positional is missing
34+
test_exc("def f(x, y): pass\nf(x=1)", TypeError)

tests/basics/getitem.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,13 @@ def __getitem__(self, index):
2020
next(it)
2121
except StopIteration:
2222
pass
23+
24+
# this class raises a non-StopIteration exception on iteration
25+
class A:
26+
def __getitem__(self, i):
27+
raise TypeError
28+
try:
29+
for i in A():
30+
pass
31+
except TypeError:
32+
print("TypeError")

tests/basics/namedtuple1.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,22 @@
4949
except TypeError:
5050
print("TypeError")
5151

52+
# enough args, but kw is wrong
53+
try:
54+
t = T(1, baz=3)
55+
except TypeError:
56+
print("TypeError")
57+
58+
# bad argument for member spec
59+
try:
60+
namedtuple('T', 1)
61+
except TypeError:
62+
print("TypeError")
63+
5264
# Try single string
53-
# Not implemented so far
54-
#T3 = namedtuple("TupComma", "foo bar")
55-
#t = T3(1, 2)
65+
T3 = namedtuple("TupComma", "foo bar")
66+
t = T3(1, 2)
67+
print(t.foo, t.bar)
5668

5769
# Try single string with comma field seperator
5870
# Not implemented so far

tests/basics/struct1.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,6 @@
3737
# check maximum unpack
3838
print(struct.unpack("<I", b"\xff\xff\xff\xff"))
3939
print(struct.unpack("<Q", b"\xff\xff\xff\xff\xff\xff\xff\xff"))
40+
41+
# network byte order
42+
print(struct.pack('!i', 123))

tests/extmod/zlibd_decompress.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,9 @@
2323
out = zlib.decompress(v, -15)
2424
assert(out == exp)
2525
print(exp)
26+
27+
# this should error
28+
try:
29+
zlib.decompress(b'abc')
30+
except Exception:
31+
print("Exception")

0 commit comments

Comments
 (0)