tests/basics/special_methods: Add testcases for __int__.

This commit is contained in:
Paul Sokolovsky 2018-08-29 18:27:20 +03:00 committed by Damien George
parent b1d08726ee
commit d690c2e148
1 changed files with 14 additions and 0 deletions

View File

@ -93,6 +93,9 @@ class Cud():
print("__isub__ called") print("__isub__ called")
return self return self
def __int__(self):
return 42
cud1 = Cud() cud1 = Cud()
cud2 = Cud() cud2 = Cud()
@ -104,5 +107,16 @@ cud1 >= cud2
cud1 > cud2 cud1 > cud2
cud1 + cud2 cud1 + cud2
cud1 - cud2 cud1 - cud2
print(int(cud1))
class BadInt:
def __int__(self):
print("__int__ called")
return None
try:
int(BadInt())
except TypeError:
print("TypeError")
# more in special_methods2.py # more in special_methods2.py