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:
Paul Sokolovsky 2017-09-10 17:05:31 +03:00
parent eb84a830df
commit d6f9d64d97
5 changed files with 35 additions and 0 deletions

View File

@ -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)

View 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))

View File

@ -0,0 +1,9 @@
class Foo:
def __radd__(self, other):
pass
try:
5 + Foo()
except TypeError:
print("TypeError")

View File

View 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)