Skip to content

Commit ed6a1ad

Browse files
rguillondpgeorge
authored andcommitted
tests/basics: Add a test file for overriding special methods.
1 parent d2cc7c7 commit ed6a1ad

File tree

1 file changed

+153
-0
lines changed

1 file changed

+153
-0
lines changed

tests/basics/special_methods.py

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
class Cud():
2+
3+
def __init__(self):
4+
print("__init__ called")
5+
6+
def __repr__(self):
7+
print("__repr__ called")
8+
return ""
9+
10+
def __lt__(self, other):
11+
print("__lt__ called")
12+
13+
def __le__(self, other):
14+
print("__le__ called")
15+
16+
def __eq__(self, other):
17+
print("__eq__ called")
18+
19+
def __ne__(self, other):
20+
print("__ne__ called")
21+
22+
def __ge__(self, other):
23+
print("__ge__ called")
24+
25+
def __gt__(self, other):
26+
print("__gt__ called")
27+
28+
def __abs__(self):
29+
print("__abs__ called")
30+
31+
def __add__(self, other):
32+
print("__add__ called")
33+
34+
def __and__(self, other):
35+
print("__and__ called")
36+
37+
def __floordiv__(self, other):
38+
print("__floordiv__ called")
39+
40+
def __index__(self, other):
41+
print("__index__ called")
42+
43+
def __inv__(self):
44+
print("__inv__ called")
45+
46+
def __invert__(self):
47+
print("__invert__ called")
48+
49+
def __lshift__(self, val):
50+
print("__lshift__ called")
51+
52+
def __mod__(self, val):
53+
print("__mod__ called")
54+
55+
def __mul__(self, other):
56+
print("__mul__ called")
57+
58+
def __matmul__(self, other):
59+
print("__matmul__ called")
60+
61+
def __neg__(self):
62+
print("__neg__ called")
63+
64+
def __or__(self, other):
65+
print("__or__ called")
66+
67+
def __pos__(self):
68+
print("__pos__ called")
69+
70+
def __pow__(self, val):
71+
print("__pow__ called")
72+
73+
def __rshift__(self, val):
74+
print("__rshift__ called")
75+
76+
def __sub__(self, other):
77+
print("__sub__ called")
78+
79+
def __truediv__(self, other):
80+
print("__truediv__ called")
81+
82+
def __div__(self, other):
83+
print("__div__ called")
84+
85+
def __xor__(self, other):
86+
print("__xor__ called")
87+
88+
cud1 = Cud()
89+
cud2 = Cud()
90+
str(cud1)
91+
cud1 < cud2
92+
cud1 <= cud2
93+
cud1 == cud2
94+
cud1 >= cud2
95+
cud1 > cud2
96+
cud1 + cud2
97+
98+
# TODO: the following operations are not supported on every ports
99+
#
100+
# ne is not supported, !(eq) is called instead
101+
#cud1 != cud2
102+
#
103+
# binary and is not supported
104+
# cud1 & cud2
105+
#
106+
# floor div is not supported on the qemu arm port
107+
# cud2 // cud1
108+
#
109+
# inv is not supported on the qemu arm port
110+
# ~cud1
111+
#
112+
# binary lshift is not supported
113+
# cud1<<1
114+
#
115+
# modulus is not supported
116+
# cud1 % 2
117+
#
118+
# mult is not supported on the qemu arm port
119+
# cud1 * cud2
120+
#
121+
# mult is not supported on the qemu arm port
122+
# cud1 * 2
123+
#
124+
# inv is not supported on the qemu arm port
125+
# -cud1
126+
#
127+
# binary or is not supported
128+
# cud1 | cud2
129+
#
130+
# pos is not supported on the qemu arm port
131+
# +cud1
132+
#
133+
# pow is not supported
134+
# cud1**2
135+
#
136+
# rshift is not suported
137+
# cud1>>1
138+
#
139+
# sub is not supported on the qemu arm port
140+
# cud1 - cud2
141+
#
142+
# div is not supported on the qemu arm port
143+
# cud1 / cud2
144+
#
145+
# div is not supported on the qemu arm port
146+
# cud1 / 2
147+
#
148+
# xor is not supported
149+
# cud1^cud2
150+
#
151+
# in the followin test, cpython still calls __eq__
152+
# cud3=cud1
153+
# cud3==cud1

0 commit comments

Comments
 (0)