summaryrefslogtreecommitdiff
path: root/tests/float
diff options
context:
space:
mode:
authorDamien George <damien@micropython.org>2020-06-22 10:21:02 +1000
committerDamien George <damien@micropython.org>2020-06-27 01:03:10 +1000
commit9f911d822ee97edaa94873823db5eb10c31f5f77 (patch)
treef09d51dcfa8481f2dce415e70b9efca9c528293b /tests/float
parent41fa8b5482089bdd7fa5478fe24f32913b23967c (diff)
py/objcomplex: Add mp_obj_get_complex_maybe for use in complex bin-op.
This allows complex binary operations to fail gracefully with unsupported operation rather than raising an exception, so that special methods work correctly. Signed-off-by: Damien George <damien@micropython.org>
Diffstat (limited to 'tests/float')
-rw-r--r--tests/float/cmath_fun.py6
-rw-r--r--tests/float/complex_special_mehods.py15
2 files changed, 21 insertions, 0 deletions
diff --git a/tests/float/cmath_fun.py b/tests/float/cmath_fun.py
index 7b5e69245..15b72e7a6 100644
--- a/tests/float/cmath_fun.py
+++ b/tests/float/cmath_fun.py
@@ -57,3 +57,9 @@ for f_name, f, test_vals in functions:
if abs(real) < 1e-6:
real = 0.0
print("complex(%.5g, %.5g)" % (real, ret.imag))
+
+# test invalid type passed to cmath function
+try:
+ log([])
+except TypeError:
+ print("TypeError")
diff --git a/tests/float/complex_special_mehods.py b/tests/float/complex_special_mehods.py
new file mode 100644
index 000000000..6789013fa
--- /dev/null
+++ b/tests/float/complex_special_mehods.py
@@ -0,0 +1,15 @@
+# test complex interacting with special methods
+
+
+class A:
+ def __add__(self, x):
+ print("__add__")
+ return 1
+
+ def __radd__(self, x):
+ print("__radd__")
+ return 2
+
+
+print(A() + 1j)
+print(1j + A())