Skip to content

Commit

Permalink
tests/basics/special_methods: Add testcases for __int__.
Browse files Browse the repository at this point in the history
  • Loading branch information
pfalcon authored and dpgeorge committed Dec 7, 2018
1 parent b1d0872 commit d690c2e
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tests/basics/special_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ def __isub__(self, other):
print("__isub__ called")
return self

def __int__(self):
return 42

cud1 = Cud()
cud2 = Cud()

Expand All @@ -104,5 +107,16 @@ def __isub__(self, other):
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

0 comments on commit d690c2e

Please sign in to comment.