Skip to content

Commit d007cb8

Browse files
committed
tests: Add more tests to improve coverage, mostly testing exceptions.
1 parent d292a81 commit d007cb8

19 files changed

+260
-4
lines changed

tests/basics/builtin_issubclass.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# test builtin issubclass
2+
3+
class A:
4+
pass
5+
6+
print(issubclass(A, A))
7+
print(issubclass(A, (A,)))
8+
9+
try:
10+
issubclass(A, 1)
11+
except TypeError:
12+
print('TypeError')
13+
14+
try:
15+
issubclass('a', 1)
16+
except TypeError:
17+
print('TypeError')

tests/basics/builtin_property.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,20 @@ def x(self):
7676
c.x = 6
7777
print(c.x)
7878
del c.x
79+
80+
# a property that has no get, set or del
81+
class D:
82+
prop = property()
83+
d = D()
84+
try:
85+
d.prop
86+
except AttributeError:
87+
print('AttributeError')
88+
try:
89+
d.prop = 1
90+
except AttributeError:
91+
print('AttributeError')
92+
try:
93+
del d.prop
94+
except AttributeError:
95+
print('AttributeError')

tests/basics/builtin_type.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# test builtin type
2+
3+
print(type(int))
4+
5+
try:
6+
type()
7+
except TypeError:
8+
print('TypeError')
9+
10+
try:
11+
type(1, 2)
12+
except TypeError:
13+
print('TypeError')

tests/basics/bytes_construct.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,9 @@
1414

1515
# long ints
1616
print(ord(bytes([14953042807679334000 & 0xff])))
17+
18+
# error in construction
19+
try:
20+
a = bytes([1, 2, 3], 1)
21+
except TypeError:
22+
print('TypeError')

tests/basics/bytes_subscr.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# test [...] of bytes
2+
3+
print(b'123'[0])
4+
print(b'123'[1])
5+
print(b'123'[-1])
6+
7+
try:
8+
b'123'[1] = 4
9+
except TypeError:
10+
print('TypeError')
11+
12+
try:
13+
del b'123'[1]
14+
except TypeError:
15+
print('TypeError')

tests/basics/class2.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,12 @@ def __init__(self, x):
1515
c2 = C2(4)
1616
print(type(c2) == C2)
1717
print(c2.x)
18+
19+
# __init__ should return None
20+
class C3:
21+
def __init__(self):
22+
return 10
23+
try:
24+
C3()
25+
except TypeError:
26+
print('TypeError')

tests/basics/class_new.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,8 @@ def meth(self):
2525
# __new__ should automatically be a staticmethod, so this should work
2626
a = a.__new__(A)
2727
a.meth()
28+
29+
class B:
30+
def __new__(self, v1, v2):
31+
None
32+
B(1, 2)

tests/basics/class_super.py

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

1515
a = Sub()
1616
a.meth()
17+
18+
# printing super
19+
class A:
20+
def p(self):
21+
print(str(super())[:18])
22+
A().p()

tests/basics/set_binop.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# test set binary operations
2+
13
sets = [set(), {1}, {1, 2}, {1, 2, 3}, {2, 3}, {2, 3, 5}, {5}, {7}]
24
for s in sets:
35
for t in sets:
@@ -24,3 +26,10 @@
2426
print(sorted(s), '>=', sorted(t), '=', s >= t)
2527
print(sorted(s), '<', sorted(t), '=', s < t)
2628
print(sorted(s), '<=', sorted(t), '=', s <= t)
29+
30+
print(set('abc') == 1)
31+
32+
try:
33+
set('abc') * 2
34+
except TypeError:
35+
print('TypeError')

tests/basics/set_unop.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# test set unary operations
2+
3+
print(bool(set()))
4+
print(bool(set('abc')))
5+
6+
print(len(set()))
7+
print(len(set('abc')))
8+
9+
try:
10+
hash(set('abc'))
11+
except TypeError:
12+
print('TypeError')

0 commit comments

Comments
 (0)