diff options
author | rguillon <rguillon@users.sourceforce.net> | 2016-08-14 17:59:47 +0200 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2016-08-17 12:11:32 +1000 |
commit | ed6a1ada2470617cb4fd4a65b0947ae982cfe927 (patch) | |
tree | 9e8492711bd88762b876021ad2123850ed3bb5d5 /tests/basics/special_methods.py | |
parent | d2cc7c720b3c6cd0f48f235a04d2e0bb740dad44 (diff) | |
download | micropython-ed6a1ada2470617cb4fd4a65b0947ae982cfe927.tar.gz micropython-ed6a1ada2470617cb4fd4a65b0947ae982cfe927.zip |
tests/basics: Add a test file for overriding special methods.
Diffstat (limited to 'tests/basics/special_methods.py')
-rw-r--r-- | tests/basics/special_methods.py | 153 |
1 files changed, 153 insertions, 0 deletions
diff --git a/tests/basics/special_methods.py b/tests/basics/special_methods.py new file mode 100644 index 0000000000..b4eb8710d3 --- /dev/null +++ b/tests/basics/special_methods.py @@ -0,0 +1,153 @@ +class Cud(): + + def __init__(self): + print("__init__ called") + + def __repr__(self): + print("__repr__ called") + return "" + + def __lt__(self, other): + print("__lt__ called") + + def __le__(self, other): + print("__le__ called") + + def __eq__(self, other): + print("__eq__ called") + + def __ne__(self, other): + print("__ne__ called") + + def __ge__(self, other): + print("__ge__ called") + + def __gt__(self, other): + print("__gt__ called") + + def __abs__(self): + print("__abs__ called") + + def __add__(self, other): + print("__add__ called") + + def __and__(self, other): + print("__and__ called") + + def __floordiv__(self, other): + print("__floordiv__ called") + + def __index__(self, other): + print("__index__ called") + + def __inv__(self): + print("__inv__ called") + + def __invert__(self): + print("__invert__ called") + + def __lshift__(self, val): + print("__lshift__ called") + + def __mod__(self, val): + print("__mod__ called") + + def __mul__(self, other): + print("__mul__ called") + + def __matmul__(self, other): + print("__matmul__ called") + + def __neg__(self): + print("__neg__ called") + + def __or__(self, other): + print("__or__ called") + + def __pos__(self): + print("__pos__ called") + + def __pow__(self, val): + print("__pow__ called") + + def __rshift__(self, val): + print("__rshift__ called") + + def __sub__(self, other): + print("__sub__ called") + + def __truediv__(self, other): + print("__truediv__ called") + + def __div__(self, other): + print("__div__ called") + + def __xor__(self, other): + print("__xor__ called") + +cud1 = Cud() +cud2 = Cud() +str(cud1) +cud1 < cud2 +cud1 <= cud2 +cud1 == cud2 +cud1 >= cud2 +cud1 > cud2 +cud1 + cud2 + +# TODO: the following operations are not supported on every ports +# +# ne is not supported, !(eq) is called instead +#cud1 != cud2 +# +# binary and is not supported +# cud1 & cud2 +# +# floor div is not supported on the qemu arm port +# cud2 // cud1 +# +# inv is not supported on the qemu arm port +# ~cud1 +# +# binary lshift is not supported +# cud1<<1 +# +# modulus is not supported +# cud1 % 2 +# +# mult is not supported on the qemu arm port +# cud1 * cud2 +# +# mult is not supported on the qemu arm port +# cud1 * 2 +# +# inv is not supported on the qemu arm port +# -cud1 +# +# binary or is not supported +# cud1 | cud2 +# +# pos is not supported on the qemu arm port +# +cud1 +# +# pow is not supported +# cud1**2 +# +# rshift is not suported +# cud1>>1 +# +# sub is not supported on the qemu arm port +# cud1 - cud2 +# +# div is not supported on the qemu arm port +# cud1 / cud2 +# +# div is not supported on the qemu arm port +# cud1 / 2 +# +# xor is not supported +# cud1^cud2 +# +# in the followin test, cpython still calls __eq__ +# cud3=cud1 +# cud3==cud1 |