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

pull/1174/merge
Damien George 2015-04-05 00:03:43 +01:00
rodzic 97abe22963
commit e5c4362a98
6 zmienionych plików z 53 dodań i 3 usunięć

Wyświetl plik

@ -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")

Wyświetl plik

@ -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)

Wyświetl plik

@ -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")

Wyświetl plik

@ -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

Wyświetl plik

@ -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))

Wyświetl plik

@ -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")