tests/class_reverse_op: Test for reverse arith ops special methods.
This test should be run only if support for reverse ops is enabled, so the corresponding feature_check is added to run-tests.
This commit is contained in:
parent
eb84a830df
commit
d6f9d64d97
@ -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)
|
||||
|
18
tests/basics/class_reverse_op.py
Normal file
18
tests/basics/class_reverse_op.py
Normal file
@ -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))
|
9
tests/feature_check/reverse_ops.py
Normal file
9
tests/feature_check/reverse_ops.py
Normal file
@ -0,0 +1,9 @@
|
||||
class Foo:
|
||||
|
||||
def __radd__(self, other):
|
||||
pass
|
||||
|
||||
try:
|
||||
5 + Foo()
|
||||
except TypeError:
|
||||
print("TypeError")
|
0
tests/feature_check/reverse_ops.py.exp
Normal file
0
tests/feature_check/reverse_ops.py.exp
Normal file
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user