Skip to content

Commit 36f7952

Browse files
committed
tests: Add tests to improve coverage of py/objtype.c.
1 parent badaf3e commit 36f7952

5 files changed

Lines changed: 53 additions & 0 deletions

File tree

tests/basics/class_inherit_mul.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# test multiple inheritance of user classes
2+
13
class A:
24
def __init__(self, x):
35
print('A init', x)
@@ -30,6 +32,9 @@ def __init__(self):
3032
def g(self):
3133
print(self.x)
3234

35+
print(issubclass(Sub, A))
36+
print(issubclass(Sub, B))
37+
3338
o = Sub()
3439
print(o.x)
3540
o.f()
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# test super with multiple inheritance
2+
3+
class A:
4+
def foo(self):
5+
print('A.foo')
6+
7+
class B:
8+
def foo(self):
9+
print('B.foo')
10+
11+
class C(A, B):
12+
def foo(self):
13+
print('C.foo')
14+
super().foo()
15+
16+
C().foo()

tests/basics/sys_getsizeof.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# test sys.getsizeof() function
2+
3+
import sys
4+
try:
5+
sys.getsizeof
6+
except AttributeError:
7+
print('SKIP')
8+
raise SystemExit
9+
10+
print(sys.getsizeof([1, 2]) >= 2)
11+
print(sys.getsizeof({1: 2}) >= 2)
12+
13+
class A:
14+
pass
15+
print(sys.getsizeof(A()) > 0)

tests/misc/non_compliant.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,18 @@ def f():
124124
f.x = 1
125125
except AttributeError:
126126
print('AttributeError')
127+
128+
# can't call a function type (ie make new instances of a function)
129+
try:
130+
type(f)()
131+
except TypeError:
132+
print('TypeError')
133+
134+
# test when object explicitly listed at not-last position in parent tuple
135+
# this is not compliant with CPython because of illegal MRO
136+
class A:
137+
def foo(self):
138+
print('A.foo')
139+
class B(object, A):
140+
pass
141+
B().foo()

tests/misc/non_compliant.py.exp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,5 @@ b'\x01\x02'
1818
b'\x01\x00'
1919
NotImplementedError
2020
AttributeError
21+
TypeError
22+
A.foo

0 commit comments

Comments
 (0)