Skip to content
Snippets Groups Projects
Commit e5c4362a authored by Damien George's avatar Damien George
Browse files

tests: Add some more tests to improve code coverage of corner cases.

parent 97abe229
No related branches found
No related tags found
No related merge requests found
......@@ -3,6 +3,10 @@
# print
print(range(4))
# bool
print(bool(range(0)))
print(bool(range(10)))
# len
print(len(range(0)))
print(len(range(4)))
......@@ -29,3 +33,15 @@ print(range(4)[1:-2:2])
print(range(1, 2, 3).start)
print(range(1, 2, 3).stop)
print(range(1, 2, 3).step)
# bad unary op
try:
-range(1)
except TypeError:
print("TypeError")
# bad subscription (can't store)
try:
range(1)[0] = 1
except TypeError:
print("TypeError")
......@@ -29,3 +29,6 @@ test_exc("[].sort(noexist=1)", TypeError)
# function with keyword args not given a specific keyword arg
test_exc("enumerate()", TypeError)
# kw given for positional, but a different positional is missing
test_exc("def f(x, y): pass\nf(x=1)", TypeError)
......@@ -20,3 +20,13 @@ try:
next(it)
except StopIteration:
pass
# this class raises a non-StopIteration exception on iteration
class A:
def __getitem__(self, i):
raise TypeError
try:
for i in A():
pass
except TypeError:
print("TypeError")
......@@ -49,10 +49,22 @@ try:
except TypeError:
print("TypeError")
# enough args, but kw is wrong
try:
t = T(1, baz=3)
except TypeError:
print("TypeError")
# bad argument for member spec
try:
namedtuple('T', 1)
except TypeError:
print("TypeError")
# Try single string
# Not implemented so far
#T3 = namedtuple("TupComma", "foo bar")
#t = T3(1, 2)
T3 = namedtuple("TupComma", "foo bar")
t = T3(1, 2)
print(t.foo, t.bar)
# Try single string with comma field seperator
# Not implemented so far
......
......@@ -37,3 +37,6 @@ print(struct.pack("<I", 0xffffffff))
# check maximum unpack
print(struct.unpack("<I", b"\xff\xff\xff\xff"))
print(struct.unpack("<Q", b"\xff\xff\xff\xff\xff\xff\xff\xff"))
# network byte order
print(struct.pack('!i', 123))
......@@ -23,3 +23,9 @@ exp = b"hello"
out = zlib.decompress(v, -15)
assert(out == exp)
print(exp)
# this should error
try:
zlib.decompress(b'abc')
except Exception:
print("Exception")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment