summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ports/qemu-arm/mpconfigport.h1
-rw-r--r--tests/basics/class_reverse_op.py18
-rw-r--r--tests/feature_check/reverse_ops.py9
-rw-r--r--tests/feature_check/reverse_ops.py.exp0
-rwxr-xr-xtests/run-tests7
5 files changed, 35 insertions, 0 deletions
diff --git a/ports/qemu-arm/mpconfigport.h b/ports/qemu-arm/mpconfigport.h
index a12165a92..51706b927 100644
--- a/ports/qemu-arm/mpconfigport.h
+++ b/ports/qemu-arm/mpconfigport.h
@@ -18,6 +18,7 @@
#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_FLOAT)
#define MICROPY_CAN_OVERRIDE_BUILTINS (1)
#define MICROPY_PY_ALL_SPECIAL_METHODS (1)
+#define MICROPY_PY_REVERSE_SPECIAL_METHODS (1)
#define MICROPY_PY_ARRAY_SLICE_ASSIGN (1)
#define MICROPY_PY_BUILTINS_FROZENSET (1)
#define MICROPY_PY_BUILTINS_MEMORYVIEW (1)
diff --git a/tests/basics/class_reverse_op.py b/tests/basics/class_reverse_op.py
new file mode 100644
index 000000000..d41c55c9d
--- /dev/null
+++ b/tests/basics/class_reverse_op.py
@@ -0,0 +1,18 @@
+class A:
+
+ def __init__(self, v):
+ self.v = v
+
+ def __add__(self, o):
+ if isinstance(o, A):
+ return A(self.v + o.v)
+ return A(self.v + o)
+
+ def __radd__(self, o):
+ return A(self.v + o)
+
+ def __repr__(self):
+ return "A(%s)" % self.v
+
+print(A(3) + 1)
+print(2 + A(5))
diff --git a/tests/feature_check/reverse_ops.py b/tests/feature_check/reverse_ops.py
new file mode 100644
index 000000000..668748bc5
--- /dev/null
+++ b/tests/feature_check/reverse_ops.py
@@ -0,0 +1,9 @@
+class Foo:
+
+ def __radd__(self, other):
+ pass
+
+try:
+ 5 + Foo()
+except TypeError:
+ print("TypeError")
diff --git a/tests/feature_check/reverse_ops.py.exp b/tests/feature_check/reverse_ops.py.exp
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/tests/feature_check/reverse_ops.py.exp
diff --git a/tests/run-tests b/tests/run-tests
index 14df1e986..c9f9efe77 100755
--- a/tests/run-tests
+++ b/tests/run-tests
@@ -207,6 +207,7 @@ def run_tests(pyb, tests, args, base_path="."):
skip_set_type = False
skip_async = False
skip_const = False
+ skip_revops = False
# Check if micropython.native is supported, and skip such tests if it's not
native = run_feature_check(pyb, args, base_path, 'native_check.py')
@@ -233,6 +234,11 @@ def run_tests(pyb, tests, args, base_path="."):
if native == b'CRASH':
skip_const = True
+ # Check if __rOP__ special methods are supported, and skip such tests if it's not
+ native = run_feature_check(pyb, args, base_path, 'reverse_ops.py')
+ if native == b'TypeError\n':
+ skip_revops = True
+
# Check if emacs repl is supported, and skip such tests if it's not
t = run_feature_check(pyb, args, base_path, 'repl_emacs_check.py')
if not 'True' in str(t, 'ascii'):
@@ -360,6 +366,7 @@ def run_tests(pyb, tests, args, base_path="."):
skip_it |= skip_set_type and is_set_type
skip_it |= skip_async and is_async
skip_it |= skip_const and is_const
+ skip_it |= skip_revops and test_name.startswith("class_reverse_op")
if skip_it:
print("skip ", test_file)