Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
micropython/tests/float/complex_dunder.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
46 lines (29 sloc)
635 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# test __complex__ function support | |
class TestFloat: | |
def __float__(self): | |
return 1.0 | |
class TestComplex: | |
def __complex__(self): | |
return 1j + 10 | |
class TestStrComplex: | |
def __complex__(self): | |
return "a" | |
class TestNonComplex: | |
def __complex__(self): | |
return 6 | |
class Test: | |
pass | |
print(complex(TestFloat())) | |
print(complex(TestComplex())) | |
try: | |
print(complex(TestStrComplex())) | |
except TypeError: | |
print("TypeError") | |
try: | |
print(complex(TestNonComplex())) | |
except TypeError: | |
print("TypeError") | |
try: | |
print(complex(Test())) | |
except TypeError: | |
print("TypeError") |