From 65cadbeb9d78bfc80314ff4f19fdb4aff5e78244 Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 9 Jan 2017 00:19:01 +1100 Subject: tests: Update test suite to be compatible with CPython 3.6. CPython 3.6 has a few changes that, when run on uPy's test suite, give a different output to CPython 3.5. uPy currently officially supports the 3.4 language definition, but it's useful to be able to run the test suite with 3.4/3.5/3.6 versions of CPython. This patch makes such changes to support 3.6. --- tests/basics/python34.py | 9 +++++---- tests/basics/python34.py.exp | 2 ++ tests/basics/syntaxerror.py | 4 ---- 3 files changed, 7 insertions(+), 8 deletions(-) (limited to 'tests/basics') diff --git a/tests/basics/python34.py b/tests/basics/python34.py index 7f7a1e015..a23f347d6 100644 --- a/tests/basics/python34.py +++ b/tests/basics/python34.py @@ -1,4 +1,4 @@ -# tests that differ when running under Python 3.4 vs 3.5 +# tests that differ when running under Python 3.4 vs 3.5/3.6 # from basics/fun_kwvarargs.py # test evaluation order of arguments (in 3.4 it's backwards, 3.5 it's fixed) @@ -13,14 +13,15 @@ f4(*print_ret(['a', 'b']), kw_arg=print_ret(None)) {print_ret(1):print_ret(2)} # from basics/syntaxerror.py -# can't have multiple * or ** (in 3.5 we can) def test_syntax(code): try: exec(code) except SyntaxError: print("SyntaxError") -test_syntax("f(*a, *b)") -test_syntax("f(**a, **b)") +test_syntax("f(*a, *b)") # can't have multiple * (in 3.5 we can) +test_syntax("f(**a, **b)") # can't have multiple ** (in 3.5 we can) +test_syntax("() = []") # can't assign to empty tuple (in 3.6 we can) +test_syntax("del ()") # can't delete empty tuple (in 3.6 we can) # from basics/sys1.py # uPy prints version 3.4 diff --git a/tests/basics/python34.py.exp b/tests/basics/python34.py.exp index 637f77ce8..f497df3b8 100644 --- a/tests/basics/python34.py.exp +++ b/tests/basics/python34.py.exp @@ -5,5 +5,7 @@ None 1 SyntaxError SyntaxError +SyntaxError +SyntaxError 3.4 3 4 diff --git a/tests/basics/syntaxerror.py b/tests/basics/syntaxerror.py index e5cbbac06..4161de017 100644 --- a/tests/basics/syntaxerror.py +++ b/tests/basics/syntaxerror.py @@ -46,9 +46,6 @@ test_syntax("f**2 = 1") # can't assign to power of composite test_syntax("f[0]**2 = 1") -# can't assign to empty tuple -test_syntax("() = 1") - # can't have *x on RHS test_syntax("x = *x") @@ -66,7 +63,6 @@ test_syntax("[a, b] += c") test_syntax("def f(a=1, b): pass") # can't delete these things -test_syntax("del ()") test_syntax("del f()") test_syntax("del f[0]**2") test_syntax("del (a for a in a)") -- cgit v1.2.3 From 96baaa68a4430efd585f2186976cfa473ca73bfc Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 17 Jan 2017 00:17:44 +1100 Subject: tests: Update tests, and add new ones, for recent generator tweaks. --- tests/basics/gen_yield_from_throw2.py | 15 +++++++++------ tests/basics/gen_yield_from_throw2.py.exp | 3 --- tests/basics/gen_yield_from_throw3.py | 30 ++++++++++++++++++++++++++++++ tests/run-tests | 2 +- 4 files changed, 40 insertions(+), 10 deletions(-) delete mode 100644 tests/basics/gen_yield_from_throw2.py.exp create mode 100644 tests/basics/gen_yield_from_throw3.py (limited to 'tests/basics') diff --git a/tests/basics/gen_yield_from_throw2.py b/tests/basics/gen_yield_from_throw2.py index 2cff9e08b..0abfdd8cc 100644 --- a/tests/basics/gen_yield_from_throw2.py +++ b/tests/basics/gen_yield_from_throw2.py @@ -1,5 +1,5 @@ -# uPy differs from CPython for this test -# generator ignored GeneratorExit +# generator ignores a thrown GeneratorExit (this is allowed) + def gen(): try: yield 123 @@ -7,9 +7,12 @@ def gen(): print('GeneratorExit') yield 456 +# thrown a class g = gen() print(next(g)) -try: - g.throw(GeneratorExit) -except RuntimeError: - print('RuntimeError') +print(g.throw(GeneratorExit)) + +# thrown an instance +g = gen() +print(next(g)) +print(g.throw(GeneratorExit())) diff --git a/tests/basics/gen_yield_from_throw2.py.exp b/tests/basics/gen_yield_from_throw2.py.exp deleted file mode 100644 index d5805b494..000000000 --- a/tests/basics/gen_yield_from_throw2.py.exp +++ /dev/null @@ -1,3 +0,0 @@ -123 -GeneratorExit -RuntimeError diff --git a/tests/basics/gen_yield_from_throw3.py b/tests/basics/gen_yield_from_throw3.py new file mode 100644 index 000000000..0f6c7c842 --- /dev/null +++ b/tests/basics/gen_yield_from_throw3.py @@ -0,0 +1,30 @@ +# yield-from a user-defined generator with a throw() method + +class Iter: + def __iter__(self): + return self + + def __next__(self): + return 1 + + def throw(self, x): + print('throw', x) + return 456 + +def gen(): + yield from Iter() + +# calling close() should not call throw() +g = gen() +print(next(g)) +g.close() + +# can throw a non-exception object +g = gen() +print(next(g)) +print(g.throw(123)) + +# throwing an exception class just injects that class +g = gen() +print(next(g)) +print(g.throw(ZeroDivisionError)) diff --git a/tests/run-tests b/tests/run-tests index 91282667d..b835047a2 100755 --- a/tests/run-tests +++ b/tests/run-tests @@ -281,7 +281,7 @@ def run_tests(pyb, tests, args): # Some tests are known to fail with native emitter # Remove them from the below when they work if args.emit == 'native': - skip_tests.update({'basics/%s.py' % t for t in 'gen_yield_from gen_yield_from_close gen_yield_from_ducktype gen_yield_from_exc gen_yield_from_iter gen_yield_from_send gen_yield_from_stopped gen_yield_from_throw gen_yield_from_throw2 generator1 generator2 generator_args generator_close generator_closure generator_exc generator_return generator_send'.split()}) # require yield + skip_tests.update({'basics/%s.py' % t for t in 'gen_yield_from gen_yield_from_close gen_yield_from_ducktype gen_yield_from_exc gen_yield_from_iter gen_yield_from_send gen_yield_from_stopped gen_yield_from_throw gen_yield_from_throw2 gen_yield_from_throw3 generator1 generator2 generator_args generator_close generator_closure generator_exc generator_return generator_send'.split()}) # require yield skip_tests.update({'basics/%s.py' % t for t in 'bytes_gen class_store_class globals_del string_join'.split()}) # require yield skip_tests.update({'basics/async_%s.py' % t for t in 'def await await2 for for2 with with2'.split()}) # require yield skip_tests.update({'basics/%s.py' % t for t in 'try_reraise try_reraise2'.split()}) # require raise_varargs -- cgit v1.2.3 From 5314219f182e8a303e3fa68e2bacca978cb08002 Mon Sep 17 00:00:00 2001 From: Rami Ali Date: Tue, 17 Jan 2017 16:03:30 +1100 Subject: tests/basics: Improve runtime.c test coverage. --- tests/basics/fun_calldblstar3.py | 3 ++- tests/basics/fun_callstar.py | 5 +++++ tests/basics/iter0.py | 3 +++ 3 files changed, 10 insertions(+), 1 deletion(-) (limited to 'tests/basics') diff --git a/tests/basics/fun_calldblstar3.py b/tests/basics/fun_calldblstar3.py index 4367e68df..b796d52c7 100644 --- a/tests/basics/fun_calldblstar3.py +++ b/tests/basics/fun_calldblstar3.py @@ -5,7 +5,8 @@ def foo(**kw): class Mapping: def keys(self): - return ['a', 'b', 'c'] + # the long string checks the case of string interning + return ['a', 'b', 'c', 'abcdefghijklmnopqrst'] def __getitem__(self, key): if key == 'a': diff --git a/tests/basics/fun_callstar.py b/tests/basics/fun_callstar.py index 2275d3d4f..a27a288a3 100644 --- a/tests/basics/fun_callstar.py +++ b/tests/basics/fun_callstar.py @@ -17,6 +17,11 @@ foo(*range(3)) # pos then iterator foo(1, *range(2, 4)) +# an iterator with many elements +def foo(*rest): + print(rest) +foo(*range(10)) + # method calls with *pos class A: diff --git a/tests/basics/iter0.py b/tests/basics/iter0.py index 6110e8fa5..d20ade7fe 100644 --- a/tests/basics/iter0.py +++ b/tests/basics/iter0.py @@ -4,3 +4,6 @@ try: pass except TypeError: print('TypeError') + +# builtin type that is iterable, calling __next__ explicitly +print(iter(range(4)).__next__()) -- cgit v1.2.3 From af9046193148084f008501434e4c9f49fedc053f Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Tue, 17 Jan 2017 22:50:20 +0300 Subject: py/binary: mp_binary_get_size: Raise error on unsupported typecodes. Previouly, we had errors checked in callers, which led to duplicate code or missing checks in some places. --- py/binary.c | 6 ++++++ py/modstruct.c | 3 --- py/objarray.c | 3 --- tests/basics/struct2.py | 12 +++++++++++- 4 files changed, 17 insertions(+), 7 deletions(-) (limited to 'tests/basics') diff --git a/py/binary.c b/py/binary.c index d22e0f342..6450478cc 100644 --- a/py/binary.c +++ b/py/binary.c @@ -33,6 +33,7 @@ #include "py/binary.h" #include "py/smallint.h" #include "py/objint.h" +#include "py/runtime.h" // Helpers to work with binary-encoded data @@ -100,6 +101,11 @@ size_t mp_binary_get_size(char struct_type, char val_type, mp_uint_t *palign) { } } } + + if (size == 0) { + mp_raise_ValueError("bad typecode"); + } + if (palign != NULL) { *palign = align; } diff --git a/py/modstruct.c b/py/modstruct.c index 88411ff0f..3c99ef1d8 100644 --- a/py/modstruct.c +++ b/py/modstruct.c @@ -113,9 +113,6 @@ STATIC mp_obj_t struct_calcsize(mp_obj_t fmt_in) { } else { mp_uint_t align; size_t sz = mp_binary_get_size(fmt_type, *fmt, &align); - if (sz == 0) { - mp_raise_ValueError("unsupported format"); - } while (cnt--) { // Apply alignment size = (size + align - 1) & ~(align - 1); diff --git a/py/objarray.c b/py/objarray.c index 8e1d32f0f..ed666df8f 100644 --- a/py/objarray.c +++ b/py/objarray.c @@ -94,9 +94,6 @@ STATIC void array_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t #if MICROPY_PY_BUILTINS_BYTEARRAY || MICROPY_PY_ARRAY STATIC mp_obj_array_t *array_new(char typecode, mp_uint_t n) { int typecode_size = mp_binary_get_size('@', typecode, NULL); - if (typecode_size == 0) { - mp_raise_msg(&mp_type_ValueError, "bad typecode"); - } mp_obj_array_t *o = m_new_obj(mp_obj_array_t); #if MICROPY_PY_BUILTINS_BYTEARRAY && MICROPY_PY_ARRAY o->base.type = (typecode == BYTEARRAY_TYPECODE) ? &mp_type_bytearray : &mp_type_array; diff --git a/tests/basics/struct2.py b/tests/basics/struct2.py index 6dd963260..e3f8bbebf 100644 --- a/tests/basics/struct2.py +++ b/tests/basics/struct2.py @@ -26,7 +26,17 @@ print(struct.calcsize('0s1s0H2H')) print(struct.unpack('<0s1s0H2H', b'01234')) print(struct.pack('<0s1s0H2H', b'abc', b'abc', 258, 515)) -# check that zero of an unknown type raises an exception +# check that unknown types raise an exception +try: + struct.unpack('z', b'1') +except: + print('Exception') + +try: + struct.pack('z', (b'1',)) +except: + print('Exception') + try: struct.calcsize('0z') except: -- cgit v1.2.3 From 1639200e5700b1170a9d2312a32c7991ed5198b4 Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 20 Jan 2017 13:17:22 +1100 Subject: tests/basics: Add test for assignment of attribute to bound method. --- tests/basics/boundmeth1.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'tests/basics') diff --git a/tests/basics/boundmeth1.py b/tests/basics/boundmeth1.py index a72887275..f483ba406 100644 --- a/tests/basics/boundmeth1.py +++ b/tests/basics/boundmeth1.py @@ -22,3 +22,9 @@ print(m(1)) # bound method with lots of extra args m = A().h print(m(1, 2, 3, 4, 5, 6)) + +# can't assign attributes to a bound method +try: + A().f.x = 1 +except AttributeError: + print('AttributeError') -- cgit v1.2.3 From 3b09dca046634e5ff6cdf97a77bbeab922f7ba2d Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sat, 21 Jan 2017 20:15:31 +0300 Subject: tests: Add test for int.from_bytes() for arbitrary-precision integer. This test works only for MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_MPZ and needs a way of skipping in other cases. --- tests/basics/int_bytes_long.py | 7 +++++++ tests/basics/int_bytes_notimpl.py | 5 ----- tests/basics/int_bytes_notimpl.py.exp | 1 - 3 files changed, 7 insertions(+), 6 deletions(-) create mode 100644 tests/basics/int_bytes_long.py (limited to 'tests/basics') diff --git a/tests/basics/int_bytes_long.py b/tests/basics/int_bytes_long.py new file mode 100644 index 000000000..81ebc6cdc --- /dev/null +++ b/tests/basics/int_bytes_long.py @@ -0,0 +1,7 @@ +b = bytes(range(20)) + +il = int.from_bytes(b, "little") +ib = int.from_bytes(b, "big") +print(il) +print(ib) +print(il.to_bytes(20, "little")) diff --git a/tests/basics/int_bytes_notimpl.py b/tests/basics/int_bytes_notimpl.py index b47d6ab58..b149f4496 100644 --- a/tests/basics/int_bytes_notimpl.py +++ b/tests/basics/int_bytes_notimpl.py @@ -2,8 +2,3 @@ try: print((10).to_bytes(1, "big")) except Exception as e: print(type(e)) - -try: - print(int.from_bytes(b"\0", "big")) -except Exception as e: - print(type(e)) diff --git a/tests/basics/int_bytes_notimpl.py.exp b/tests/basics/int_bytes_notimpl.py.exp index d1bf338eb..606649a69 100644 --- a/tests/basics/int_bytes_notimpl.py.exp +++ b/tests/basics/int_bytes_notimpl.py.exp @@ -1,2 +1 @@ - -- cgit v1.2.3 From 1864f90e9a2c0cc12e91c88ddd491b809c5317e5 Mon Sep 17 00:00:00 2001 From: Damien George Date: Sun, 22 Jan 2017 11:49:08 +1100 Subject: tests: Add test for builtin help function. --- tests/basics/builtin_help.py | 17 +++++++++++++++++ tests/basics/builtin_help.py.exp | 14 ++++++++++++++ tests/run-tests | 2 +- 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 tests/basics/builtin_help.py create mode 100644 tests/basics/builtin_help.py.exp (limited to 'tests/basics') diff --git a/tests/basics/builtin_help.py b/tests/basics/builtin_help.py new file mode 100644 index 000000000..902a95175 --- /dev/null +++ b/tests/basics/builtin_help.py @@ -0,0 +1,17 @@ +# test builtin help function + +try: + help +except NameError: + print("SKIP") + import sys + sys.exit() + +help() # no args +help(help) # help for a function +help(int) # help for a class +help(1) # help for an instance +import micropython +help(micropython) # help for a module + +print('done') # so last bit of output is predictable diff --git a/tests/basics/builtin_help.py.exp b/tests/basics/builtin_help.py.exp new file mode 100644 index 000000000..ed8a7d74b --- /dev/null +++ b/tests/basics/builtin_help.py.exp @@ -0,0 +1,14 @@ +######## +object is of type function +object is of type type + from_bytes -- + to_bytes -- +object 1 is of type int + from_bytes -- + to_bytes -- +object is of type module + __name__ -- micropython + const -- + opt_level -- +######## +done diff --git a/tests/run-tests b/tests/run-tests index b835047a2..6834d59be 100755 --- a/tests/run-tests +++ b/tests/run-tests @@ -51,7 +51,7 @@ def convert_regex_escapes(line): def run_micropython(pyb, args, test_file): - special_tests = ('micropython/meminfo.py', 'basics/bytes_compare3.py', 'thread/thread_exc2.py') + special_tests = ('micropython/meminfo.py', 'basics/bytes_compare3.py', 'basics/builtin_help.py', 'thread/thread_exc2.py') is_special = False if pyb is None: # run on PC -- cgit v1.2.3 From 20fc620327125e17ffa22493d1578835795bcc88 Mon Sep 17 00:00:00 2001 From: Damien George Date: Sun, 22 Jan 2017 12:14:56 +1100 Subject: tests/basics/builtin_help: Add test for help('modules'). --- tests/basics/builtin_help.py | 1 + 1 file changed, 1 insertion(+) (limited to 'tests/basics') diff --git a/tests/basics/builtin_help.py b/tests/basics/builtin_help.py index 902a95175..d554f308d 100644 --- a/tests/basics/builtin_help.py +++ b/tests/basics/builtin_help.py @@ -13,5 +13,6 @@ help(int) # help for a class help(1) # help for an instance import micropython help(micropython) # help for a module +help('modules') # list available modules print('done') # so last bit of output is predictable -- cgit v1.2.3 From 33b8e65bc0cb56c0c3da28511ce8f7c612c3e1c8 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Tue, 31 Jan 2017 00:33:01 +0300 Subject: tests/basics/zip: Make skippable. --- tests/basics/zip.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'tests/basics') diff --git a/tests/basics/zip.py b/tests/basics/zip.py index c0109094f..958addb7a 100644 --- a/tests/basics/zip.py +++ b/tests/basics/zip.py @@ -1,2 +1,10 @@ +try: + zip + set +except NameError: + print("SKIP") + import sys + sys.exit() + print(list(zip())) -print(list(zip([1], {2,3}))) +print(list(zip([1], set([2, 3])))) -- cgit v1.2.3 From 05c70fdfba7e5c0f9104c927e29822a8da8c467f Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 2 Feb 2017 23:36:53 +1100 Subject: tests/basics/set_binop: Add tests for inplace set operations. --- tests/basics/set_binop.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'tests/basics') diff --git a/tests/basics/set_binop.py b/tests/basics/set_binop.py index a3657d84b..7848920b6 100644 --- a/tests/basics/set_binop.py +++ b/tests/basics/set_binop.py @@ -29,6 +29,25 @@ for s in sets: print(set('abc') == 1) +# make sure inplace operators modify the set + +s1 = s2 = set('abc') +s1 |= set('ad') +print(s1 is s2, len(s1)) + +s1 = s2 = set('abc') +s1 ^= set('ad') +print(s1 is s2, len(s1)) + +s1 = s2 = set('abc') +s1 &= set('ad') +print(s1 is s2, len(s1)) + +s1 = s2 = set('abc') +s1 -= set('ad') +print(s1 is s2, len(s1)) + +# unsupported operator try: set('abc') * 2 except TypeError: -- cgit v1.2.3 From df0117c8ae213a0652c3b19a969edc7fd994eeab Mon Sep 17 00:00:00 2001 From: Nicko van Someren Date: Wed, 1 Feb 2017 16:41:22 -0700 Subject: py: Added optimised support for 3-argument calls to builtin.pow() Updated modbuiltin.c to add conditional support for 3-arg calls to pow() using MICROPY_PY_BUILTINS_POW3 config parameter. Added support in objint_mpz.c for for optimised implementation. --- py/modbuiltins.c | 9 ++++++++- py/mpconfig.h | 5 +++++ py/mpz.c | 6 +++--- py/mpz.h | 1 + py/objint.h | 1 + py/objint_mpz.c | 33 +++++++++++++++++++++++++++++++++ tests/basics/builtin_pow.py | 28 ++++++++++++++++++++++++++++ unix/mpconfigport.h | 1 + 8 files changed, 80 insertions(+), 4 deletions(-) (limited to 'tests/basics') diff --git a/py/modbuiltins.c b/py/modbuiltins.c index f62afd807..a0c68930d 100644 --- a/py/modbuiltins.c +++ b/py/modbuiltins.c @@ -378,7 +378,14 @@ MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_ord_obj, mp_builtin_ord); STATIC mp_obj_t mp_builtin_pow(size_t n_args, const mp_obj_t *args) { switch (n_args) { case 2: return mp_binary_op(MP_BINARY_OP_POWER, args[0], args[1]); - default: return mp_binary_op(MP_BINARY_OP_MODULO, mp_binary_op(MP_BINARY_OP_POWER, args[0], args[1]), args[2]); // TODO optimise... + default: +#if !MICROPY_PY_BUILTINS_POW3 + mp_raise_msg(&mp_type_NotImplementedError, "3-arg pow() not supported"); +#elif MICROPY_LONGINT_IMPL != MICROPY_LONGINT_IMPL_MPZ + return mp_binary_op(MP_BINARY_OP_MODULO, mp_binary_op(MP_BINARY_OP_POWER, args[0], args[1]), args[2]); +#else + return mp_obj_int_pow3(args[0], args[1], args[2]); +#endif } } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_pow_obj, 2, 3, mp_builtin_pow); diff --git a/py/mpconfig.h b/py/mpconfig.h index 993ad1db8..13af4c62b 100644 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -490,6 +490,11 @@ #define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_NONE) #endif +// Support for calls to pow() with 3 integer arguments +#ifndef MICROPY_PY_BUILTINS_POW3 +#define MICROPY_PY_BUILTINS_POW3 (0) +#endif + #if MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_LONGLONG typedef long long mp_longint_impl_t; #endif diff --git a/py/mpz.c b/py/mpz.c index 6477c3f8d..230eb921c 100644 --- a/py/mpz.c +++ b/py/mpz.c @@ -1395,9 +1395,6 @@ void mpz_pow_inpl(mpz_t *dest, const mpz_t *lhs, const mpz_t *rhs) { mpz_free(n); } -#if 0 -these functions are unused - /* computes dest = (lhs ** rhs) % mod can have dest, lhs, rhs the same; mod can't be the same as dest */ @@ -1436,6 +1433,9 @@ void mpz_pow3_inpl(mpz_t *dest, const mpz_t *lhs, const mpz_t *rhs, const mpz_t mpz_free(n); } +#if 0 +these functions are unused + /* computes gcd(z1, z2) based on Knuth's modified gcd algorithm (I think?) gcd(z1, z2) >= 0 diff --git a/py/mpz.h b/py/mpz.h index a26cbea5c..8facb1a0f 100644 --- a/py/mpz.h +++ b/py/mpz.h @@ -123,6 +123,7 @@ void mpz_add_inpl(mpz_t *dest, const mpz_t *lhs, const mpz_t *rhs); void mpz_sub_inpl(mpz_t *dest, const mpz_t *lhs, const mpz_t *rhs); void mpz_mul_inpl(mpz_t *dest, const mpz_t *lhs, const mpz_t *rhs); void mpz_pow_inpl(mpz_t *dest, const mpz_t *lhs, const mpz_t *rhs); +void mpz_pow3_inpl(mpz_t *dest, const mpz_t *lhs, const mpz_t *rhs, const mpz_t *mod); void mpz_and_inpl(mpz_t *dest, const mpz_t *lhs, const mpz_t *rhs); void mpz_or_inpl(mpz_t *dest, const mpz_t *lhs, const mpz_t *rhs); void mpz_xor_inpl(mpz_t *dest, const mpz_t *lhs, const mpz_t *rhs); diff --git a/py/objint.h b/py/objint.h index a84a33fa5..7205761ad 100644 --- a/py/objint.h +++ b/py/objint.h @@ -66,5 +66,6 @@ mp_obj_t mp_obj_int_abs(mp_obj_t self_in); mp_obj_t mp_obj_int_unary_op(mp_uint_t op, mp_obj_t o_in); mp_obj_t mp_obj_int_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in); mp_obj_t mp_obj_int_binary_op_extra_cases(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in); +mp_obj_t mp_obj_int_pow3(mp_obj_t base, mp_obj_t exponent, mp_obj_t modulus); #endif // __MICROPY_INCLUDED_PY_OBJINT_H__ diff --git a/py/objint_mpz.c b/py/objint_mpz.c index d465ef965..2b27df4f6 100644 --- a/py/objint_mpz.c +++ b/py/objint_mpz.c @@ -326,6 +326,39 @@ mp_obj_t mp_obj_int_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) { } } +#if MICROPY_PY_BUILTINS_POW3 +STATIC mpz_t *mp_mpz_for_int(mp_obj_t arg, mpz_t *temp) { + if (MP_OBJ_IS_SMALL_INT(arg)) { + mpz_init_from_int(temp, MP_OBJ_SMALL_INT_VALUE(arg)); + return temp; + } else { + mp_obj_int_t *arp_p = MP_OBJ_TO_PTR(arg); + return &(arp_p->mpz); + } +} + +mp_obj_t mp_obj_int_pow3(mp_obj_t base, mp_obj_t exponent, mp_obj_t modulus) { + if (!MP_OBJ_IS_INT(base) || !MP_OBJ_IS_INT(exponent) || !MP_OBJ_IS_INT(modulus)) { + mp_raise_TypeError("pow() with 3 arguments requires integers"); + } else { + mp_obj_t result = mp_obj_new_int_from_ull(0); // Use the _from_ull version as this forces an mpz int + mp_obj_int_t *res_p = (mp_obj_int_t *) MP_OBJ_TO_PTR(result); + + mpz_t l_temp, r_temp, m_temp; + mpz_t *lhs = mp_mpz_for_int(base, &l_temp); + mpz_t *rhs = mp_mpz_for_int(exponent, &r_temp); + mpz_t *mod = mp_mpz_for_int(modulus, &m_temp); + + mpz_pow3_inpl(&(res_p->mpz), lhs, rhs, mod); + + if (lhs == &l_temp) { mpz_deinit(lhs); } + if (rhs == &r_temp) { mpz_deinit(rhs); } + if (mod == &m_temp) { mpz_deinit(mod); } + return result; + } +} +#endif + mp_obj_t mp_obj_new_int(mp_int_t value) { if (MP_SMALL_INT_FITS(value)) { return MP_OBJ_NEW_SMALL_INT(value); diff --git a/tests/basics/builtin_pow.py b/tests/basics/builtin_pow.py index a19ab8c84..faf75f0df 100644 --- a/tests/basics/builtin_pow.py +++ b/tests/basics/builtin_pow.py @@ -8,4 +8,32 @@ print(pow(3, 8)) # 3 arg version print(pow(3, 4, 7)) +print(pow(555557, 1000002, 1000003)) +# 3 arg pow is defined to only work on integers +try: + print(pow("x", 5, 6)) +except TypeError: + print("TypeError expected") + +try: + print(pow(4, "y", 6)) +except TypeError: + print("TypeError expected") + +try: + print(pow(4, 5, "z")) +except TypeError: + print("TypeError expected") + +# Tests for 3 arg pow with large values + +# This value happens to be prime +x = 0xd48a1e2a099b1395895527112937a391d02d4a208bce5d74b281cf35a57362502726f79a632f063a83c0eba66196712d963aa7279ab8a504110a668c0fc38a7983c51e6ee7a85cae87097686ccdc359ee4bbf2c583bce524e3f7836bded1c771a4efcb25c09460a862fc98e18f7303df46aaeb34da46b0c4d61d5cd78350f3edb60e6bc4befa712a849 +y = 0x3accf60bb1a5365e4250d1588eb0fe6cd81ad495e9063f90880229f2a625e98c59387238670936afb2cafc5b79448e4414d6cd5e9901aa845aa122db58ddd7b9f2b17414600a18c47494ed1f3d49d005a5 + +print(hex(pow(2, 200, x))) # Should not overflow, just 1 << 200 +print(hex(pow(2, x-1, x))) # Should be 1, since x is prime +print(hex(pow(y, x-1, x))) # Should be 1, since x is prime +print(hex(pow(y, y-1, x))) # Should be a 'big value' +print(hex(pow(y, y-1, y))) # Should be a 'big value' diff --git a/unix/mpconfigport.h b/unix/mpconfigport.h index ba2b5ce98..66de0fa96 100644 --- a/unix/mpconfigport.h +++ b/unix/mpconfigport.h @@ -80,6 +80,7 @@ #define MICROPY_PY_BUILTINS_FROZENSET (1) #define MICROPY_PY_BUILTINS_COMPILE (1) #define MICROPY_PY_BUILTINS_NOTIMPLEMENTED (1) +#define MICROPY_PY_BUILTINS_POW3 (1) #define MICROPY_PY_MICROPYTHON_MEM_INFO (1) #define MICROPY_PY_ALL_SPECIAL_METHODS (1) #define MICROPY_PY_ARRAY_SLICE_ASSIGN (1) -- cgit v1.2.3 From 87882e1708bc5118bcaaed048c121c75e349888c Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Thu, 2 Feb 2017 23:34:52 +0300 Subject: tests: Split tests for 2- and 3-arg pow(). --- tests/basics/builtin_pow.py | 34 +--------------------------------- tests/basics/builtin_pow3.py | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 33 deletions(-) create mode 100644 tests/basics/builtin_pow3.py (limited to 'tests/basics') diff --git a/tests/basics/builtin_pow.py b/tests/basics/builtin_pow.py index faf75f0df..5012a76be 100644 --- a/tests/basics/builtin_pow.py +++ b/tests/basics/builtin_pow.py @@ -1,39 +1,7 @@ # test builtin pow() with integral values - # 2 arg version + print(pow(0, 1)) print(pow(1, 0)) print(pow(-2, 3)) print(pow(3, 8)) - -# 3 arg version -print(pow(3, 4, 7)) -print(pow(555557, 1000002, 1000003)) - -# 3 arg pow is defined to only work on integers -try: - print(pow("x", 5, 6)) -except TypeError: - print("TypeError expected") - -try: - print(pow(4, "y", 6)) -except TypeError: - print("TypeError expected") - -try: - print(pow(4, 5, "z")) -except TypeError: - print("TypeError expected") - -# Tests for 3 arg pow with large values - -# This value happens to be prime -x = 0xd48a1e2a099b1395895527112937a391d02d4a208bce5d74b281cf35a57362502726f79a632f063a83c0eba66196712d963aa7279ab8a504110a668c0fc38a7983c51e6ee7a85cae87097686ccdc359ee4bbf2c583bce524e3f7836bded1c771a4efcb25c09460a862fc98e18f7303df46aaeb34da46b0c4d61d5cd78350f3edb60e6bc4befa712a849 -y = 0x3accf60bb1a5365e4250d1588eb0fe6cd81ad495e9063f90880229f2a625e98c59387238670936afb2cafc5b79448e4414d6cd5e9901aa845aa122db58ddd7b9f2b17414600a18c47494ed1f3d49d005a5 - -print(hex(pow(2, 200, x))) # Should not overflow, just 1 << 200 -print(hex(pow(2, x-1, x))) # Should be 1, since x is prime -print(hex(pow(y, x-1, x))) # Should be 1, since x is prime -print(hex(pow(y, y-1, x))) # Should be a 'big value' -print(hex(pow(y, y-1, y))) # Should be a 'big value' diff --git a/tests/basics/builtin_pow3.py b/tests/basics/builtin_pow3.py new file mode 100644 index 000000000..35e143a38 --- /dev/null +++ b/tests/basics/builtin_pow3.py @@ -0,0 +1,39 @@ +# test builtin pow() with integral values +# 3 arg version + +try: + print(pow(3, 4, 7)) +except NotImplementedError: + import sys + print("SKIP") + sys.exit() + +print(pow(555557, 1000002, 1000003)) + +# 3 arg pow is defined to only work on integers +try: + print(pow("x", 5, 6)) +except TypeError: + print("TypeError expected") + +try: + print(pow(4, "y", 6)) +except TypeError: + print("TypeError expected") + +try: + print(pow(4, 5, "z")) +except TypeError: + print("TypeError expected") + +# Tests for 3 arg pow with large values + +# This value happens to be prime +x = 0xd48a1e2a099b1395895527112937a391d02d4a208bce5d74b281cf35a57362502726f79a632f063a83c0eba66196712d963aa7279ab8a504110a668c0fc38a7983c51e6ee7a85cae87097686ccdc359ee4bbf2c583bce524e3f7836bded1c771a4efcb25c09460a862fc98e18f7303df46aaeb34da46b0c4d61d5cd78350f3edb60e6bc4befa712a849 +y = 0x3accf60bb1a5365e4250d1588eb0fe6cd81ad495e9063f90880229f2a625e98c59387238670936afb2cafc5b79448e4414d6cd5e9901aa845aa122db58ddd7b9f2b17414600a18c47494ed1f3d49d005a5 + +print(hex(pow(2, 200, x))) # Should not overflow, just 1 << 200 +print(hex(pow(2, x-1, x))) # Should be 1, since x is prime +print(hex(pow(y, x-1, x))) # Should be 1, since x is prime +print(hex(pow(y, y-1, x))) # Should be a 'big value' +print(hex(pow(y, y-1, y))) # Should be a 'big value' -- cgit v1.2.3 From 84fb292cd55727598159585f864dce669203aec9 Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 3 Feb 2017 12:17:43 +1100 Subject: tests/basics/string_format_modulo: Add more tests for dict formatting. --- tests/basics/string_format_modulo.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'tests/basics') diff --git a/tests/basics/string_format_modulo.py b/tests/basics/string_format_modulo.py index 2e4909220..f00502457 100644 --- a/tests/basics/string_format_modulo.py +++ b/tests/basics/string_format_modulo.py @@ -66,6 +66,11 @@ print(">%-08.4d<" % -12) print(">%-+08.4d<" % -12) print(">%-+08.4d<" % 12) +# Should be able to print dicts; in this case they aren't used +# to lookup keywords in formats like %(foo)s +print('%s' % {}) +print('%s' % ({},)) + # Cases when "*" used and there's not enough values total try: print("%*s" % 5) @@ -77,6 +82,7 @@ except TypeError: print("TypeError") print("%(foo)s" % {"foo": "bar", "baz": False}) +print("%s %(foo)s %(foo)s" % {"foo": 1}) try: print("%(foo)s" % {}) except KeyError: @@ -87,6 +93,16 @@ try: except TypeError: print("TypeError") +# When using %(foo)s format the single argument must be a dict +try: + '%(foo)s' % 1 +except TypeError: + print('TypeError') +try: + '%(foo)s' % ({},) +except TypeError: + print('TypeError') + try: '%(a' % {'a':1} except ValueError: -- cgit v1.2.3 From 18e65691661ef8e83060d0e72d66b16cc918c8b4 Mon Sep 17 00:00:00 2001 From: dmazzella Date: Tue, 3 Jan 2017 11:00:12 +0100 Subject: py/objtype: Implement __delattr__ and __setattr__. This patch implements support for class methods __delattr__ and __setattr__ for customising attribute access. It is controlled by the config option MICROPY_PY_DELATTR_SETATTR and is disabled by default. --- py/mpconfig.h | 6 ++++ py/objtype.c | 34 +++++++++++++++++++ tests/basics/class_delattr_setattr.py | 63 +++++++++++++++++++++++++++++++++++ unix/mpconfigport_coverage.h | 1 + 4 files changed, 104 insertions(+) create mode 100644 tests/basics/class_delattr_setattr.py (limited to 'tests/basics') diff --git a/py/mpconfig.h b/py/mpconfig.h index afd9a0be5..093625a46 100644 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -635,6 +635,12 @@ typedef double mp_float_t; #define MICROPY_PY_DESCRIPTORS (0) #endif +// Whether to support class __delattr__ and __setattr__ methods +// This costs some code size and makes all del attrs and store attrs slow +#ifndef MICROPY_PY_DELATTR_SETATTR +#define MICROPY_PY_DELATTR_SETATTR (0) +#endif + // Support for async/await/async for/async with #ifndef MICROPY_PY_ASYNC_AWAIT #define MICROPY_PY_ASYNC_AWAIT (1) diff --git a/py/objtype.c b/py/objtype.c index c20b0693e..85e10e762 100644 --- a/py/objtype.c +++ b/py/objtype.c @@ -533,6 +533,15 @@ STATIC void mp_obj_instance_load_attr(mp_obj_t self_in, qstr attr, mp_obj_t *des // try __getattr__ if (attr != MP_QSTR___getattr__) { + #if MICROPY_PY_DELATTR_SETATTR + // If the requested attr is __setattr__/__delattr__ then don't delegate the lookup + // to __getattr__. If we followed CPython's behaviour then __setattr__/__delattr__ + // would have already been found in the "object" base class. + if (attr == MP_QSTR___setattr__ || attr == MP_QSTR___delattr__) { + return; + } + #endif + mp_obj_t dest2[3]; mp_load_method_maybe(self_in, MP_QSTR___getattr__, dest2); if (dest2[0] != MP_OBJ_NULL) { @@ -626,10 +635,35 @@ STATIC bool mp_obj_instance_store_attr(mp_obj_t self_in, qstr attr, mp_obj_t val if (value == MP_OBJ_NULL) { // delete attribute + #if MICROPY_PY_DELATTR_SETATTR + // try __delattr__ first + mp_obj_t attr_delattr_method[3]; + mp_load_method_maybe(self_in, MP_QSTR___delattr__, attr_delattr_method); + if (attr_delattr_method[0] != MP_OBJ_NULL) { + // __delattr__ exists, so call it + attr_delattr_method[2] = MP_OBJ_NEW_QSTR(attr); + mp_call_method_n_kw(1, 0, attr_delattr_method); + return true; + } + #endif + mp_map_elem_t *elem = mp_map_lookup(&self->members, MP_OBJ_NEW_QSTR(attr), MP_MAP_LOOKUP_REMOVE_IF_FOUND); return elem != NULL; } else { // store attribute + #if MICROPY_PY_DELATTR_SETATTR + // try __setattr__ first + mp_obj_t attr_setattr_method[4]; + mp_load_method_maybe(self_in, MP_QSTR___setattr__, attr_setattr_method); + if (attr_setattr_method[0] != MP_OBJ_NULL) { + // __setattr__ exists, so call it + attr_setattr_method[2] = MP_OBJ_NEW_QSTR(attr); + attr_setattr_method[3] = value; + mp_call_method_n_kw(2, 0, attr_setattr_method); + return true; + } + #endif + mp_map_lookup(&self->members, MP_OBJ_NEW_QSTR(attr), MP_MAP_LOOKUP_ADD_IF_NOT_FOUND)->value = value; return true; } diff --git a/tests/basics/class_delattr_setattr.py b/tests/basics/class_delattr_setattr.py new file mode 100644 index 000000000..0d061aee6 --- /dev/null +++ b/tests/basics/class_delattr_setattr.py @@ -0,0 +1,63 @@ +# test __delattr__ and __setattr__ + +# feature test for __setattr__/__delattr__ +try: + class Test(): + def __delattr__(self, attr): pass + del Test().noexist +except AttributeError: + import sys + print('SKIP') + sys.exit() + +# this class just prints the calls to see if they were executed +class A(): + def __getattr__(self, attr): + print('get', attr) + return 1 + def __setattr__(self, attr, val): + print('set', attr, val) + def __delattr__(self, attr): + print('del', attr) +a = A() + +# check basic behaviour +print(getattr(a, 'foo')) +setattr(a, 'bar', 2) +delattr(a, 'baz') + +# check meta behaviour +getattr(a, '__getattr__') # should not call A.__getattr__ +getattr(a, '__setattr__') # should not call A.__getattr__ +getattr(a, '__delattr__') # should not call A.__getattr__ +setattr(a, '__setattr__', 1) # should call A.__setattr__ +delattr(a, '__delattr__') # should call A.__delattr__ + +# this class acts like a dictionary +class B: + def __init__(self, d): + # store the dict in the class, not instance, so + # we don't get infinite recursion in __getattr_ + B.d = d + + def __getattr__(self, attr): + if attr in B.d: + return B.d[attr] + else: + raise AttributeError(attr) + + def __setattr__(self, attr, value): + B.d[attr] = value + + def __delattr__(self, attr): + del B.d[attr] + +a = B({"a":1, "b":2}) +print(a.a, a.b) +a.a = 3 +print(a.a, a.b) +del a.a +try: + print(a.a) +except AttributeError: + print("AttributeError") diff --git a/unix/mpconfigport_coverage.h b/unix/mpconfigport_coverage.h index 87a743cf8..9df8d0fca 100644 --- a/unix/mpconfigport_coverage.h +++ b/unix/mpconfigport_coverage.h @@ -32,6 +32,7 @@ #include +#define MICROPY_PY_DELATTR_SETATTR (1) #define MICROPY_PY_BUILTINS_HELP (1) #define MICROPY_PY_BUILTINS_HELP_MODULES (1) #define MICROPY_PY_URANDOM_EXTRA_FUNCS (1) -- cgit v1.2.3 From 800b163cd8713df8a2b1c87f23c40eb80290d918 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Tue, 14 Feb 2017 22:22:45 +0300 Subject: tests/comprehension1, containment: Split set tests to separate files. To make skippable. --- tests/basics/comprehension1.py | 3 +-- tests/basics/containment.py | 3 ++- tests/basics/set_comprehension.py | 1 + tests/basics/set_containment.py | 4 ++++ 4 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 tests/basics/set_comprehension.py create mode 100644 tests/basics/set_containment.py (limited to 'tests/basics') diff --git a/tests/basics/comprehension1.py b/tests/basics/comprehension1.py index 7f541ee53..892d6b4e3 100644 --- a/tests/basics/comprehension1.py +++ b/tests/basics/comprehension1.py @@ -14,7 +14,6 @@ def f(): print(d[0], d[1], d[2], d[3], d[4]) # set comprehension - - print({a for a in range(5)}) + # see set_comprehension.py f() diff --git a/tests/basics/containment.py b/tests/basics/containment.py index f8be04e92..bae366113 100644 --- a/tests/basics/containment.py +++ b/tests/basics/containment.py @@ -1,5 +1,6 @@ +# sets, see set_containment for i in 1, 2: - for o in {1:2}, {1}, {1:2}.keys(): + for o in {1:2}, {1:2}.keys(): print("{} in {}: {}".format(i, o, i in o)) print("{} not in {}: {}".format(i, o, i not in o)) diff --git a/tests/basics/set_comprehension.py b/tests/basics/set_comprehension.py new file mode 100644 index 000000000..12a9a29d3 --- /dev/null +++ b/tests/basics/set_comprehension.py @@ -0,0 +1 @@ +print({a for a in range(5)}) diff --git a/tests/basics/set_containment.py b/tests/basics/set_containment.py new file mode 100644 index 000000000..97694f74c --- /dev/null +++ b/tests/basics/set_containment.py @@ -0,0 +1,4 @@ +for i in 1, 2: + for o in {}, {1}, {2}: + print("{} in {}: {}".format(i, o, i in o)) + print("{} not in {}: {}".format(i, o, i not in o)) -- cgit v1.2.3 From d61ce3202278e9ad251bde0e6075a7d841b7639e Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Tue, 14 Feb 2017 23:27:44 +0300 Subject: tests/builtin_dir: The most expected thing in sys is exit, test for it. --- tests/basics/builtin_dir.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/basics') diff --git a/tests/basics/builtin_dir.py b/tests/basics/builtin_dir.py index 843467e78..16e7e669e 100644 --- a/tests/basics/builtin_dir.py +++ b/tests/basics/builtin_dir.py @@ -5,7 +5,7 @@ print('__name__' in dir()) # dir of module import sys -print('platform' in dir(sys)) +print('exit' in dir(sys)) # dir of type print('append' in dir(list)) -- cgit v1.2.3 From 83623b2fdeee0ada918ee4f91a99f3d732c3dee7 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Wed, 15 Feb 2017 00:57:56 +0300 Subject: tests/basic/[a-f]*: Make skippable. For small ports which don't have all features enabled. --- tests/basics/array_micropython.py | 7 ++++++- tests/basics/attrtuple1.py | 9 +++++++++ tests/basics/builtin_delattr.py | 6 ++++++ tests/basics/builtin_minmax.py | 7 +++++++ tests/basics/builtin_override.py | 8 +++++++- tests/basics/builtin_range.py | 11 ----------- tests/basics/builtin_range_attrs.py | 19 +++++++++++++++++++ tests/basics/builtin_reversed.py | 6 ++++++ tests/basics/class_descriptor.py | 7 +++++++ tests/basics/class_new.py | 8 ++++++++ tests/basics/class_store_class.py | 7 ++++++- tests/basics/class_super_object.py | 8 ++++++++ tests/basics/dict_fromkeys.py | 3 ++- tests/basics/enumerate.py | 7 +++++++ tests/basics/filter.py | 7 +++++++ 15 files changed, 105 insertions(+), 15 deletions(-) create mode 100644 tests/basics/builtin_range_attrs.py (limited to 'tests/basics') diff --git a/tests/basics/array_micropython.py b/tests/basics/array_micropython.py index 8e904bdfe..0c1df0923 100644 --- a/tests/basics/array_micropython.py +++ b/tests/basics/array_micropython.py @@ -1,5 +1,10 @@ # test MicroPython-specific features of array.array -import array +try: + import array +except ImportError: + import sys + print("SKIP") + sys.exit() # arrays of objects a = array.array('O') diff --git a/tests/basics/attrtuple1.py b/tests/basics/attrtuple1.py index c4daaaf25..597bfc2a3 100644 --- a/tests/basics/attrtuple1.py +++ b/tests/basics/attrtuple1.py @@ -4,6 +4,15 @@ import sys t = sys.implementation +# It can be just a normal tuple on small ports +try: + t.name +except AttributeError: + import sys + print("SKIP") + sys.exit() + + # test printing of attrtuple print(str(t).find("version=") > 0) diff --git a/tests/basics/builtin_delattr.py b/tests/basics/builtin_delattr.py index 3743df227..9b38837e4 100644 --- a/tests/basics/builtin_delattr.py +++ b/tests/basics/builtin_delattr.py @@ -1,4 +1,10 @@ # test builtin delattr +try: + delattr +except: + import sys + print("SKIP") + sys.exit() class A: pass a = A() diff --git a/tests/basics/builtin_minmax.py b/tests/basics/builtin_minmax.py index d395d4421..a925b3fe9 100644 --- a/tests/basics/builtin_minmax.py +++ b/tests/basics/builtin_minmax.py @@ -1,4 +1,11 @@ # test builtin min and max functions +try: + min + max +except: + import sys + print("SKIP") + sys.exit() print(min(0,1)) print(min(1,0)) diff --git a/tests/basics/builtin_override.py b/tests/basics/builtin_override.py index e245985ad..f3632e59a 100644 --- a/tests/basics/builtin_override.py +++ b/tests/basics/builtin_override.py @@ -3,7 +3,13 @@ import builtins # override generic builtin -builtins.abs = lambda x: x + 1 +try: + builtins.abs = lambda x: x + 1 +except AttributeError: + import sys + print("SKIP") + sys.exit() + print(abs(1)) # __build_class__ is handled in a special way diff --git a/tests/basics/builtin_range.py b/tests/basics/builtin_range.py index 59fc0344a..7c3e5beef 100644 --- a/tests/basics/builtin_range.py +++ b/tests/basics/builtin_range.py @@ -34,11 +34,6 @@ print(range(1, 4)[1:]) print(range(1, 4)[:-1]) print(range(7, -2, -4)[:]) -# attrs -print(range(1, 2, 3).start) -print(range(1, 2, 3).stop) -print(range(1, 2, 3).step) - # bad unary op try: -range(1) @@ -50,9 +45,3 @@ try: range(1)[0] = 1 except TypeError: print("TypeError") - -# bad attr (can't store) -try: - range(4).start = 0 -except AttributeError: - print('AttributeError') diff --git a/tests/basics/builtin_range_attrs.py b/tests/basics/builtin_range_attrs.py new file mode 100644 index 000000000..9327c802a --- /dev/null +++ b/tests/basics/builtin_range_attrs.py @@ -0,0 +1,19 @@ +# test attributes of builtin range type + +try: + range(0).start +except AttributeError: + import sys + print("SKIP") + sys.exit() + +# attrs +print(range(1, 2, 3).start) +print(range(1, 2, 3).stop) +print(range(1, 2, 3).step) + +# bad attr (can't store) +try: + range(4).start = 0 +except AttributeError: + print('AttributeError') diff --git a/tests/basics/builtin_reversed.py b/tests/basics/builtin_reversed.py index f129a4f5d..59e9c7821 100644 --- a/tests/basics/builtin_reversed.py +++ b/tests/basics/builtin_reversed.py @@ -1,4 +1,10 @@ # test the builtin reverse() function +try: + reversed +except: + import sys + print("SKIP") + sys.exit() # list print(list(reversed([]))) diff --git a/tests/basics/class_descriptor.py b/tests/basics/class_descriptor.py index 25b373e47..7f295f071 100644 --- a/tests/basics/class_descriptor.py +++ b/tests/basics/class_descriptor.py @@ -18,6 +18,13 @@ class Main: Forward = Descriptor() m = Main() +try: + m.__class__ +except AttributeError: + import sys + print("SKIP") + sys.exit() + r = m.Forward if 'Descriptor' in repr(r.__class__): print('SKIP') diff --git a/tests/basics/class_new.py b/tests/basics/class_new.py index a6a34c581..0198456b2 100644 --- a/tests/basics/class_new.py +++ b/tests/basics/class_new.py @@ -1,3 +1,11 @@ +try: + # If we don't expose object.__new__ (small ports), there's + # nothing to test. + object.__new__ +except AttributeError: + import sys + print("SKIP") + sys.exit() class A: def __new__(cls): print("A.__new__") diff --git a/tests/basics/class_store_class.py b/tests/basics/class_store_class.py index 10b94d3c6..00a291586 100644 --- a/tests/basics/class_store_class.py +++ b/tests/basics/class_store_class.py @@ -5,7 +5,12 @@ try: from collections import namedtuple except ImportError: - from ucollections import namedtuple + try: + from ucollections import namedtuple + except ImportError: + import sys + print("SKIP") + sys.exit() _DefragResultBase = namedtuple('DefragResult', [ 'foo', 'bar' ]) diff --git a/tests/basics/class_super_object.py b/tests/basics/class_super_object.py index 21b97328e..a841d34ab 100644 --- a/tests/basics/class_super_object.py +++ b/tests/basics/class_super_object.py @@ -1,4 +1,12 @@ # Calling object.__init__() via super().__init__ +try: + # If we don't expose object.__init__ (small ports), there's + # nothing to test. + object.__init__ +except AttributeError: + import sys + print("SKIP") + sys.exit() class Test(object): def __init__(self): diff --git a/tests/basics/dict_fromkeys.py b/tests/basics/dict_fromkeys.py index bfad347c8..796f657d7 100644 --- a/tests/basics/dict_fromkeys.py +++ b/tests/basics/dict_fromkeys.py @@ -9,5 +9,6 @@ l.sort() print(l) # argument to fromkeys has no __len__ -d = dict.fromkeys(reversed(range(1))) +#d = dict.fromkeys(reversed(range(1))) +d = dict.fromkeys((x for x in range(1))) print(d) diff --git a/tests/basics/enumerate.py b/tests/basics/enumerate.py index 00595cb0f..3cc1350a0 100644 --- a/tests/basics/enumerate.py +++ b/tests/basics/enumerate.py @@ -1,3 +1,10 @@ +try: + enumerate +except: + import sys + print("SKIP") + sys.exit() + print(list(enumerate([]))) print(list(enumerate([1, 2, 3]))) print(list(enumerate([1, 2, 3], 5))) diff --git a/tests/basics/filter.py b/tests/basics/filter.py index 5883e3d00..d0b36733c 100644 --- a/tests/basics/filter.py +++ b/tests/basics/filter.py @@ -1,2 +1,9 @@ +try: + filter +except: + import sys + print("SKIP") + sys.exit() + print(list(filter(lambda x: x & 1, range(-3, 4)))) print(list(filter(None, range(-3, 4)))) -- cgit v1.2.3 From 7bb146350e5de1f406dc69679ecdf4cdded5be75 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Wed, 15 Feb 2017 01:30:16 +0300 Subject: tests/dict_fromkeys: Revert to use reversed() to run in native codegen mode. --- tests/basics/dict_fromkeys.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/basics') diff --git a/tests/basics/dict_fromkeys.py b/tests/basics/dict_fromkeys.py index 796f657d7..118d0ffd9 100644 --- a/tests/basics/dict_fromkeys.py +++ b/tests/basics/dict_fromkeys.py @@ -9,6 +9,6 @@ l.sort() print(l) # argument to fromkeys has no __len__ -#d = dict.fromkeys(reversed(range(1))) -d = dict.fromkeys((x for x in range(1))) +d = dict.fromkeys(reversed(range(1))) +#d = dict.fromkeys((x for x in range(1))) print(d) -- cgit v1.2.3 From b737c9cbc823b012808ae08c8b285b4e1543703a Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Wed, 15 Feb 2017 17:05:27 +0300 Subject: tests/gen_yield_from_close: Use range() instead of reversed(). As a "more basic" builtin iterator, present even in smaller ports. --- tests/basics/gen_yield_from_close.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/basics') diff --git a/tests/basics/gen_yield_from_close.py b/tests/basics/gen_yield_from_close.py index d66691ff9..833986105 100644 --- a/tests/basics/gen_yield_from_close.py +++ b/tests/basics/gen_yield_from_close.py @@ -102,7 +102,7 @@ except RuntimeError: # case where close is propagated up to a built-in iterator def gen8(): - g = reversed([2, 1]) + g = range(2) yield from g g = gen8() print(next(g)) -- cgit v1.2.3 From f980c70997eb9748ed169d486489ab3d0d2002af Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Wed, 15 Feb 2017 18:11:16 +0300 Subject: tests/basic/: Make various tests skippable. To run the testsuite on small ports. --- tests/basics/iter_of_iter.py | 3 +- tests/basics/map.py | 2 +- tests/basics/memoryview1.py | 6 ++ tests/basics/memoryview2.py | 9 ++- tests/basics/memoryview_gc.py | 6 ++ tests/basics/namedtuple1.py | 9 ++- tests/basics/object_new.py | 8 ++ tests/basics/op_error.py | 1 - tests/basics/op_error_memoryview.py | 19 +++++ tests/basics/set_iter_of_iter.py | 2 + tests/basics/special_methods.py | 40 +--------- tests/basics/special_methods2.py | 145 +++++++++++++++++++++++++++++++++++ tests/basics/subclass_classmethod.py | 7 ++ tests/basics/sys1.py | 14 +++- 14 files changed, 222 insertions(+), 49 deletions(-) create mode 100644 tests/basics/op_error_memoryview.py create mode 100644 tests/basics/set_iter_of_iter.py create mode 100644 tests/basics/special_methods2.py (limited to 'tests/basics') diff --git a/tests/basics/iter_of_iter.py b/tests/basics/iter_of_iter.py index 70282aa97..d775b6a44 100644 --- a/tests/basics/iter_of_iter.py +++ b/tests/basics/iter_of_iter.py @@ -4,5 +4,4 @@ i = iter(iter([1, 2, 3])) print(list(i)) i = iter(iter({1:2, 3:4, 5:6})) print(sorted(i)) -i = iter(iter({1, 2, 3})) -print(sorted(i)) +# set, see set_iter_of_iter.py diff --git a/tests/basics/map.py b/tests/basics/map.py index 62dca44ed..8fce352c2 100644 --- a/tests/basics/map.py +++ b/tests/basics/map.py @@ -1,4 +1,4 @@ print(list(map(lambda x: x & 1, range(-3, 4)))) print(list(map(abs, range(-3, 4)))) -print(list(map(set, [[i] for i in range(-3, 4)]))) +print(list(map(tuple, [[i] for i in range(-3, 4)]))) print(list(map(pow, range(4), range(4)))) diff --git a/tests/basics/memoryview1.py b/tests/basics/memoryview1.py index 1cd411195..019a1179f 100644 --- a/tests/basics/memoryview1.py +++ b/tests/basics/memoryview1.py @@ -1,4 +1,10 @@ # test memoryview +try: + memoryview +except: + import sys + print("SKIP") + sys.exit() # test reading from bytes b = b'1234' diff --git a/tests/basics/memoryview2.py b/tests/basics/memoryview2.py index 5117d7a68..edb7c9e64 100644 --- a/tests/basics/memoryview2.py +++ b/tests/basics/memoryview2.py @@ -1,6 +1,11 @@ # test memoryview accessing maximum values for signed/unsigned elements - -from array import array +try: + from array import array + memoryview +except: + import sys + print("SKIP") + sys.exit() print(list(memoryview(b'\x7f\x80\x81\xff'))) print(list(memoryview(array('b', [0x7f, -0x80])))) diff --git a/tests/basics/memoryview_gc.py b/tests/basics/memoryview_gc.py index a1e4baad4..9d4857e36 100644 --- a/tests/basics/memoryview_gc.py +++ b/tests/basics/memoryview_gc.py @@ -1,4 +1,10 @@ # test memoryview retains pointer to original object/buffer +try: + memoryview +except: + import sys + print("SKIP") + sys.exit() b = bytearray(10) m = memoryview(b)[1:] diff --git a/tests/basics/namedtuple1.py b/tests/basics/namedtuple1.py index 346e32fbf..132dcf96b 100644 --- a/tests/basics/namedtuple1.py +++ b/tests/basics/namedtuple1.py @@ -1,7 +1,12 @@ try: - from collections import namedtuple + try: + from collections import namedtuple + except ImportError: + from ucollections import namedtuple except ImportError: - from ucollections import namedtuple + import sys + print("SKIP") + sys.exit() T = namedtuple("Tup", ["foo", "bar"]) # CPython prints fully qualified name, what we don't bother to do so far diff --git a/tests/basics/object_new.py b/tests/basics/object_new.py index befb5bfc2..568feccda 100644 --- a/tests/basics/object_new.py +++ b/tests/basics/object_new.py @@ -2,6 +2,14 @@ # (non-initialized) instance of class. # See e.g. http://infohost.nmt.edu/tcc/help/pubs/python/web/new-new-method.html # TODO: Find reference in CPython docs +try: + # If we don't expose object.__new__ (small ports), there's + # nothing to test. + object.__new__ +except AttributeError: + import sys + print("SKIP") + sys.exit() class Foo: diff --git a/tests/basics/op_error.py b/tests/basics/op_error.py index 19ce04bc5..5ba6a80e2 100644 --- a/tests/basics/op_error.py +++ b/tests/basics/op_error.py @@ -20,7 +20,6 @@ test_exc("False in True", TypeError) test_exc("1 * {}", TypeError) test_exc("1 in 1", TypeError) test_exc("bytearray() // 2", TypeError) -test_exc("m = memoryview(bytearray())\nm += bytearray()", TypeError) # object with buffer protocol needed on rhs test_exc("bytearray(1) + 1", TypeError) diff --git a/tests/basics/op_error_memoryview.py b/tests/basics/op_error_memoryview.py new file mode 100644 index 000000000..658ededc8 --- /dev/null +++ b/tests/basics/op_error_memoryview.py @@ -0,0 +1,19 @@ +# test errors from bad operations (unary, binary, etc) +try: + memoryview +except: + import sys + print("SKIP") + sys.exit() + +def test_exc(code, exc): + try: + exec(code) + print("no exception") + except exc: + print("right exception") + except: + print("wrong exception") + +# unsupported binary operators +test_exc("m = memoryview(bytearray())\nm += bytearray()", TypeError) diff --git a/tests/basics/set_iter_of_iter.py b/tests/basics/set_iter_of_iter.py new file mode 100644 index 000000000..e3e91fa45 --- /dev/null +++ b/tests/basics/set_iter_of_iter.py @@ -0,0 +1,2 @@ +i = iter(iter({1, 2, 3})) +print(sorted(i)) diff --git a/tests/basics/special_methods.py b/tests/basics/special_methods.py index 1df7a7c4c..9f57247c1 100644 --- a/tests/basics/special_methods.py +++ b/tests/basics/special_methods.py @@ -105,42 +105,4 @@ cud1 > cud2 cud1 + cud2 cud1 - cud2 -# the following require MICROPY_PY_ALL_SPECIAL_METHODS -+cud1 --cud1 -~cud1 -cud1 * cud2 -cud1 / cud2 -cud2 // cud1 -cud1 += cud2 -cud1 -= cud2 - -# TODO: the following operations are not supported on every ports -# -# ne is not supported, !(eq) is called instead -#cud1 != cud2 -# -# binary and is not supported -# cud1 & cud2 -# -# binary lshift is not supported -# cud1<<1 -# -# modulus is not supported -# cud1 % 2 -# -# binary or is not supported -# cud1 | cud2 -# -# pow is not supported -# cud1**2 -# -# rshift is not suported -# cud1>>1 -# -# xor is not supported -# cud1^cud2 -# -# in the followin test, cpython still calls __eq__ -# cud3=cud1 -# cud3==cud1 +# more in special_methods2.py diff --git a/tests/basics/special_methods2.py b/tests/basics/special_methods2.py new file mode 100644 index 000000000..3623b30dc --- /dev/null +++ b/tests/basics/special_methods2.py @@ -0,0 +1,145 @@ +class Cud(): + + def __init__(self): + #print("__init__ called") + pass + + def __repr__(self): + print("__repr__ called") + return "" + + def __lt__(self, other): + print("__lt__ called") + + def __le__(self, other): + print("__le__ called") + + def __eq__(self, other): + print("__eq__ called") + + def __ne__(self, other): + print("__ne__ called") + + def __ge__(self, other): + print("__ge__ called") + + def __gt__(self, other): + print("__gt__ called") + + def __abs__(self): + print("__abs__ called") + + def __add__(self, other): + print("__add__ called") + + def __and__(self, other): + print("__and__ called") + + def __floordiv__(self, other): + print("__floordiv__ called") + + def __index__(self, other): + print("__index__ called") + + def __inv__(self): + print("__inv__ called") + + def __invert__(self): + print("__invert__ called") + + def __lshift__(self, val): + print("__lshift__ called") + + def __mod__(self, val): + print("__mod__ called") + + def __mul__(self, other): + print("__mul__ called") + + def __matmul__(self, other): + print("__matmul__ called") + + def __neg__(self): + print("__neg__ called") + + def __or__(self, other): + print("__or__ called") + + def __pos__(self): + print("__pos__ called") + + def __pow__(self, val): + print("__pow__ called") + + def __rshift__(self, val): + print("__rshift__ called") + + def __sub__(self, other): + print("__sub__ called") + + def __truediv__(self, other): + print("__truediv__ called") + + def __div__(self, other): + print("__div__ called") + + def __xor__(self, other): + print("__xor__ called") + + def __iadd__(self, other): + print("__iadd__ called") + return self + + def __isub__(self, other): + print("__isub__ called") + return self + +cud1 = Cud() +cud2 = Cud() + +try: + +cud1 +except TypeError: + import sys + print("SKIP") + sys.exit() + +# the following require MICROPY_PY_ALL_SPECIAL_METHODS ++cud1 +-cud1 +~cud1 +cud1 * cud2 +cud1 / cud2 +cud2 // cud1 +cud1 += cud2 +cud1 -= cud2 + +# TODO: the following operations are not supported on every ports +# +# ne is not supported, !(eq) is called instead +#cud1 != cud2 +# +# binary and is not supported +# cud1 & cud2 +# +# binary lshift is not supported +# cud1<<1 +# +# modulus is not supported +# cud1 % 2 +# +# binary or is not supported +# cud1 | cud2 +# +# pow is not supported +# cud1**2 +# +# rshift is not suported +# cud1>>1 +# +# xor is not supported +# cud1^cud2 +# +# in the followin test, cpython still calls __eq__ +# cud3=cud1 +# cud3==cud1 diff --git a/tests/basics/subclass_classmethod.py b/tests/basics/subclass_classmethod.py index ae5fbd1aa..48f164b36 100644 --- a/tests/basics/subclass_classmethod.py +++ b/tests/basics/subclass_classmethod.py @@ -5,6 +5,13 @@ class Base: def foo(cls): print(cls.__name__) +try: + Base.__name__ +except AttributeError: + import sys + print("SKIP") + sys.exit() + class Sub(Base): pass diff --git a/tests/basics/sys1.py b/tests/basics/sys1.py index 816c8823a..29ef974d1 100644 --- a/tests/basics/sys1.py +++ b/tests/basics/sys1.py @@ -6,8 +6,18 @@ print(sys.__name__) print(type(sys.path)) print(type(sys.argv)) print(sys.byteorder in ('little', 'big')) -print(sys.maxsize > 100) -print(sys.implementation.name in ('cpython', 'micropython')) + +try: + print(sys.maxsize > 100) +except AttributeError: + # Effectively skip subtests + print(True) + +try: + print(sys.implementation.name in ('cpython', 'micropython')) +except AttributeError: + # Effectively skip subtests + print(True) try: sys.exit() -- cgit v1.2.3 From d87c6b676855a8f19586e7ac637fe5f1dbc31cbc Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 17 Feb 2017 12:30:27 +1100 Subject: tests/basics/string_join: Add more tests for string concatenation. --- tests/basics/string_join.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'tests/basics') diff --git a/tests/basics/string_join.py b/tests/basics/string_join.py index b8694c01e..4a2e9aa91 100644 --- a/tests/basics/string_join.py +++ b/tests/basics/string_join.py @@ -25,3 +25,13 @@ except TypeError: # joined by the compiler print("a" "b") +print("a" '''b''') +print("a" # inline comment + "b") +print("a" \ + "b") + +# the following should not be joined by the compiler +x = 'a' +'b' +print(x) -- cgit v1.2.3 From 89267886cc6d3889d35e29b3273164d713ac2347 Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 20 Feb 2017 15:09:59 +1100 Subject: py/objlist: For list slice assignment, allow RHS to be a tuple or list. Before this patch, assigning anything other than a list would lead to a crash. Fixes issue #2886. --- py/objlist.c | 10 +++++----- tests/basics/list_slice_assign.py | 11 +++++++++++ 2 files changed, 16 insertions(+), 5 deletions(-) (limited to 'tests/basics') diff --git a/py/objlist.c b/py/objlist.c index 55ee19120..ba7898415 100644 --- a/py/objlist.c +++ b/py/objlist.c @@ -192,13 +192,13 @@ STATIC mp_obj_t list_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { #if MICROPY_PY_BUILTINS_SLICE if (MP_OBJ_IS_TYPE(index, &mp_type_slice)) { mp_obj_list_t *self = MP_OBJ_TO_PTR(self_in); - mp_check_self(MP_OBJ_IS_TYPE(value, &mp_type_list)); - mp_obj_list_t *slice = MP_OBJ_TO_PTR(value); + mp_uint_t value_len; mp_obj_t *value_items; + mp_obj_get_array(value, &value_len, &value_items); mp_bound_slice_t slice_out; if (!mp_seq_get_fast_slice_indexes(self->len, index, &slice_out)) { mp_not_implemented(""); } - mp_int_t len_adj = slice->len - (slice_out.stop - slice_out.start); + mp_int_t len_adj = value_len - (slice_out.stop - slice_out.start); //printf("Len adj: %d\n", len_adj); if (len_adj > 0) { if (self->len + len_adj > self->alloc) { @@ -208,10 +208,10 @@ STATIC mp_obj_t list_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { self->alloc = self->len + len_adj; } mp_seq_replace_slice_grow_inplace(self->items, self->len, - slice_out.start, slice_out.stop, slice->items, slice->len, len_adj, sizeof(*self->items)); + slice_out.start, slice_out.stop, value_items, value_len, len_adj, sizeof(*self->items)); } else { mp_seq_replace_slice_no_grow(self->items, self->len, - slice_out.start, slice_out.stop, slice->items, slice->len, sizeof(*self->items)); + slice_out.start, slice_out.stop, value_items, value_len, sizeof(*self->items)); // Clear "freed" elements at the end of list mp_seq_clear(self->items, self->len + len_adj, self->len, sizeof(*self->items)); // TODO: apply allocation policy re: alloc_size diff --git a/tests/basics/list_slice_assign.py b/tests/basics/list_slice_assign.py index baa9a0081..1ad1ef27c 100644 --- a/tests/basics/list_slice_assign.py +++ b/tests/basics/list_slice_assign.py @@ -34,3 +34,14 @@ print(l) l = list(x) del l[:-3] print(l) + +# assign a tuple +l = [1, 2, 3] +l[0:1] = (10, 11, 12) +print(l) + +# RHS of slice must be an iterable +try: + [][0:1] = 123 +except TypeError: + print('TypeError') -- cgit v1.2.3 From f4a12dca58c53f11a6e89424a47158fe6e48ade9 Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 27 Feb 2017 16:09:57 +1100 Subject: py/objarray: Disallow slice-assignment to read-only memoryview. Also comes with a test for this. Fixes issue #2904. --- py/objarray.c | 4 ++++ tests/basics/memoryview1.py | 4 ++++ 2 files changed, 8 insertions(+) (limited to 'tests/basics') diff --git a/py/objarray.c b/py/objarray.c index 1b590f3c0..a84a63151 100644 --- a/py/objarray.c +++ b/py/objarray.c @@ -418,6 +418,10 @@ STATIC mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value uint8_t* dest_items = o->items; #if MICROPY_PY_BUILTINS_MEMORYVIEW if (o->base.type == &mp_type_memoryview) { + if ((o->typecode & 0x80) == 0) { + // store to read-only memoryview not allowed + return MP_OBJ_NULL; + } if (len_adj != 0) { goto compat_error; } diff --git a/tests/basics/memoryview1.py b/tests/basics/memoryview1.py index 019a1179f..a771acdda 100644 --- a/tests/basics/memoryview1.py +++ b/tests/basics/memoryview1.py @@ -18,6 +18,10 @@ try: m[0] = 1 except TypeError: print("TypeError") +try: + m[0:2] = b'00' +except TypeError: + print("TypeError") # test writing to bytearray b = bytearray(b) -- cgit v1.2.3 From 3d91c12d3382226263ea3d660b48f1ef1125d099 Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 3 Mar 2017 11:23:54 +1100 Subject: tests/basics: Add further tests for OrderedDict. --- tests/basics/ordereddict1.py | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'tests/basics') diff --git a/tests/basics/ordereddict1.py b/tests/basics/ordereddict1.py index 5e8b2413b..7147968c5 100644 --- a/tests/basics/ordereddict1.py +++ b/tests/basics/ordereddict1.py @@ -9,8 +9,19 @@ except ImportError: sys.exit() d = OrderedDict([(10, 20), ("b", 100), (1, 2)]) +print(len(d)) print(list(d.keys())) print(list(d.values())) del d["b"] +print(len(d)) +print(list(d.keys())) +print(list(d.values())) + +# access remaining elements after deleting +print(d[10], d[1]) + +# add an element after deleting +d["abc"] = 123 +print(len(d)) print(list(d.keys())) print(list(d.values())) -- cgit v1.2.3 From 3ab6aa3a6d0506e805caa19369bef279c1c789b4 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sat, 4 Mar 2017 00:13:27 +0300 Subject: tests/basic: Split tests into working with small ints and not working. Tests which don't work with small ints are suffixed with _intbig.py. Some of these may still work with long long ints and need to be reclassified later. --- tests/basics/array_intbig.py | 20 +++++++ tests/basics/array_q.py | 20 ------- tests/basics/builtin_abs.py | 8 --- tests/basics/builtin_abs_intbig.py | 9 +++ tests/basics/builtin_bin.py | 1 - tests/basics/builtin_bin_intbig.py | 3 + tests/basics/builtin_divmod.py | 12 ---- tests/basics/builtin_divmod_intbig.py | 13 +++++ tests/basics/builtin_hash.py | 8 --- tests/basics/builtin_hash_intbig.py | 10 ++++ tests/basics/builtin_hex.py | 3 - tests/basics/builtin_hex_intbig.py | 4 ++ tests/basics/builtin_oct.py | 3 - tests/basics/builtin_oct_intbig.py | 4 ++ tests/basics/builtin_pow3.py | 14 ----- tests/basics/builtin_pow3_intbig.py | 23 ++++++++ tests/basics/bytearray_intbig.py | 1 + tests/basics/bytearray_longint.py | 1 - tests/basics/bytes_construct.py | 3 - tests/basics/bytes_construct_intbig.py | 4 ++ tests/basics/floordivide.py | 15 ----- tests/basics/floordivide_intbig.py | 15 +++++ tests/basics/int_big1.py | 97 +++++++++++++++++++++++++++++++++ tests/basics/int_bytes.py | 1 - tests/basics/int_bytes_intbig.py | 9 +++ tests/basics/int_bytes_long.py | 7 --- tests/basics/int_constfolding.py | 14 ----- tests/basics/int_constfolding_intbig.py | 19 +++++++ tests/basics/int_divmod.py | 8 --- tests/basics/int_divmod_intbig.py | 9 +++ tests/basics/int_intbig.py | 54 ++++++++++++++++++ tests/basics/int_long.py | 54 ------------------ tests/basics/int_mpz.py | 97 --------------------------------- tests/basics/op_error.py | 1 - tests/basics/op_error_intbig.py | 13 +++++ tests/basics/slice_bignum.py | 5 -- tests/basics/slice_intbig.py | 5 ++ tests/basics/struct1.py | 28 ---------- tests/basics/struct1_intbig.py | 37 +++++++++++++ tests/run-tests | 2 +- 40 files changed, 350 insertions(+), 304 deletions(-) create mode 100644 tests/basics/array_intbig.py delete mode 100644 tests/basics/array_q.py create mode 100644 tests/basics/builtin_abs_intbig.py create mode 100644 tests/basics/builtin_bin_intbig.py create mode 100644 tests/basics/builtin_divmod_intbig.py create mode 100644 tests/basics/builtin_hash_intbig.py create mode 100644 tests/basics/builtin_hex_intbig.py create mode 100644 tests/basics/builtin_oct_intbig.py create mode 100644 tests/basics/builtin_pow3_intbig.py create mode 100644 tests/basics/bytearray_intbig.py delete mode 100644 tests/basics/bytearray_longint.py create mode 100644 tests/basics/bytes_construct_intbig.py create mode 100644 tests/basics/floordivide_intbig.py create mode 100644 tests/basics/int_big1.py create mode 100644 tests/basics/int_bytes_intbig.py delete mode 100644 tests/basics/int_bytes_long.py create mode 100644 tests/basics/int_constfolding_intbig.py create mode 100644 tests/basics/int_divmod_intbig.py create mode 100644 tests/basics/int_intbig.py delete mode 100644 tests/basics/int_long.py delete mode 100644 tests/basics/int_mpz.py create mode 100644 tests/basics/op_error_intbig.py delete mode 100644 tests/basics/slice_bignum.py create mode 100644 tests/basics/slice_intbig.py create mode 100644 tests/basics/struct1_intbig.py (limited to 'tests/basics') diff --git a/tests/basics/array_intbig.py b/tests/basics/array_intbig.py new file mode 100644 index 000000000..2975cd385 --- /dev/null +++ b/tests/basics/array_intbig.py @@ -0,0 +1,20 @@ +# test array('q') and array('Q') + +try: + from array import array +except ImportError: + import sys + print("SKIP") + sys.exit() + +print(array('q')) +print(array('Q')) + +print(array('q', [0])) +print(array('Q', [0])) + +print(array('q', [-2**63, -1, 0, 1, 2, 2**63-1])) +print(array('Q', [0, 1, 2, 2**64-1])) + +print(bytes(array('q', [-1]))) +print(bytes(array('Q', [2**64-1]))) diff --git a/tests/basics/array_q.py b/tests/basics/array_q.py deleted file mode 100644 index 2975cd385..000000000 --- a/tests/basics/array_q.py +++ /dev/null @@ -1,20 +0,0 @@ -# test array('q') and array('Q') - -try: - from array import array -except ImportError: - import sys - print("SKIP") - sys.exit() - -print(array('q')) -print(array('Q')) - -print(array('q', [0])) -print(array('Q', [0])) - -print(array('q', [-2**63, -1, 0, 1, 2, 2**63-1])) -print(array('Q', [0, 1, 2, 2**64-1])) - -print(bytes(array('q', [-1]))) -print(bytes(array('Q', [2**64-1]))) diff --git a/tests/basics/builtin_abs.py b/tests/basics/builtin_abs.py index 788bc450f..142344e22 100644 --- a/tests/basics/builtin_abs.py +++ b/tests/basics/builtin_abs.py @@ -4,11 +4,3 @@ print(abs(False)) print(abs(True)) print(abs(1)) print(abs(-1)) - -# bignum -print(abs(123456789012345678901234567890)) -print(abs(-123456789012345678901234567890)) - -# edge cases for 32 and 64 bit archs (small int overflow when negating) -print(abs(-0x3fffffff - 1)) -print(abs(-0x3fffffffffffffff - 1)) diff --git a/tests/basics/builtin_abs_intbig.py b/tests/basics/builtin_abs_intbig.py new file mode 100644 index 000000000..3dd5ea89f --- /dev/null +++ b/tests/basics/builtin_abs_intbig.py @@ -0,0 +1,9 @@ +# test builtin abs + +# bignum +print(abs(123456789012345678901234567890)) +print(abs(-123456789012345678901234567890)) + +# edge cases for 32 and 64 bit archs (small int overflow when negating) +print(abs(-0x3fffffff - 1)) +print(abs(-0x3fffffffffffffff - 1)) diff --git a/tests/basics/builtin_bin.py b/tests/basics/builtin_bin.py index f6b6079de..85af406ce 100644 --- a/tests/basics/builtin_bin.py +++ b/tests/basics/builtin_bin.py @@ -8,5 +8,4 @@ print(bin(-15)) print(bin(12345)) print(bin(0b10101)) -print(bin(12345678901234567890)) print(bin(0b10101010101010101010)) diff --git a/tests/basics/builtin_bin_intbig.py b/tests/basics/builtin_bin_intbig.py new file mode 100644 index 000000000..345e1f687 --- /dev/null +++ b/tests/basics/builtin_bin_intbig.py @@ -0,0 +1,3 @@ +# test builtin bin function + +print(bin(12345678901234567890)) diff --git a/tests/basics/builtin_divmod.py b/tests/basics/builtin_divmod.py index c3b865819..26b3ae382 100644 --- a/tests/basics/builtin_divmod.py +++ b/tests/basics/builtin_divmod.py @@ -9,19 +9,7 @@ try: except ZeroDivisionError: print("ZeroDivisionError") -try: - divmod(1 << 65, 0) -except ZeroDivisionError: - print("ZeroDivisionError") - try: divmod('a', 'b') except TypeError: print("TypeError") - -# bignum -l = (1 << 65) + 123 -print(divmod(3, l)) -print(divmod(l, 5)) -print(divmod(l + 3, l)) -print(divmod(l * 20, l + 2)) diff --git a/tests/basics/builtin_divmod_intbig.py b/tests/basics/builtin_divmod_intbig.py new file mode 100644 index 000000000..758e83415 --- /dev/null +++ b/tests/basics/builtin_divmod_intbig.py @@ -0,0 +1,13 @@ +# test builtin divmod + +try: + divmod(1 << 65, 0) +except ZeroDivisionError: + print("ZeroDivisionError") + +# bignum +l = (1 << 65) + 123 +print(divmod(3, l)) +print(divmod(l, 5)) +print(divmod(l + 3, l)) +print(divmod(l * 20, l + 2)) diff --git a/tests/basics/builtin_hash.py b/tests/basics/builtin_hash.py index ffea08e57..704895fbb 100644 --- a/tests/basics/builtin_hash.py +++ b/tests/basics/builtin_hash.py @@ -4,8 +4,6 @@ print(hash(False)) print(hash(True)) print({():1}) # hash tuple print({(1,):1}) # hash non-empty tuple -print({1 << 66:1}) # hash big int -print({-(1 << 66):2}) # hash negative big int print(hash in {hash:1}) # hash function try: @@ -50,9 +48,3 @@ class E: def __hash__(self): return True print(hash(E())) - -# __hash__ returning a large number should be truncated -class F: - def __hash__(self): - return 1 << 70 | 1 -print(hash(F()) != 0) diff --git a/tests/basics/builtin_hash_intbig.py b/tests/basics/builtin_hash_intbig.py new file mode 100644 index 000000000..0092c0f3a --- /dev/null +++ b/tests/basics/builtin_hash_intbig.py @@ -0,0 +1,10 @@ +# test builtin hash function + +print({1 << 66:1}) # hash big int +print({-(1 << 66):2}) # hash negative big int + +# __hash__ returning a large number should be truncated +class F: + def __hash__(self): + return 1 << 70 | 1 +print(hash(F()) != 0) diff --git a/tests/basics/builtin_hex.py b/tests/basics/builtin_hex.py index 7d1c98a7a..95d74257e 100644 --- a/tests/basics/builtin_hex.py +++ b/tests/basics/builtin_hex.py @@ -7,6 +7,3 @@ print(hex(-15)) print(hex(12345)) print(hex(0x12345)) - -print(hex(12345678901234567890)) -print(hex(0x12345678901234567890)) diff --git a/tests/basics/builtin_hex_intbig.py b/tests/basics/builtin_hex_intbig.py new file mode 100644 index 000000000..7049ca3f5 --- /dev/null +++ b/tests/basics/builtin_hex_intbig.py @@ -0,0 +1,4 @@ +# test builtin hex function + +print(hex(12345678901234567890)) +print(hex(0x12345678901234567890)) diff --git a/tests/basics/builtin_oct.py b/tests/basics/builtin_oct.py index d8ba8e434..6dc48a6fa 100644 --- a/tests/basics/builtin_oct.py +++ b/tests/basics/builtin_oct.py @@ -7,6 +7,3 @@ print(oct(-15)) print(oct(12345)) print(oct(0o12345)) - -print(oct(12345678901234567890)) -print(oct(0o12345670123456701234)) diff --git a/tests/basics/builtin_oct_intbig.py b/tests/basics/builtin_oct_intbig.py new file mode 100644 index 000000000..4dc28ab46 --- /dev/null +++ b/tests/basics/builtin_oct_intbig.py @@ -0,0 +1,4 @@ +# test builtin oct function + +print(oct(12345678901234567890)) +print(oct(0o12345670123456701234)) diff --git a/tests/basics/builtin_pow3.py b/tests/basics/builtin_pow3.py index 35e143a38..dec7253bb 100644 --- a/tests/basics/builtin_pow3.py +++ b/tests/basics/builtin_pow3.py @@ -8,8 +8,6 @@ except NotImplementedError: print("SKIP") sys.exit() -print(pow(555557, 1000002, 1000003)) - # 3 arg pow is defined to only work on integers try: print(pow("x", 5, 6)) @@ -25,15 +23,3 @@ try: print(pow(4, 5, "z")) except TypeError: print("TypeError expected") - -# Tests for 3 arg pow with large values - -# This value happens to be prime -x = 0xd48a1e2a099b1395895527112937a391d02d4a208bce5d74b281cf35a57362502726f79a632f063a83c0eba66196712d963aa7279ab8a504110a668c0fc38a7983c51e6ee7a85cae87097686ccdc359ee4bbf2c583bce524e3f7836bded1c771a4efcb25c09460a862fc98e18f7303df46aaeb34da46b0c4d61d5cd78350f3edb60e6bc4befa712a849 -y = 0x3accf60bb1a5365e4250d1588eb0fe6cd81ad495e9063f90880229f2a625e98c59387238670936afb2cafc5b79448e4414d6cd5e9901aa845aa122db58ddd7b9f2b17414600a18c47494ed1f3d49d005a5 - -print(hex(pow(2, 200, x))) # Should not overflow, just 1 << 200 -print(hex(pow(2, x-1, x))) # Should be 1, since x is prime -print(hex(pow(y, x-1, x))) # Should be 1, since x is prime -print(hex(pow(y, y-1, x))) # Should be a 'big value' -print(hex(pow(y, y-1, y))) # Should be a 'big value' diff --git a/tests/basics/builtin_pow3_intbig.py b/tests/basics/builtin_pow3_intbig.py new file mode 100644 index 000000000..9f482cbde --- /dev/null +++ b/tests/basics/builtin_pow3_intbig.py @@ -0,0 +1,23 @@ +# test builtin pow() with integral values +# 3 arg version + +try: + print(pow(3, 4, 7)) +except NotImplementedError: + import sys + print("SKIP") + sys.exit() + +print(pow(555557, 1000002, 1000003)) + +# Tests for 3 arg pow with large values + +# This value happens to be prime +x = 0xd48a1e2a099b1395895527112937a391d02d4a208bce5d74b281cf35a57362502726f79a632f063a83c0eba66196712d963aa7279ab8a504110a668c0fc38a7983c51e6ee7a85cae87097686ccdc359ee4bbf2c583bce524e3f7836bded1c771a4efcb25c09460a862fc98e18f7303df46aaeb34da46b0c4d61d5cd78350f3edb60e6bc4befa712a849 +y = 0x3accf60bb1a5365e4250d1588eb0fe6cd81ad495e9063f90880229f2a625e98c59387238670936afb2cafc5b79448e4414d6cd5e9901aa845aa122db58ddd7b9f2b17414600a18c47494ed1f3d49d005a5 + +print(hex(pow(2, 200, x))) # Should not overflow, just 1 << 200 +print(hex(pow(2, x-1, x))) # Should be 1, since x is prime +print(hex(pow(y, x-1, x))) # Should be 1, since x is prime +print(hex(pow(y, y-1, x))) # Should be a 'big value' +print(hex(pow(y, y-1, y))) # Should be a 'big value' diff --git a/tests/basics/bytearray_intbig.py b/tests/basics/bytearray_intbig.py new file mode 100644 index 000000000..334eabe12 --- /dev/null +++ b/tests/basics/bytearray_intbig.py @@ -0,0 +1 @@ +print(bytearray(2**65 - (2**65 - 1))) diff --git a/tests/basics/bytearray_longint.py b/tests/basics/bytearray_longint.py deleted file mode 100644 index 334eabe12..000000000 --- a/tests/basics/bytearray_longint.py +++ /dev/null @@ -1 +0,0 @@ -print(bytearray(2**65 - (2**65 - 1))) diff --git a/tests/basics/bytes_construct.py b/tests/basics/bytes_construct.py index 59e02f063..164738767 100644 --- a/tests/basics/bytes_construct.py +++ b/tests/basics/bytes_construct.py @@ -11,9 +11,6 @@ print(bytes(bytearray(4))) print(bytes(array('b', [1, 2]))) print(bytes(array('h', [0x101, 0x202]))) -# long ints -print(ord(bytes([14953042807679334000 & 0xff]))) - # constructor value out of range try: bytes([-1]) diff --git a/tests/basics/bytes_construct_intbig.py b/tests/basics/bytes_construct_intbig.py new file mode 100644 index 000000000..c32de185f --- /dev/null +++ b/tests/basics/bytes_construct_intbig.py @@ -0,0 +1,4 @@ +# test construction of bytes from different objects + +# long ints +print(ord(bytes([14953042807679334000 & 0xff]))) diff --git a/tests/basics/floordivide.py b/tests/basics/floordivide.py index 930313d6c..60e7634b1 100644 --- a/tests/basics/floordivide.py +++ b/tests/basics/floordivide.py @@ -12,18 +12,3 @@ print(a // b) print(a // -b) print(-a // b) print(-a // -b) - -if True: - a = 987654321987987987987987987987 - b = 19 - - print(a // b) - print(a // -b) - print(-a // b) - print(-a // -b) - a = 10000000000000000000000000000000000000000000 - b = 100 - print(a // b) - print(a // -b) - print(-a // b) - print(-a // -b) diff --git a/tests/basics/floordivide_intbig.py b/tests/basics/floordivide_intbig.py new file mode 100644 index 000000000..422329fcd --- /dev/null +++ b/tests/basics/floordivide_intbig.py @@ -0,0 +1,15 @@ +# check modulo matches python definition + +a = 987654321987987987987987987987 +b = 19 + +print(a // b) +print(a // -b) +print(-a // b) +print(-a // -b) +a = 10000000000000000000000000000000000000000000 +b = 100 +print(a // b) +print(a // -b) +print(-a // b) +print(-a // -b) diff --git a/tests/basics/int_big1.py b/tests/basics/int_big1.py new file mode 100644 index 000000000..425bc21b6 --- /dev/null +++ b/tests/basics/int_big1.py @@ -0,0 +1,97 @@ +# to test arbitrariy precision integers + +x = 1000000000000000000000000000000 +xn = -1000000000000000000000000000000 +y = 2000000000000000000000000000000 + +# printing +print(x) +print(y) +print('%#X' % (x - x)) # print prefix +print('{:#,}'.format(x)) # print with commas + +# addition +print(x + 1) +print(x + y) +print(x + xn == 0) +print(bool(x + xn)) + +# subtraction +print(x - 1) +print(x - y) +print(y - x) +print(x - x == 0) +print(bool(x - x)) + +# multiplication +print(x * 2) +print(x * y) + +# integer division +print(x // 2) +print(y // x) + +# bit inversion +print(~x) +print(~(-x)) + +# left shift +x = 0x10000000000000000000000 +for i in range(32): + x = x << 1 + print(x) + +# right shift +x = 0x10000000000000000000000 +for i in range(32): + x = x >> 1 + print(x) + +# left shift of a negative number +for i in range(8): + print(-10000000000000000000000000 << i) + print(-10000000000000000000000001 << i) + print(-10000000000000000000000002 << i) + print(-10000000000000000000000003 << i) + print(-10000000000000000000000004 << i) + +# right shift of a negative number +for i in range(8): + print(-10000000000000000000000000 >> i) + print(-10000000000000000000000001 >> i) + print(-10000000000000000000000002 >> i) + print(-10000000000000000000000003 >> i) + print(-10000000000000000000000004 >> i) + +# conversion from string +print(int("123456789012345678901234567890")) +print(int("-123456789012345678901234567890")) +print(int("123456789012345678901234567890abcdef", 16)) +print(int("123456789012345678901234567890ABCDEF", 16)) +print(int("1234567890abcdefghijklmnopqrstuvwxyz", 36)) + +# invalid characters in string +try: + print(int("123456789012345678901234567890abcdef")) +except ValueError: + print('ValueError'); + +# test constant integer with more than 255 chars +x = 0x84ce72aa8699df436059f052ac51b6398d2511e49631bcb7e71f89c499b9ee425dfbc13a5f6d408471b054f2655617cbbaf7937b7c80cd8865cf02c8487d30d2b0fbd8b2c4e102e16d828374bbc47b93852f212d5043c3ea720f086178ff798cc4f63f787b9c2e419efa033e7644ea7936f54462dc21a6c4580725f7f0e7d1aaaaaaa +print(x) + +# test parsing ints just on threshold of small to big +# for 32 bit archs +x = 1073741823 # small +x = -1073741823 # small +x = 1073741824 # big +x = -1073741824 # big +# for 64 bit archs +x = 4611686018427387903 # small +x = -4611686018427387903 # small +x = 4611686018427387904 # big +x = -4611686018427387904 # big + +# sys.maxsize is a constant mpz, so test it's compatible with dynamic ones +import sys +print(sys.maxsize + 1 - 1 == sys.maxsize) diff --git a/tests/basics/int_bytes.py b/tests/basics/int_bytes.py index 2f468da44..45965ed46 100644 --- a/tests/basics/int_bytes.py +++ b/tests/basics/int_bytes.py @@ -1,7 +1,6 @@ print((10).to_bytes(1, "little")) print((111111).to_bytes(4, "little")) print((100).to_bytes(10, "little")) -print((2**64).to_bytes(9, "little")) print(int.from_bytes(b"\x00\x01\0\0\0\0\0\0", "little")) print(int.from_bytes(b"\x01\0\0\0\0\0\0\0", "little")) print(int.from_bytes(b"\x00\x01\0\0\0\0\0\0", "little")) diff --git a/tests/basics/int_bytes_intbig.py b/tests/basics/int_bytes_intbig.py new file mode 100644 index 000000000..39cd67d26 --- /dev/null +++ b/tests/basics/int_bytes_intbig.py @@ -0,0 +1,9 @@ +print((2**64).to_bytes(9, "little")) + +b = bytes(range(20)) + +il = int.from_bytes(b, "little") +ib = int.from_bytes(b, "big") +print(il) +print(ib) +print(il.to_bytes(20, "little")) diff --git a/tests/basics/int_bytes_long.py b/tests/basics/int_bytes_long.py deleted file mode 100644 index 81ebc6cdc..000000000 --- a/tests/basics/int_bytes_long.py +++ /dev/null @@ -1,7 +0,0 @@ -b = bytes(range(20)) - -il = int.from_bytes(b, "little") -ib = int.from_bytes(b, "big") -print(il) -print(ib) -print(il.to_bytes(20, "little")) diff --git a/tests/basics/int_constfolding.py b/tests/basics/int_constfolding.py index aa38fa6b8..7bb538378 100644 --- a/tests/basics/int_constfolding.py +++ b/tests/basics/int_constfolding.py @@ -7,19 +7,11 @@ print(+100) # negation print(-1) print(-(-1)) -print(-0x3fffffff) # 32-bit edge case -print(-0x3fffffffffffffff) # 64-bit edge case -print(-(-0x3fffffff - 1)) # 32-bit edge case -print(-(-0x3fffffffffffffff - 1)) # 64-bit edge case # 1's complement print(~0) print(~1) print(~-1) -print(~0x3fffffff) # 32-bit edge case -print(~0x3fffffffffffffff) # 64-bit edge case -print(~(-0x3fffffff - 1)) # 32-bit edge case -print(~(-0x3fffffffffffffff - 1)) # 64-bit edge case # addition print(1 + 2) @@ -37,9 +29,3 @@ print(123 // 7, 123 % 7) print(-123 // 7, -123 % 7) print(123 // -7, 123 % -7) print(-123 // -7, -123 % -7) - -# zero big-num on rhs -print(1 + ((1 << 65) - (1 << 65))) - -# negative big-num on rhs -print(1 + (-(1 << 65))) diff --git a/tests/basics/int_constfolding_intbig.py b/tests/basics/int_constfolding_intbig.py new file mode 100644 index 000000000..714f1559a --- /dev/null +++ b/tests/basics/int_constfolding_intbig.py @@ -0,0 +1,19 @@ +# tests int constant folding in compiler + +# negation +print(-0x3fffffff) # 32-bit edge case +print(-0x3fffffffffffffff) # 64-bit edge case +print(-(-0x3fffffff - 1)) # 32-bit edge case +print(-(-0x3fffffffffffffff - 1)) # 64-bit edge case + +# 1's complement +print(~0x3fffffff) # 32-bit edge case +print(~0x3fffffffffffffff) # 64-bit edge case +print(~(-0x3fffffff - 1)) # 32-bit edge case +print(~(-0x3fffffffffffffff - 1)) # 64-bit edge case + +# zero big-num on rhs +print(1 + ((1 << 65) - (1 << 65))) + +# negative big-num on rhs +print(1 + (-(1 << 65))) diff --git a/tests/basics/int_divmod.py b/tests/basics/int_divmod.py index 3c76cd958..2e878135f 100644 --- a/tests/basics/int_divmod.py +++ b/tests/basics/int_divmod.py @@ -5,11 +5,3 @@ for i in range(-2, 3): for j in range(-4, 5): if j != 0: print(i, j, i // j, i % j, divmod(i, j)) - -# this tests bignum modulo -a = 987654321987987987987987987987 -b = 19 -print(a % b) -print(a % -b) -print(-a % b) -print(-a % -b) diff --git a/tests/basics/int_divmod_intbig.py b/tests/basics/int_divmod_intbig.py new file mode 100644 index 000000000..ea8de07f2 --- /dev/null +++ b/tests/basics/int_divmod_intbig.py @@ -0,0 +1,9 @@ +# test integer floor division and modulo + +# this tests bignum modulo +a = 987654321987987987987987987987 +b = 19 +print(a % b) +print(a % -b) +print(-a % b) +print(-a % -b) diff --git a/tests/basics/int_intbig.py b/tests/basics/int_intbig.py new file mode 100644 index 000000000..a22075d1f --- /dev/null +++ b/tests/basics/int_intbig.py @@ -0,0 +1,54 @@ +# This tests long ints for 32-bit machine + +a = 0x1ffffffff +b = 0x100000000 +print(a) +print(b) +print(a + b) +print(a - b) +print(b - a) +# overflows long long implementation +#print(a * b) +print(a // b) +print(a % b) +print("&", a & b) +print(a | b) +print(a ^ b) +print(a << 3) +print(a >> 1) + +a += b +print(a) +a -= 123456 +print(a) +a *= 257 +print(a) +a //= 257 +print(a) +a %= b +print(a) +a ^= b +print(a) +a |= b +print(a) +a &= b +print("&=", a) +a <<= 5 +print(a) +a >>= 1 +print(a) + +# Test referential integrity of long ints +a = 0x1ffffffff +b = a +a += 1 +print(a) +print(b) + +# Bitwise ops on 64-bit + +a = 0x1ffffffffffffffff +b = 0x10000000000000000 +print("&", a & b) +print(a | b) +print(a ^ b) diff --git a/tests/basics/int_long.py b/tests/basics/int_long.py deleted file mode 100644 index a22075d1f..000000000 --- a/tests/basics/int_long.py +++ /dev/null @@ -1,54 +0,0 @@ -# This tests long ints for 32-bit machine - -a = 0x1ffffffff -b = 0x100000000 -print(a) -print(b) -print(a + b) -print(a - b) -print(b - a) -# overflows long long implementation -#print(a * b) -print(a // b) -print(a % b) -print("&", a & b) -print(a | b) -print(a ^ b) -print(a << 3) -print(a >> 1) - -a += b -print(a) -a -= 123456 -print(a) -a *= 257 -print(a) -a //= 257 -print(a) -a %= b -print(a) -a ^= b -print(a) -a |= b -print(a) -a &= b -print("&=", a) -a <<= 5 -print(a) -a >>= 1 -print(a) - -# Test referential integrity of long ints -a = 0x1ffffffff -b = a -a += 1 -print(a) -print(b) - -# Bitwise ops on 64-bit - -a = 0x1ffffffffffffffff -b = 0x10000000000000000 -print("&", a & b) -print(a | b) -print(a ^ b) diff --git a/tests/basics/int_mpz.py b/tests/basics/int_mpz.py deleted file mode 100644 index 425bc21b6..000000000 --- a/tests/basics/int_mpz.py +++ /dev/null @@ -1,97 +0,0 @@ -# to test arbitrariy precision integers - -x = 1000000000000000000000000000000 -xn = -1000000000000000000000000000000 -y = 2000000000000000000000000000000 - -# printing -print(x) -print(y) -print('%#X' % (x - x)) # print prefix -print('{:#,}'.format(x)) # print with commas - -# addition -print(x + 1) -print(x + y) -print(x + xn == 0) -print(bool(x + xn)) - -# subtraction -print(x - 1) -print(x - y) -print(y - x) -print(x - x == 0) -print(bool(x - x)) - -# multiplication -print(x * 2) -print(x * y) - -# integer division -print(x // 2) -print(y // x) - -# bit inversion -print(~x) -print(~(-x)) - -# left shift -x = 0x10000000000000000000000 -for i in range(32): - x = x << 1 - print(x) - -# right shift -x = 0x10000000000000000000000 -for i in range(32): - x = x >> 1 - print(x) - -# left shift of a negative number -for i in range(8): - print(-10000000000000000000000000 << i) - print(-10000000000000000000000001 << i) - print(-10000000000000000000000002 << i) - print(-10000000000000000000000003 << i) - print(-10000000000000000000000004 << i) - -# right shift of a negative number -for i in range(8): - print(-10000000000000000000000000 >> i) - print(-10000000000000000000000001 >> i) - print(-10000000000000000000000002 >> i) - print(-10000000000000000000000003 >> i) - print(-10000000000000000000000004 >> i) - -# conversion from string -print(int("123456789012345678901234567890")) -print(int("-123456789012345678901234567890")) -print(int("123456789012345678901234567890abcdef", 16)) -print(int("123456789012345678901234567890ABCDEF", 16)) -print(int("1234567890abcdefghijklmnopqrstuvwxyz", 36)) - -# invalid characters in string -try: - print(int("123456789012345678901234567890abcdef")) -except ValueError: - print('ValueError'); - -# test constant integer with more than 255 chars -x = 0x84ce72aa8699df436059f052ac51b6398d2511e49631bcb7e71f89c499b9ee425dfbc13a5f6d408471b054f2655617cbbaf7937b7c80cd8865cf02c8487d30d2b0fbd8b2c4e102e16d828374bbc47b93852f212d5043c3ea720f086178ff798cc4f63f787b9c2e419efa033e7644ea7936f54462dc21a6c4580725f7f0e7d1aaaaaaa -print(x) - -# test parsing ints just on threshold of small to big -# for 32 bit archs -x = 1073741823 # small -x = -1073741823 # small -x = 1073741824 # big -x = -1073741824 # big -# for 64 bit archs -x = 4611686018427387903 # small -x = -4611686018427387903 # small -x = 4611686018427387904 # big -x = -4611686018427387904 # big - -# sys.maxsize is a constant mpz, so test it's compatible with dynamic ones -import sys -print(sys.maxsize + 1 - 1 == sys.maxsize) diff --git a/tests/basics/op_error.py b/tests/basics/op_error.py index 5ba6a80e2..b30b5f0a3 100644 --- a/tests/basics/op_error.py +++ b/tests/basics/op_error.py @@ -23,7 +23,6 @@ test_exc("bytearray() // 2", TypeError) # object with buffer protocol needed on rhs test_exc("bytearray(1) + 1", TypeError) -test_exc("(1 << 70) in 1", TypeError) # unsupported subscription test_exc("1[0]", TypeError) diff --git a/tests/basics/op_error_intbig.py b/tests/basics/op_error_intbig.py new file mode 100644 index 000000000..432c05a9f --- /dev/null +++ b/tests/basics/op_error_intbig.py @@ -0,0 +1,13 @@ +# test errors from bad operations (unary, binary, etc) + +def test_exc(code, exc): + try: + exec(code) + print("no exception") + except exc: + print("right exception") + except: + print("wrong exception") + +# object with buffer protocol needed on rhs +test_exc("(1 << 70) in 1", TypeError) diff --git a/tests/basics/slice_bignum.py b/tests/basics/slice_bignum.py deleted file mode 100644 index cc820522b..000000000 --- a/tests/basics/slice_bignum.py +++ /dev/null @@ -1,5 +0,0 @@ -# test slicing when arguments are bignums - -print(list(range(10))[(1<<66)>>65:]) -print(list(range(10))[:(1<<66)>>65]) -print(list(range(10))[::(1<<66)>>65]) diff --git a/tests/basics/slice_intbig.py b/tests/basics/slice_intbig.py new file mode 100644 index 000000000..cc820522b --- /dev/null +++ b/tests/basics/slice_intbig.py @@ -0,0 +1,5 @@ +# test slicing when arguments are bignums + +print(list(range(10))[(1<<66)>>65:]) +print(list(range(10))[:(1<<66)>>65]) +print(list(range(10))[::(1<<66)>>65]) diff --git a/tests/basics/struct1.py b/tests/basics/struct1.py index d89519a2f..bb6877c78 100644 --- a/tests/basics/struct1.py +++ b/tests/basics/struct1.py @@ -37,34 +37,6 @@ s = struct.pack("BHBI", 10, 100, 200, 300) v = struct.unpack("BHBI", s) print(v == (10, 100, 200, 300)) -# check maximum pack on 32-bit machine -print(struct.pack("Q", 2**64 - 1)) -print(struct.pack("Q", 0xffffffffffffffff)) -print(struct.pack("q", -1)) -print(struct.pack("Q", 1234567890123456789)) -print(struct.pack(">q", -1234567890123456789)) -print(struct.unpack("Q", b"\x12\x34\x56\x78\x90\x12\x34\x56")) -print(struct.unpack("q", b"\xf2\x34\x56\x78\x90\x12\x34\x56")) - -# check maximum unpack -print(struct.unpack("Q", 2**64 - 1)) +print(struct.pack("Q", 0xffffffffffffffff)) +print(struct.pack("q", -1)) +print(struct.pack("Q", 1234567890123456789)) +print(struct.pack(">q", -1234567890123456789)) +print(struct.unpack("Q", b"\x12\x34\x56\x78\x90\x12\x34\x56")) +print(struct.unpack("q", b"\xf2\x34\x56\x78\x90\x12\x34\x56")) + +# check maximum unpack +print(struct.unpack(" Date: Sat, 4 Mar 2017 12:34:58 +0100 Subject: tests/basics/string_join.py: Add test case where argument is not iterable. --- tests/basics/string_join.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'tests/basics') diff --git a/tests/basics/string_join.py b/tests/basics/string_join.py index 4a2e9aa91..82f1b799a 100644 --- a/tests/basics/string_join.py +++ b/tests/basics/string_join.py @@ -13,6 +13,11 @@ print(','.join('abc' for i in range(5))) print(b','.join([b'abc', b'123'])) +try: + ''.join(None) +except TypeError: + print("TypeError") + try: print(b','.join(['abc', b'123'])) except TypeError: -- cgit v1.2.3 From 1bd17de4b782487725a611acb407f64fa41ae257 Mon Sep 17 00:00:00 2001 From: Krzysztof Blazewicz Date: Sat, 4 Mar 2017 12:37:26 +0100 Subject: tests/basics/unpack1.py: Test if *a, = b copies b when b is a list. --- tests/basics/unpack1.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/basics') diff --git a/tests/basics/unpack1.py b/tests/basics/unpack1.py index 0e8ec592c..1e8b53aa1 100644 --- a/tests/basics/unpack1.py +++ b/tests/basics/unpack1.py @@ -41,7 +41,7 @@ a, *b, c = 24, 25, 26, 27 ; print(a, b) a = [28, 29] *b, = a -print(a, b, a == b) +print(a, b, a == b, a is b) [*a] = [1, 2, 3] print(a) -- cgit v1.2.3 From 983144404b6526c22e5c4224807ea4214e11e248 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Thu, 9 Mar 2017 00:07:19 +0100 Subject: tests/basic: Make various tests skippable. --- tests/basics/builtin_property.py | 6 ++++++ tests/basics/builtin_sorted.py | 7 +++++++ tests/basics/bytearray_construct.py | 6 ------ tests/basics/bytearray_construct_array.py | 11 +++++++++++ tests/basics/bytearray_construct_endian.py | 8 ++++++-- tests/basics/bytes_add.py | 7 ------- tests/basics/bytes_add_array.py | 12 ++++++++++++ tests/basics/bytes_add_endian.py | 8 ++++++-- tests/basics/bytes_compare2.py | 6 ------ tests/basics/bytes_compare_array.py | 10 ++++++++++ tests/basics/bytes_construct.py | 6 ------ tests/basics/bytes_construct_array.py | 11 +++++++++++ tests/basics/bytes_construct_endian.py | 7 ++++++- 13 files changed, 75 insertions(+), 30 deletions(-) create mode 100644 tests/basics/bytearray_construct_array.py create mode 100644 tests/basics/bytes_add_array.py create mode 100644 tests/basics/bytes_compare_array.py create mode 100644 tests/basics/bytes_construct_array.py (limited to 'tests/basics') diff --git a/tests/basics/builtin_property.py b/tests/basics/builtin_property.py index 403abd62f..ff4ff073c 100644 --- a/tests/basics/builtin_property.py +++ b/tests/basics/builtin_property.py @@ -1,4 +1,10 @@ # test builtin property +try: + property +except: + import sys + print("SKIP") + sys.exit() # create a property object explicitly property() diff --git a/tests/basics/builtin_sorted.py b/tests/basics/builtin_sorted.py index a4f71a15e..68855b61b 100644 --- a/tests/basics/builtin_sorted.py +++ b/tests/basics/builtin_sorted.py @@ -1,4 +1,11 @@ # test builtin sorted +try: + sorted + set +except: + import sys + print("SKIP") + sys.exit() print(sorted(set(range(100)))) print(sorted(set(range(100)), key=lambda x: x + 100*(x % 2))) diff --git a/tests/basics/bytearray_construct.py b/tests/basics/bytearray_construct.py index 1c45f6fcf..9c8f3adaa 100644 --- a/tests/basics/bytearray_construct.py +++ b/tests/basics/bytearray_construct.py @@ -1,12 +1,6 @@ # test construction of bytearray from different objects -from array import array - # bytes, tuple, list print(bytearray(b'123')) print(bytearray((1, 2))) print(bytearray([1, 2])) - -# arrays -print(bytearray(array('b', [1, 2]))) -print(bytearray(array('h', [0x101, 0x202]))) diff --git a/tests/basics/bytearray_construct_array.py b/tests/basics/bytearray_construct_array.py new file mode 100644 index 000000000..6d45cafda --- /dev/null +++ b/tests/basics/bytearray_construct_array.py @@ -0,0 +1,11 @@ +# test construction of bytearray from different objects +try: + from array import array +except ImportError: + import sys + print("SKIP") + sys.exit() + +# arrays +print(bytearray(array('b', [1, 2]))) +print(bytearray(array('h', [0x101, 0x202]))) diff --git a/tests/basics/bytearray_construct_endian.py b/tests/basics/bytearray_construct_endian.py index dbd635c0c..f68f9b89d 100644 --- a/tests/basics/bytearray_construct_endian.py +++ b/tests/basics/bytearray_construct_endian.py @@ -1,6 +1,10 @@ # test construction of bytearray from different objects - -from array import array +try: + from array import array +except ImportError: + import sys + print("SKIP") + sys.exit() # arrays print(bytearray(array('h', [1, 2]))) diff --git a/tests/basics/bytes_add.py b/tests/basics/bytes_add.py index 7a887db23..5432d01e5 100644 --- a/tests/basics/bytes_add.py +++ b/tests/basics/bytes_add.py @@ -2,10 +2,3 @@ print(b"123" + b"456") print(b"123" + bytearray(2)) - -import array - -# should be byteorder-neutral -print(b"123" + array.array('h', [0x1515])) - -print(b"\x01\x02" + array.array('b', [1, 2])) diff --git a/tests/basics/bytes_add_array.py b/tests/basics/bytes_add_array.py new file mode 100644 index 000000000..2b8cbccef --- /dev/null +++ b/tests/basics/bytes_add_array.py @@ -0,0 +1,12 @@ +# test bytes + other +try: + import array +except ImportError: + import sys + print("SKIP") + sys.exit() + +# should be byteorder-neutral +print(b"123" + array.array('h', [0x1515])) + +print(b"\x01\x02" + array.array('b', [1, 2])) diff --git a/tests/basics/bytes_add_endian.py b/tests/basics/bytes_add_endian.py index 5471280d9..1bbd0f2c3 100644 --- a/tests/basics/bytes_add_endian.py +++ b/tests/basics/bytes_add_endian.py @@ -1,5 +1,9 @@ # test bytes + other - -import array +try: + import array +except ImportError: + import sys + print("SKIP") + sys.exit() print(b"123" + array.array('i', [1])) diff --git a/tests/basics/bytes_compare2.py b/tests/basics/bytes_compare2.py index 8959da3ae..4d5de21d2 100644 --- a/tests/basics/bytes_compare2.py +++ b/tests/basics/bytes_compare2.py @@ -3,9 +3,3 @@ print(b"123" == bytearray(b"123")) print(b'123' < bytearray(b"124")) print(b'123' > bytearray(b"122")) print(bytearray(b"23") in b"1234") - -import array - -print(array.array('b', [1, 2]) in b'\x01\x02\x03') -# CPython gives False here -#print(b"\x01\x02\x03" == array.array("B", [1, 2, 3])) diff --git a/tests/basics/bytes_compare_array.py b/tests/basics/bytes_compare_array.py new file mode 100644 index 000000000..ad41d1d37 --- /dev/null +++ b/tests/basics/bytes_compare_array.py @@ -0,0 +1,10 @@ +try: + import array +except ImportError: + import sys + print("SKIP") + sys.exit() + +print(array.array('b', [1, 2]) in b'\x01\x02\x03') +# CPython gives False here +#print(b"\x01\x02\x03" == array.array("B", [1, 2, 3])) diff --git a/tests/basics/bytes_construct.py b/tests/basics/bytes_construct.py index 164738767..0d638c08f 100644 --- a/tests/basics/bytes_construct.py +++ b/tests/basics/bytes_construct.py @@ -1,16 +1,10 @@ # test construction of bytes from different objects -from array import array - # tuple, list, bytearray print(bytes((1, 2))) print(bytes([1, 2])) print(bytes(bytearray(4))) -# arrays -print(bytes(array('b', [1, 2]))) -print(bytes(array('h', [0x101, 0x202]))) - # constructor value out of range try: bytes([-1]) diff --git a/tests/basics/bytes_construct_array.py b/tests/basics/bytes_construct_array.py new file mode 100644 index 000000000..72c2d0c58 --- /dev/null +++ b/tests/basics/bytes_construct_array.py @@ -0,0 +1,11 @@ +# test construction of bytes from different objects +try: + from array import array +except ImportError: + import sys + print("SKIP") + sys.exit() + +# arrays +print(bytes(array('b', [1, 2]))) +print(bytes(array('h', [0x101, 0x202]))) diff --git a/tests/basics/bytes_construct_endian.py b/tests/basics/bytes_construct_endian.py index 1912f63a4..77e0eaaa5 100644 --- a/tests/basics/bytes_construct_endian.py +++ b/tests/basics/bytes_construct_endian.py @@ -1,6 +1,11 @@ # test construction of bytes from different objects -from array import array +try: + from array import array +except ImportError: + import sys + print("SKIP") + sys.exit() # arrays print(bytes(array('h', [1, 2]))) -- cgit v1.2.3 From ce63a95a85cf323d608329daa264e15fc21aa258 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Thu, 9 Mar 2017 08:31:35 +0100 Subject: tests/dict_fromkeys: Split out skippable part. --- tests/basics/dict_fromkeys.py | 5 ----- tests/basics/dict_fromkeys2.py | 11 +++++++++++ 2 files changed, 11 insertions(+), 5 deletions(-) create mode 100644 tests/basics/dict_fromkeys2.py (limited to 'tests/basics') diff --git a/tests/basics/dict_fromkeys.py b/tests/basics/dict_fromkeys.py index 118d0ffd9..7b11319a2 100644 --- a/tests/basics/dict_fromkeys.py +++ b/tests/basics/dict_fromkeys.py @@ -7,8 +7,3 @@ d = dict.fromkeys([1, 2, 3, 4], 42) l = list(d.values()) l.sort() print(l) - -# argument to fromkeys has no __len__ -d = dict.fromkeys(reversed(range(1))) -#d = dict.fromkeys((x for x in range(1))) -print(d) diff --git a/tests/basics/dict_fromkeys2.py b/tests/basics/dict_fromkeys2.py new file mode 100644 index 000000000..7ea0cc5b3 --- /dev/null +++ b/tests/basics/dict_fromkeys2.py @@ -0,0 +1,11 @@ +try: + reversed +except: + import sys + print("SKIP") + sys.exit() + +# argument to fromkeys has no __len__ +d = dict.fromkeys(reversed(range(1))) +#d = dict.fromkeys((x for x in range(1))) +print(d) -- cgit v1.2.3 From c9705cff6860c9d77ea009ce6a6c0e9e946a0b21 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Fri, 10 Mar 2017 02:22:56 +0100 Subject: tests/basics/fun_error: Split out skippable test. --- tests/basics/fun_error.py | 3 --- tests/basics/fun_error2.py | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 tests/basics/fun_error2.py (limited to 'tests/basics') diff --git a/tests/basics/fun_error.py b/tests/basics/fun_error.py index 305b24911..367fe0b7f 100644 --- a/tests/basics/fun_error.py +++ b/tests/basics/fun_error.py @@ -27,8 +27,5 @@ test_exc("[].sort(1)", TypeError) # function with keyword args given extra keyword args test_exc("[].sort(noexist=1)", TypeError) -# function with keyword args not given a specific keyword arg -test_exc("enumerate()", TypeError) - # kw given for positional, but a different positional is missing test_exc("def f(x, y): pass\nf(x=1)", TypeError) diff --git a/tests/basics/fun_error2.py b/tests/basics/fun_error2.py new file mode 100644 index 000000000..c4d2c0b64 --- /dev/null +++ b/tests/basics/fun_error2.py @@ -0,0 +1,19 @@ +# test errors from bad function calls +try: + enumerate +except: + print("SKIP") + import sys + sys.exit() + +def test_exc(code, exc): + try: + exec(code) + print("no exception") + except exc: + print("right exception") + except: + print("wrong exception") + +# function with keyword args not given a specific keyword arg +test_exc("enumerate()", TypeError) -- cgit v1.2.3 From 05fec17d9b126ee680095110fd520162669a6ce7 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 14 Mar 2017 18:27:43 +1100 Subject: tests/basics/struct_micropython: Add test for 'S' typecode in ustruct. The 'S' typecode is a uPy extension so it should be grouped with the other extension (namely 'O' typecode). Testing 'S' needs uctypes which is an extmod module and not always available, so this test is made optional and will only be run on ports that have (u)struct and uctypes. Otherwise it will be silently skipped. --- tests/basics/struct_micropython.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'tests/basics') diff --git a/tests/basics/struct_micropython.py b/tests/basics/struct_micropython.py index e3b0ea508..53306dad6 100644 --- a/tests/basics/struct_micropython.py +++ b/tests/basics/struct_micropython.py @@ -18,3 +18,16 @@ o = A() s = struct.pack(" Date: Wed, 15 Mar 2017 17:25:46 +1100 Subject: tests/basics/string_format2: Adjust comment now that tests succeed. --- tests/basics/string_format2.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/basics') diff --git a/tests/basics/string_format2.py b/tests/basics/string_format2.py index e211535be..881ff4f80 100644 --- a/tests/basics/string_format2.py +++ b/tests/basics/string_format2.py @@ -1,6 +1,6 @@ # comprehensive functionality test for {} format string -int_tests = False # these take a while, and some give wrong results +int_tests = False # these take a while char_tests = True str_tests = True -- cgit v1.2.3 From b154468b085dad53de8fdef09ec42c8518475556 Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 15 Mar 2017 17:31:17 +1100 Subject: tests/basics: Add test for string module formatting with int argument. --- tests/basics/string_format_modulo_int.py | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 tests/basics/string_format_modulo_int.py (limited to 'tests/basics') diff --git a/tests/basics/string_format_modulo_int.py b/tests/basics/string_format_modulo_int.py new file mode 100644 index 000000000..c97bca9bd --- /dev/null +++ b/tests/basics/string_format_modulo_int.py @@ -0,0 +1,7 @@ +# test string modulo formatting with int values + +# test + option with various amount of padding +for pad in ('', ' ', '0'): + for n in (1, 2, 3): + for val in (-1, 0, 1): + print(('%+' + pad + str(n) + 'd') % val) -- cgit v1.2.3 From ecb4357fe1c417e7349a56affcee5e2ccdf0d421 Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 15 Mar 2017 17:34:47 +1100 Subject: tests/basics: Move string-modulo-format int tests to dedicated file. --- tests/basics/string_format_modulo.py | 32 ------------------------------ tests/basics/string_format_modulo_int.py | 34 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 32 deletions(-) (limited to 'tests/basics') diff --git a/tests/basics/string_format_modulo.py b/tests/basics/string_format_modulo.py index f00502457..77bbcfbe3 100644 --- a/tests/basics/string_format_modulo.py +++ b/tests/basics/string_format_modulo.py @@ -33,38 +33,6 @@ print("%c" % 48) print("%c" % 'a') print("%10s" % 'abc') print("%-10s" % 'abc') -print("%d" % 10) -print("%+d" % 10) -print("% d" % 10) -print("%d" % -10) -print("%d" % True) -print("%i" % -10) -print("%i" % True) -print("%u" % -10) -print("%u" % True) -print("%x" % 18) -print("%o" % 18) -print("%X" % 18) -print("%#x" % 18) -print("%#X" % 18) -print("%#6o" % 18) -print("%#6x" % 18) -print("%#06x" % 18) - -print("%*d" % (5, 10)) -print("%*.*d" % (2, 2, 20)) -print("%*.*d" % (5, 8, 20)) - -print(">%8.4d<" % -12) -print(">% 8.4d<" % -12) -print(">%+8.4d<" % 12) -print(">%+8.4d<" % -12) -print(">%08.4d<" % -12) -print(">%08.4d<" % 12) -print(">%-8.4d<" % -12) -print(">%-08.4d<" % -12) -print(">%-+08.4d<" % -12) -print(">%-+08.4d<" % 12) # Should be able to print dicts; in this case they aren't used # to lookup keywords in formats like %(foo)s diff --git a/tests/basics/string_format_modulo_int.py b/tests/basics/string_format_modulo_int.py index c97bca9bd..d1f29db22 100644 --- a/tests/basics/string_format_modulo_int.py +++ b/tests/basics/string_format_modulo_int.py @@ -1,5 +1,39 @@ # test string modulo formatting with int values +# basic cases +print("%d" % 10) +print("%+d" % 10) +print("% d" % 10) +print("%d" % -10) +print("%d" % True) +print("%i" % -10) +print("%i" % True) +print("%u" % -10) +print("%u" % True) +print("%x" % 18) +print("%o" % 18) +print("%X" % 18) +print("%#x" % 18) +print("%#X" % 18) +print("%#6o" % 18) +print("%#6x" % 18) +print("%#06x" % 18) + +# with * +print("%*d" % (5, 10)) +print("%*.*d" % (2, 2, 20)) +print("%*.*d" % (5, 8, 20)) + +# precision +for val in (-12, 12): + print(">%8.4d<" % val) + print(">% 8.4d<" % val) + print(">%+8.4d<" % val) + print(">%08.4d<" % val) + print(">%-8.4d<" % val) + print(">%-08.4d<" % val) + print(">%-+08.4d<" % val) + # test + option with various amount of padding for pad in ('', ' ', '0'): for n in (1, 2, 3): -- cgit v1.2.3 From eeff0c352845649a3ae7b2e325361744d2db114b Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 16 Mar 2017 14:31:03 +1100 Subject: tests/basics/bytes_add: Add tests for optimised bytes addition. --- tests/basics/bytes_add.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'tests/basics') diff --git a/tests/basics/bytes_add.py b/tests/basics/bytes_add.py index 5432d01e5..ebccf0662 100644 --- a/tests/basics/bytes_add.py +++ b/tests/basics/bytes_add.py @@ -2,3 +2,7 @@ print(b"123" + b"456") print(b"123" + bytearray(2)) + +print(b"123" + b"") # RHS is empty, can be optimised +print(b"" + b"123") # LHS is empty, can be optimised +print(b"" + bytearray(1)) # LHS is empty but can't be optimised -- cgit v1.2.3 From 734775524e14a8ae3997933afba64a4ac6a3cd47 Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 27 Mar 2017 11:29:11 +1100 Subject: tests/basics: Add test for super() when self is closed over. --- tests/basics/class_super_closure.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 tests/basics/class_super_closure.py (limited to 'tests/basics') diff --git a/tests/basics/class_super_closure.py b/tests/basics/class_super_closure.py new file mode 100644 index 000000000..41acae90d --- /dev/null +++ b/tests/basics/class_super_closure.py @@ -0,0 +1,18 @@ +# test that no-arg super() works when self is closed over + +class A: + def __init__(self): + self.val = 4 + def foo(self): + # we access a member of self to check that self is correct + return list(range(self.val)) +class B(A): + def foo(self): + # self is closed over because it's referenced in the list comprehension + # and then super() must detect this and load from the closure cell + return [self.bar(i) for i in super().foo()] + def bar(self, x): + return 2 * x + +print(A().foo()) +print(B().foo()) -- cgit v1.2.3 From bf51e2ff980584603853cc1e7d47b8012316618f Mon Sep 17 00:00:00 2001 From: Damien George Date: Sun, 2 Apr 2017 17:31:32 +1000 Subject: tests/basics: Add tests for list and bytearray growing using themselves. --- tests/basics/bytearray_slice_assign.py | 5 +++++ tests/basics/list_slice_assign_grow.py | 5 +++++ 2 files changed, 10 insertions(+) (limited to 'tests/basics') diff --git a/tests/basics/bytearray_slice_assign.py b/tests/basics/bytearray_slice_assign.py index 510e784da..c4b5c43e3 100644 --- a/tests/basics/bytearray_slice_assign.py +++ b/tests/basics/bytearray_slice_assign.py @@ -51,6 +51,11 @@ b = bytearray(10) b[:-1] = bytearray(500) print(len(b), b[0], b[-1]) +# extension with self on RHS +b = bytearray(x) +b[4:] = b +print(b) + # Assignment of bytes to array slice b = bytearray(2) b[1:1] = b"12345" diff --git a/tests/basics/list_slice_assign_grow.py b/tests/basics/list_slice_assign_grow.py index 12b1541e3..fa256235f 100644 --- a/tests/basics/list_slice_assign_grow.py +++ b/tests/basics/list_slice_assign_grow.py @@ -26,3 +26,8 @@ print(l) l = list(x) l[100:100] = [10, 20, 30, 40] print(l) + +# growing by using itself on RHS +l = list(range(10)) +l[4:] = l +print(l) -- cgit v1.2.3 From dcd8f52766784c8a32f9472e1d5b5bfd61324242 Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 5 Apr 2017 10:52:29 +1000 Subject: tests/basics: Add tests for raising ValueError when range() gets 0 step. --- tests/basics/builtin_range.py | 6 ++++++ tests/basics/for_range.py | 7 +++++++ 2 files changed, 13 insertions(+) (limited to 'tests/basics') diff --git a/tests/basics/builtin_range.py b/tests/basics/builtin_range.py index 7c3e5beef..6371ab56c 100644 --- a/tests/basics/builtin_range.py +++ b/tests/basics/builtin_range.py @@ -34,6 +34,12 @@ print(range(1, 4)[1:]) print(range(1, 4)[:-1]) print(range(7, -2, -4)[:]) +# zero step +try: + range(1, 2, 0) +except ValueError: + print("ValueError") + # bad unary op try: -range(1) diff --git a/tests/basics/for_range.py b/tests/basics/for_range.py index 58a8f7caa..fc736277d 100644 --- a/tests/basics/for_range.py +++ b/tests/basics/for_range.py @@ -6,6 +6,13 @@ for x in range(*(1, 3)): for x in range(1, *(6, 2)): print(x) +# zero step +try: + for x in range(1, 2, 0): + pass +except ValueError: + print('ValueError') + # apply args using ** try: for x in range(**{'end':1}): -- cgit v1.2.3 From b6fff4186de098946cc1e4c0204f78936f73044f Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 5 Apr 2017 12:38:18 +1000 Subject: tests/basics: Add test for tuple inplace add. --- tests/basics/tuple1.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'tests/basics') diff --git a/tests/basics/tuple1.py b/tests/basics/tuple1.py index 2993391d5..a7956c107 100644 --- a/tests/basics/tuple1.py +++ b/tests/basics/tuple1.py @@ -17,6 +17,10 @@ print(x[2:3]) print(x + (10, 100, 10000)) +# inplace add operator +x += (10, 11, 12) +print(x) + # construction of tuple from large iterator (tests implementation detail of uPy) print(tuple(range(20))) -- cgit v1.2.3 From 30badd1ce1fabd26e54fc445f07846306aa19cef Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 19 Apr 2017 09:49:48 +1000 Subject: tests: Add tests for calling super and loading a method directly. --- tests/basics/class_super.py | 14 ++++++++++++++ tests/cmdline/cmd_showbc.py | 4 ++++ tests/cmdline/cmd_showbc.py.exp | 21 ++++++++++++++++++++- tests/micropython/heapalloc_super.py | 17 +++++++++++++++++ tests/micropython/heapalloc_super.py.exp | 3 +++ 5 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 tests/micropython/heapalloc_super.py create mode 100644 tests/micropython/heapalloc_super.py.exp (limited to 'tests/basics') diff --git a/tests/basics/class_super.py b/tests/basics/class_super.py index 4b052d8f3..1338ef452 100644 --- a/tests/basics/class_super.py +++ b/tests/basics/class_super.py @@ -20,3 +20,17 @@ class A: def p(self): print(str(super())[:18]) A().p() + + +# test compiler's handling of long expressions with super +class A: + bar = 123 + def foo(self): + print('A foo') + return [1, 2, 3] +class B(A): + def foo(self): + print('B foo') + print(super().bar) # accessing attribute after super() + return super().foo().count(2) # calling a subsequent method +print(B().foo()) diff --git a/tests/cmdline/cmd_showbc.py b/tests/cmdline/cmd_showbc.py index 2f4e953bb..6e99fc418 100644 --- a/tests/cmdline/cmd_showbc.py +++ b/tests/cmdline/cmd_showbc.py @@ -150,3 +150,7 @@ class Class: # delete name del Class + +# load super method +def f(self): + super().f() diff --git a/tests/cmdline/cmd_showbc.py.exp b/tests/cmdline/cmd_showbc.py.exp index d0baee10f..1e015eb03 100644 --- a/tests/cmdline/cmd_showbc.py.exp +++ b/tests/cmdline/cmd_showbc.py.exp @@ -7,7 +7,7 @@ arg names: (N_EXC_STACK 0) bc=-1 line=1 ######## - bc=\\d\+ line=152 + bc=\\d\+ line=155 00 MAKE_FUNCTION \.\+ \\d\+ STORE_NAME f \\d\+ MAKE_FUNCTION \.\+ @@ -25,6 +25,8 @@ arg names: \\d\+ CALL_FUNCTION n=2 nkw=0 \\d\+ STORE_NAME Class \\d\+ DELETE_NAME Class +\\d\+ MAKE_FUNCTION \.\+ +\\d\+ STORE_NAME f \\d\+ LOAD_CONST_NONE \\d\+ RETURN_VALUE File cmdline/cmd_showbc.py, code block 'f' (descriptor: \.\+, bytecode @\.\+ bytes) @@ -428,6 +430,23 @@ arg names: 10 STORE_NAME __qualname__ 13 LOAD_CONST_NONE 14 RETURN_VALUE +File cmdline/cmd_showbc.py, code block 'f' (descriptor: \.\+, bytecode @\.\+ bytes) +Raw bytecode (code_info_size=\\d\+, bytecode_size=\\d\+): +######## +\.\+5b +arg names: self +(N_STATE 4) +(N_EXC_STACK 0) + bc=-1 line=1 + bc=0 line=156 +00 LOAD_GLOBAL super (cache=0) +\\d\+ LOAD_GLOBAL __class__ (cache=0) +\\d\+ LOAD_FAST 0 +\\d\+ LOAD_SUPER_METHOD f +\\d\+ CALL_METHOD n=0 nkw=0 +\\d\+ POP_TOP +\\d\+ LOAD_CONST_NONE +\\d\+ RETURN_VALUE File cmdline/cmd_showbc.py, code block '' (descriptor: \.\+, bytecode @\.\+ bytes) Raw bytecode (code_info_size=\\d\+, bytecode_size=\\d\+): ######## diff --git a/tests/micropython/heapalloc_super.py b/tests/micropython/heapalloc_super.py new file mode 100644 index 000000000..1cf5293d2 --- /dev/null +++ b/tests/micropython/heapalloc_super.py @@ -0,0 +1,17 @@ +# test super() operations which don't require allocation +import micropython + +class A: + def foo(self): + print('A foo') + return 42 +class B(A): + def foo(self): + print('B foo') + print(super().foo()) + +b = B() + +micropython.heap_lock() +b.foo() +micropython.heap_unlock() diff --git a/tests/micropython/heapalloc_super.py.exp b/tests/micropython/heapalloc_super.py.exp new file mode 100644 index 000000000..5dabd0c7c --- /dev/null +++ b/tests/micropython/heapalloc_super.py.exp @@ -0,0 +1,3 @@ +B foo +A foo +42 -- cgit v1.2.3 From 810133d97d4391151e86af90508222c480f362b7 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 25 Apr 2017 12:07:02 +1000 Subject: tests/basics: Add tests for int.from_bytes when src has trailing zeros. The trailing zeros should be truncated from the converted value. --- tests/basics/int_bytes.py | 4 ++++ tests/basics/int_bytes_intbig.py | 3 +++ 2 files changed, 7 insertions(+) (limited to 'tests/basics') diff --git a/tests/basics/int_bytes.py b/tests/basics/int_bytes.py index 45965ed46..93c00bba1 100644 --- a/tests/basics/int_bytes.py +++ b/tests/basics/int_bytes.py @@ -4,3 +4,7 @@ print((100).to_bytes(10, "little")) print(int.from_bytes(b"\x00\x01\0\0\0\0\0\0", "little")) print(int.from_bytes(b"\x01\0\0\0\0\0\0\0", "little")) print(int.from_bytes(b"\x00\x01\0\0\0\0\0\0", "little")) + +# check that extra zero bytes don't change the internal int value +print(int.from_bytes(bytes(20), "little") == 0) +print(int.from_bytes(b"\x01" + bytes(20), "little") == 1) diff --git a/tests/basics/int_bytes_intbig.py b/tests/basics/int_bytes_intbig.py index 39cd67d26..0e0ad1cbb 100644 --- a/tests/basics/int_bytes_intbig.py +++ b/tests/basics/int_bytes_intbig.py @@ -7,3 +7,6 @@ ib = int.from_bytes(b, "big") print(il) print(ib) print(il.to_bytes(20, "little")) + +# check that extra zero bytes don't change the internal int value +print(int.from_bytes(b + bytes(10), "little") == int.from_bytes(b, "little")) -- cgit v1.2.3 From 084824f866af4cda42a41a16d844fa47ba3b8938 Mon Sep 17 00:00:00 2001 From: Damien George Date: Sat, 6 May 2017 11:01:57 +1000 Subject: tests: Move super-as-local test from cpydiff to basic tests. It's now possible to use the name "super" as a local variable. --- tests/basics/class_super_aslocal.py | 9 +++++++++ tests/cpydiff/core_class_superaslocal.py | 13 ------------- 2 files changed, 9 insertions(+), 13 deletions(-) create mode 100644 tests/basics/class_super_aslocal.py delete mode 100644 tests/cpydiff/core_class_superaslocal.py (limited to 'tests/basics') diff --git a/tests/basics/class_super_aslocal.py b/tests/basics/class_super_aslocal.py new file mode 100644 index 000000000..c9259110a --- /dev/null +++ b/tests/basics/class_super_aslocal.py @@ -0,0 +1,9 @@ +# test using the name "super" as a local variable + +class A: + def foo(self): + super = [1, 2] + super.pop() + print(super) + +A().foo() diff --git a/tests/cpydiff/core_class_superaslocal.py b/tests/cpydiff/core_class_superaslocal.py deleted file mode 100644 index fc07ccb38..000000000 --- a/tests/cpydiff/core_class_superaslocal.py +++ /dev/null @@ -1,13 +0,0 @@ -""" -categories: Core,Classes -description: Bug when using "super" as a local -cause: Unknown -workaround: Unknown -""" -class A: - def foo(self): - super = [1] - super.pop() - print(super) - -A().foo() -- cgit v1.2.3 From 2e9e14980d87239f861377d1dac45bb04d3f9712 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 9 May 2017 10:46:43 +1000 Subject: tests/basics: Update array test for big-int with lL typecodes. --- tests/basics/array_intbig.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'tests/basics') diff --git a/tests/basics/array_intbig.py b/tests/basics/array_intbig.py index 2975cd385..4a3b2a0d4 100644 --- a/tests/basics/array_intbig.py +++ b/tests/basics/array_intbig.py @@ -1,4 +1,4 @@ -# test array('q') and array('Q') +# test array types QqLl that require big-ints try: from array import array @@ -7,6 +7,9 @@ except ImportError: print("SKIP") sys.exit() +print(array('L', [0, 2**32-1])) +print(array('l', [-2**31, 0, 2**31-1])) + print(array('q')) print(array('Q')) -- cgit v1.2.3 From e711e2d44a24024fcd7d7f5b39f285f979b66a77 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 9 May 2017 10:49:19 +1000 Subject: tests/basics: Add memoryview test for big ints. --- tests/basics/memoryview2.py | 4 ---- tests/basics/memoryview_intbig.py | 11 +++++++++++ 2 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 tests/basics/memoryview_intbig.py (limited to 'tests/basics') diff --git a/tests/basics/memoryview2.py b/tests/basics/memoryview2.py index edb7c9e64..4b5af852b 100644 --- a/tests/basics/memoryview2.py +++ b/tests/basics/memoryview2.py @@ -12,7 +12,3 @@ print(list(memoryview(array('b', [0x7f, -0x80])))) print(list(memoryview(array('B', [0x7f, 0x80, 0x81, 0xff])))) print(list(memoryview(array('h', [0x7f00, -0x8000])))) print(list(memoryview(array('H', [0x7f00, 0x8000, 0x8100, 0xffff])))) - -# these constructors give an internal overflow in uPy -#print(list(memoryview(array('i', [0x7f000000, -0x80000000])))) -#print(list(memoryview(array('I', [0x7f000000, 0x80000000, 0x81000000, 0xffffffff])))) diff --git a/tests/basics/memoryview_intbig.py b/tests/basics/memoryview_intbig.py new file mode 100644 index 000000000..180f15d18 --- /dev/null +++ b/tests/basics/memoryview_intbig.py @@ -0,0 +1,11 @@ +# test memoryview accessing maximum values for signed/unsigned elements +try: + from array import array + memoryview +except: + import sys + print("SKIP") + sys.exit() + +print(list(memoryview(array('i', [0x7f000000, -0x80000000])))) +print(list(memoryview(array('I', [0x7f000000, 0x80000000, 0x81000000, 0xffffffff])))) -- cgit v1.2.3 From d00d062af2743832c22e3fdff7c88db894cf59d8 Mon Sep 17 00:00:00 2001 From: Tom Collins Date: Mon, 8 May 2017 17:24:29 -0700 Subject: tests/basics/lexer: Add lexer tests for input starting with newlines. --- tests/basics/lexer.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'tests/basics') diff --git a/tests/basics/lexer.py b/tests/basics/lexer.py index 5f12afa70..f1602f5de 100644 --- a/tests/basics/lexer.py +++ b/tests/basics/lexer.py @@ -9,6 +9,14 @@ exec("\n") exec("\n\n") exec("\r") exec("\r\r") +exec("\t") +exec("\r\n") +exec("\nprint(1)") +exec("\rprint(2)") +exec("\r\nprint(3)") +exec("\n5") +exec("\r6") +exec("\r\n7") print(eval("1")) print(eval("12")) print(eval("123")) -- cgit v1.2.3 From 760aa0996f29ae33a36c48128dd8f74597b877ad Mon Sep 17 00:00:00 2001 From: Tom Collins Date: Tue, 9 May 2017 13:17:04 -0700 Subject: tests/basics/lexer: Add line continuation tests for lexer. Tests for an issue with line continuation failing in paste mode due to the lexer only checking for \n in the "following" character position, before next_char() has had a chance to convert \r and \r\n to \n. --- tests/basics/lexer.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'tests/basics') diff --git a/tests/basics/lexer.py b/tests/basics/lexer.py index f1602f5de..244de8cb9 100644 --- a/tests/basics/lexer.py +++ b/tests/basics/lexer.py @@ -27,6 +27,14 @@ print(eval("1\r")) print(eval("12\r")) print(eval("123\r")) +# line continuation +print(eval("'123' \\\r '456'")) +print(eval("'123' \\\n '456'")) +print(eval("'123' \\\r\n '456'")) +print(eval("'123'\\\r'456'")) +print(eval("'123'\\\n'456'")) +print(eval("'123'\\\r\n'456'")) + # backslash used to escape a line-break in a string print('a\ b') -- cgit v1.2.3 From e1b0f2a16fc03fe5127e74626a249d8f395d8d58 Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 17 May 2017 16:33:57 +1000 Subject: tests/basics/list_slice_3arg: Add more tests for negative slicing. --- tests/basics/list_slice_3arg.py | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'tests/basics') diff --git a/tests/basics/list_slice_3arg.py b/tests/basics/list_slice_3arg.py index 8578d5855..a5eda8034 100644 --- a/tests/basics/list_slice_3arg.py +++ b/tests/basics/list_slice_3arg.py @@ -26,3 +26,14 @@ print(x[-1:-1:-1]) print(x[-1:-2:-1]) print(x[-1:-11:-1]) print(x[-10:-11:-1]) +print(x[:-15:-1]) + +# test negative indices that are out-of-bounds +print([][::-1]) +print([1][::-1]) +print([][0:-10:-1]) +print([1][0:-10:-1]) +print([][:-20:-1]) +print([1][:-20:-1]) +print([][-20::-1]) +print([1][-20::-1]) -- cgit v1.2.3 From 218a876f97eca5a051882eb179cde25b92897f1e Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 18 May 2017 10:33:50 +1000 Subject: tests/basics/builtin_range: Add tests for negative slicing of range. --- tests/basics/builtin_range.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'tests/basics') diff --git a/tests/basics/builtin_range.py b/tests/basics/builtin_range.py index 6371ab56c..0e2fabd82 100644 --- a/tests/basics/builtin_range.py +++ b/tests/basics/builtin_range.py @@ -33,6 +33,10 @@ print(range(1, 4)[0:]) print(range(1, 4)[1:]) print(range(1, 4)[:-1]) print(range(7, -2, -4)[:]) +print(range(1, 100, 5)[5:15:3]) +print(range(1, 100, 5)[15:5:-3]) +print(range(100, 1, -5)[5:15:3]) +print(range(100, 1, -5)[15:5:-3]) # zero step try: -- cgit v1.2.3 From 8b13cd7e19d8f7c8080baa6b3cc532bb6aa79c8a Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 25 May 2017 20:48:16 +1000 Subject: tests/basics: Add more tests for unwind jumps from within a try-finally. These tests excercise cases that are fixed by the previous two commits. --- tests/basics/try_finally_loops.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'tests/basics') diff --git a/tests/basics/try_finally_loops.py b/tests/basics/try_finally_loops.py index 06a6b4a0c..a4b80196f 100644 --- a/tests/basics/try_finally_loops.py +++ b/tests/basics/try_finally_loops.py @@ -41,3 +41,28 @@ for i in [1]: break finally: print('finally 4') + +# Test unwind-jump where there is nothing in the body of the try or finally. +# This checks that the bytecode emitter allocates enough stack for the unwind. +for i in [1]: + try: + break + finally: + pass + +# The following test checks that the globals dict is valid after a call to a +# function that has an unwind jump. +# There was a bug where an unwind jump would trash the globals dict upon return +# from a function, because it used the Python-stack incorrectly. +def f(): + for i in [1]: + try: + break + finally: + pass +def g(): + global global_var + f() + print(global_var) +global_var = 'global' +g() -- cgit v1.2.3 From ca16c3821053e5bf2b87aeb10007f73f31dc1eac Mon Sep 17 00:00:00 2001 From: Ville Skyttä Date: Mon, 29 May 2017 10:08:14 +0300 Subject: various: Spelling fixes --- cc3200/README.md | 2 +- docs/library/btree.rst | 2 +- docs/library/machine.SD.rst | 2 +- docs/library/machine.UART.rst | 2 +- docs/library/uhashlib.rst | 4 ++-- docs/library/utime.rst | 4 ++-- docs/sphinx_selective_exclude/README.md | 2 +- docs/sphinx_selective_exclude/modindex_exclude.py | 2 +- esp8266/README.md | 2 +- esp8266/machine_rtc.c | 2 +- examples/conwaylife.py | 4 ++-- examples/embedding/Makefile.upylib | 2 +- examples/embedding/README.md | 2 +- extmod/modlwip.c | 4 ++-- extmod/modwebsocket.c | 2 +- lib/timeutils/timeutils.c | 2 +- lib/utils/stdout_helpers.c | 2 +- py/asmthumb.c | 2 +- py/builtinimport.c | 4 ++-- py/compile.c | 4 ++-- py/misc.h | 2 +- py/mkenv.mk | 2 +- py/mpconfig.h | 2 +- py/obj.c | 2 +- py/objstr.c | 4 ++-- py/py.mk | 2 +- py/ringbuf.h | 2 +- py/stream.c | 2 +- py/vm.c | 4 ++-- qemu-arm/README.md | 2 +- tests/basics/namedtuple1.py | 2 +- tests/basics/try_reraise2.py | 2 +- tests/pyb/can.py | 2 +- tests/thread/stress_aes.py | 2 +- tests/wipy/uart.py | 2 +- tools/insert-usb-ids.py | 2 +- tools/pyboard.py | 2 +- unix/Makefile | 2 +- unix/modsocket.c | 2 +- windows/windows_mphal.c | 2 +- zephyr/modutime.c | 2 +- 41 files changed, 49 insertions(+), 49 deletions(-) (limited to 'tests/basics') diff --git a/cc3200/README.md b/cc3200/README.md index 753fd450a..53cad3ba0 100644 --- a/cc3200/README.md +++ b/cc3200/README.md @@ -138,7 +138,7 @@ If `WIPY_IP`, `WIPY_USER` or `WIPY_PWD` are omitted the default values (the ones ## Regarding old revisions of the CC3200-LAUNCHXL First silicon (pre-release) revisions of the CC3200 had issues with the ram blocks, and MicroPython cannot run -there. Make sure to use a **v4.1 (or higer) LAUNCHXL board** when trying this port, otherwise it won't work. +there. Make sure to use a **v4.1 (or higher) LAUNCHXL board** when trying this port, otherwise it won't work. ### Note regarding FileZilla diff --git a/docs/library/btree.rst b/docs/library/btree.rst index aebcbc160..bd7890586 100644 --- a/docs/library/btree.rst +++ b/docs/library/btree.rst @@ -69,7 +69,7 @@ Functions Open a database from a random-access `stream` (like an open file). All other parameters are optional and keyword-only, and allow to tweak advanced - paramters of the database operation (most users will not need them): + parameters of the database operation (most users will not need them): * `flags` - Currently unused. * `cachesize` - Suggested maximum memory cache size in bytes. For a diff --git a/docs/library/machine.SD.rst b/docs/library/machine.SD.rst index 0eb024602..608e95831 100644 --- a/docs/library/machine.SD.rst +++ b/docs/library/machine.SD.rst @@ -34,7 +34,7 @@ Methods .. method:: SD.init(id=0, pins=('GP10', 'GP11', 'GP15')) - Enable the SD card. In order to initalize the card, give it a 3-tuple: + Enable the SD card. In order to initialize the card, give it a 3-tuple: ``(clk_pin, cmd_pin, dat0_pin)``. .. method:: SD.deinit() diff --git a/docs/library/machine.UART.rst b/docs/library/machine.UART.rst index f9c8efef7..64ff28e1a 100644 --- a/docs/library/machine.UART.rst +++ b/docs/library/machine.UART.rst @@ -16,7 +16,7 @@ UART objects can be created and initialised using:: uart = UART(1, 9600) # init with given baudrate uart.init(9600, bits=8, parity=None, stop=1) # init with given parameters -Supported paramters differ on a board: +Supported parameters differ on a board: Pyboard: Bits can be 7, 8 or 9. Stop can be 1 or 2. With `parity=None`, only 8 and 9 bits are supported. With parity enabled, only 7 and 8 bits diff --git a/docs/library/uhashlib.rst b/docs/library/uhashlib.rst index cd0216dae..6b9a764ba 100644 --- a/docs/library/uhashlib.rst +++ b/docs/library/uhashlib.rst @@ -15,11 +15,11 @@ be implemented: * SHA1 - A previous generation algorithm. Not recommended for new usages, but SHA1 is a part of number of Internet standards and existing - applications, so boards targetting network connectivity and + applications, so boards targeting network connectivity and interoperatiability will try to provide this. * MD5 - A legacy algorithm, not considered cryptographically secure. Only - selected boards, targetting interoperatibility with legacy applications, + selected boards, targeting interoperatibility with legacy applications, will offer this. Constructors diff --git a/docs/library/utime.rst b/docs/library/utime.rst index 871f6c678..f3a067cde 100644 --- a/docs/library/utime.rst +++ b/docs/library/utime.rst @@ -146,8 +146,8 @@ Functions too distant inbetween, see below). The function returns **signed** value in the range [``-TICKS_PERIOD/2`` .. ``TICKS_PERIOD/2-1``] (that's a typical range definition for two's-complement signed binary integers). If the result is negative, it means that - ``ticks1`` occured earlier in time than ``ticks2``. Otherwise, it means that - ``ticks1`` occured after ``ticks2``. This holds ``only`` if ``ticks1`` and ``ticks2`` + ``ticks1`` occurred earlier in time than ``ticks2``. Otherwise, it means that + ``ticks1`` occurred after ``ticks2``. This holds ``only`` if ``ticks1`` and ``ticks2`` are apart from each other for no more than ``TICKS_PERIOD/2-1`` ticks. If that does not hold, incorrect result will be returned. Specifically, if two tick values are apart for ``TICKS_PERIOD/2-1`` ticks, that value will be returned by the function. diff --git a/docs/sphinx_selective_exclude/README.md b/docs/sphinx_selective_exclude/README.md index cc9725c21..dab140739 100644 --- a/docs/sphinx_selective_exclude/README.md +++ b/docs/sphinx_selective_exclude/README.md @@ -66,7 +66,7 @@ index for PDF, just the same as for HTML. search_auto_exclude ------------------- -Even if you exclude soem documents from toctree:: using only:: +Even if you exclude some documents from toctree:: using only:: directive, they will be indexed for full-text search, so user may find them and get confused. This plugin follows very simple idea that if you didn't include some documents in the toctree, then diff --git a/docs/sphinx_selective_exclude/modindex_exclude.py b/docs/sphinx_selective_exclude/modindex_exclude.py index 18b49cc80..bf8db795e 100644 --- a/docs/sphinx_selective_exclude/modindex_exclude.py +++ b/docs/sphinx_selective_exclude/modindex_exclude.py @@ -2,7 +2,7 @@ # This is a Sphinx documentation tool extension which allows to # exclude some Python modules from the generated indexes. Modules # are excluded both from "modindex" and "genindex" index tables -# (in the latter case, all members of a module are exlcuded). +# (in the latter case, all members of a module are excluded). # To control exclusion, set "modindex_exclude" variable in Sphinx # conf.py to the list of modules to exclude. Note: these should be # modules (as defined by py:module directive, not just raw filenames). diff --git a/esp8266/README.md b/esp8266/README.md index 897bb4737..d717d26fe 100644 --- a/esp8266/README.md +++ b/esp8266/README.md @@ -100,7 +100,7 @@ programming). __WiFi__ -Initally, the device configures itself as a WiFi access point (AP). +Initially, the device configures itself as a WiFi access point (AP). - ESSID: MicroPython-xxxxxx (x’s are replaced with part of the MAC address). - Password: micropythoN (note the upper-case N). - IP address of the board: 192.168.4.1. diff --git a/esp8266/machine_rtc.c b/esp8266/machine_rtc.c index 019b705ba..b17bcb261 100644 --- a/esp8266/machine_rtc.c +++ b/esp8266/machine_rtc.c @@ -93,7 +93,7 @@ void pyb_rtc_set_us_since_2000(uint64_t nowus) { int64_t delta = nowus - (((uint64_t)rtc_last_ticks * cal) >> 12); // As the calibration value jitters quite a bit, to make the - // clock at least somewhat practially usable, we need to store it + // clock at least somewhat practically usable, we need to store it system_rtc_mem_write(MEM_CAL_ADDR, &cal, sizeof(cal)); system_rtc_mem_write(MEM_DELTA_ADDR, &delta, sizeof(delta)); }; diff --git a/examples/conwaylife.py b/examples/conwaylife.py index f99796175..323f42e85 100644 --- a/examples/conwaylife.py +++ b/examples/conwaylife.py @@ -8,7 +8,7 @@ lcd.light(1) def conway_step(): for x in range(128): # loop over x coordinates for y in range(32): # loop over y coordinates - # count number of neigbours + # count number of neighbours num_neighbours = (lcd.get(x - 1, y - 1) + lcd.get(x, y - 1) + lcd.get(x + 1, y - 1) + @@ -25,7 +25,7 @@ def conway_step(): if self and not (2 <= num_neighbours <= 3): lcd.pixel(x, y, 0) # not enough, or too many neighbours: cell dies elif not self and num_neighbours == 3: - lcd.pixel(x, y, 1) # exactly 3 neigbours around an empty cell: cell is born + lcd.pixel(x, y, 1) # exactly 3 neighbours around an empty cell: cell is born # randomise the start def conway_rand(): diff --git a/examples/embedding/Makefile.upylib b/examples/embedding/Makefile.upylib index 873c0fd34..4663ad30a 100644 --- a/examples/embedding/Makefile.upylib +++ b/examples/embedding/Makefile.upylib @@ -170,7 +170,7 @@ SRC_QSTR_AUTO_DEPS += include $(MPTOP)/py/mkrules.mk # Value of configure's --host= option (required for cross-compilation). -# Deduce it from CROSS_COMPILE by default, but can be overriden. +# Deduce it from CROSS_COMPILE by default, but can be overridden. ifneq ($(CROSS_COMPILE),) CROSS_COMPILE_HOST = --host=$(patsubst %-,%,$(CROSS_COMPILE)) else diff --git a/examples/embedding/README.md b/examples/embedding/README.md index 989ce1fc8..804dfede6 100644 --- a/examples/embedding/README.md +++ b/examples/embedding/README.md @@ -18,7 +18,7 @@ Building the example is as simple as running: It's worth to trace what's happening behind the scenes though: 1. As a first step, a MicroPython library is built. This is handled by a -seperate makefile, Makefile.upylib. It is more or less complex, but the +separate makefile, Makefile.upylib. It is more or less complex, but the good news is that you won't need to change anything in it, just use it as is, the main Makefile shows how. What may require editing though is a MicroPython configuration file. MicroPython is highly configurable, so diff --git a/extmod/modlwip.c b/extmod/modlwip.c index c72849cf9..47669cb3a 100644 --- a/extmod/modlwip.c +++ b/extmod/modlwip.c @@ -373,7 +373,7 @@ STATIC err_t _lwip_tcp_recv(void *arg, struct tcp_pcb *tcpb, struct pbuf *p, err } /*******************************************************************************/ -// Functions for socket send/recieve operations. Socket send/recv and friends call +// Functions for socket send/receive operations. Socket send/recv and friends call // these to do the work. // Helper function for send/sendto to handle UDP packets. @@ -805,7 +805,7 @@ STATIC mp_obj_t lwip_socket_connect(mp_obj_t self_in, mp_obj_t addr_in) { mp_raise_OSError(MP_EINPROGRESS); } } - // Register our recieve callback. + // Register our receive callback. tcp_recv(socket->pcb.tcp, _lwip_tcp_recv); socket->state = STATE_CONNECTING; err = tcp_connect(socket->pcb.tcp, &dest, port, _lwip_tcp_connected); diff --git a/extmod/modwebsocket.c b/extmod/modwebsocket.c index 8200ea708..9e17d6a6d 100644 --- a/extmod/modwebsocket.c +++ b/extmod/modwebsocket.c @@ -132,7 +132,7 @@ STATIC mp_uint_t websocket_read(mp_obj_t self_in, void *buf, mp_uint_t size, int self->buf_pos = 0; self->to_recv = to_recv; - self->msg_sz = sz; // May be overriden by FRAME_OPT + self->msg_sz = sz; // May be overridden by FRAME_OPT if (to_recv != 0) { self->state = FRAME_OPT; } else { diff --git a/lib/timeutils/timeutils.c b/lib/timeutils/timeutils.c index 0af39a295..06915f25a 100644 --- a/lib/timeutils/timeutils.c +++ b/lib/timeutils/timeutils.c @@ -165,7 +165,7 @@ mp_uint_t timeutils_mktime(mp_uint_t year, mp_int_t month, mp_int_t mday, // // tm_tomorrow = list(time.localtime()) // tm_tomorrow[2] += 1 # Adds 1 to mday - // tomorrow = time.mktime(tm_tommorrow) + // tomorrow = time.mktime(tm_tomorrow) // // And not have to worry about all the weird overflows. // diff --git a/lib/utils/stdout_helpers.c b/lib/utils/stdout_helpers.c index 5f7a17d32..3de119757 100644 --- a/lib/utils/stdout_helpers.c +++ b/lib/utils/stdout_helpers.c @@ -9,7 +9,7 @@ * implementation below can be used. */ -// Send "cooked" string of given length, where every occurance of +// Send "cooked" string of given length, where every occurrence of // LF character is replaced with CR LF. void mp_hal_stdout_tx_strn_cooked(const char *str, size_t len) { while (len--) { diff --git a/py/asmthumb.c b/py/asmthumb.c index 749c1e405..7e92e4de4 100644 --- a/py/asmthumb.c +++ b/py/asmthumb.c @@ -52,7 +52,7 @@ void asm_thumb_end_pass(asm_thumb_t *as) { #if defined(MCU_SERIES_F7) if (as->base.pass == MP_ASM_PASS_EMIT) { - // flush D-cache, so the code emited is stored in memory + // flush D-cache, so the code emitted is stored in memory SCB_CleanDCache_by_Addr((uint32_t*)as->base.code_base, as->base.code_size); // invalidate I-cache SCB_InvalidateICache(); diff --git a/py/builtinimport.c b/py/builtinimport.c index d01ebbe73..6994fc48f 100644 --- a/py/builtinimport.c +++ b/py/builtinimport.c @@ -271,7 +271,7 @@ mp_obj_t mp_builtin___import__(size_t n_args, const mp_obj_t *args) { if (level != 0) { // What we want to do here is to take name of current module, // chop trailing components, and concatenate with passed-in - // module name, thus resolving relative import name into absolue. + // module name, thus resolving relative import name into absolute. // This even appears to be correct per // http://legacy.python.org/dev/peps/pep-0328/#relative-imports-and-name // "Relative imports use a module's __name__ attribute to determine that @@ -441,7 +441,7 @@ mp_obj_t mp_builtin___import__(size_t n_args, const mp_obj_t *args) { #if MICROPY_CPYTHON_COMPAT // Store module as "__main__" in the dictionary of loaded modules (returned by sys.modules). mp_obj_dict_store(MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_loaded_modules_dict)), MP_OBJ_NEW_QSTR(MP_QSTR___main__), module_obj); - // Store real name in "__main__" attribute. Choosen semi-randonly, to reuse existing qstr's. + // Store real name in "__main__" attribute. Chosen semi-randonly, to reuse existing qstr's. mp_obj_dict_store(MP_OBJ_FROM_PTR(o->globals), MP_OBJ_NEW_QSTR(MP_QSTR___main__), MP_OBJ_NEW_QSTR(mod_name)); #endif } diff --git a/py/compile.c b/py/compile.c index 8533e0528..3b6a264d6 100644 --- a/py/compile.c +++ b/py/compile.c @@ -939,7 +939,7 @@ STATIC void c_del_stmt(compiler_t *comp, mp_parse_node_t pn) { } } } else { - // some arbitrary statment that we can't delete (eg del 1) + // some arbitrary statement that we can't delete (eg del 1) goto cannot_delete; } @@ -1090,7 +1090,7 @@ STATIC void compile_import_name(compiler_t *comp, mp_parse_node_struct_t *pns) { STATIC void compile_import_from(compiler_t *comp, mp_parse_node_struct_t *pns) { mp_parse_node_t pn_import_source = pns->nodes[0]; - // extract the preceeding .'s (if any) for a relative import, to compute the import level + // extract the preceding .'s (if any) for a relative import, to compute the import level uint import_level = 0; do { mp_parse_node_t pn_rel; diff --git a/py/misc.h b/py/misc.h index 146b9a8e4..caa5945bf 100644 --- a/py/misc.h +++ b/py/misc.h @@ -197,7 +197,7 @@ int DEBUG_printf(const char *fmt, ...); extern mp_uint_t mp_verbose_flag; // This is useful for unicode handling. Some CPU archs has -// special instructions for efficient implentation of this +// special instructions for efficient implementation of this // function (e.g. CLZ on ARM). // NOTE: this function is unused at the moment #ifndef count_lead_ones diff --git a/py/mkenv.mk b/py/mkenv.mk index eb1e44fef..b167b2533 100644 --- a/py/mkenv.mk +++ b/py/mkenv.mk @@ -32,7 +32,7 @@ ifeq ($(BUILD_VERBOSE),0) $(info Use make V=1 or set BUILD_VERBOSE in your environment to increase build verbosity.) endif -# default settings; can be overriden in main Makefile +# default settings; can be overridden in main Makefile PY_SRC ?= $(TOP)/py BUILD ?= build diff --git a/py/mpconfig.h b/py/mpconfig.h index a61d431e5..78e346d73 100644 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -32,7 +32,7 @@ // mpconfigport.h is a file containing configuration settings for a // particular port. mpconfigport.h is actually a default name for -// such config, and it can be overriden using MP_CONFIGFILE preprocessor +// such config, and it can be overridden using MP_CONFIGFILE preprocessor // define (you can do that by passing CFLAGS_EXTRA='-DMP_CONFIGFILE=""' // argument to make when using standard MicroPython makefiles). // This is useful to have more than one config per port, for example, diff --git a/py/obj.c b/py/obj.c index 98ffa930b..493945a22 100644 --- a/py/obj.c +++ b/py/obj.c @@ -401,7 +401,7 @@ mp_obj_t mp_obj_id(mp_obj_t o_in) { return MP_OBJ_NEW_SMALL_INT(id); } else { // If that didn't work, well, let's return long int, just as - // a (big) positve value, so it will never clash with the range + // a (big) positive value, so it will never clash with the range // of small int returned in previous case. return mp_obj_new_int_from_uint((mp_uint_t)id); } diff --git a/py/objstr.c b/py/objstr.c index 70de0a693..a1e223572 100644 --- a/py/objstr.c +++ b/py/objstr.c @@ -798,7 +798,7 @@ STATIC mp_obj_t str_uni_strip(int type, size_t n_args, const mp_obj_t *args) { } assert(last_good_char_pos >= first_good_char_pos); - //+1 to accomodate the last character + //+1 to accommodate the last character size_t stripped_len = last_good_char_pos - first_good_char_pos + 1; if (stripped_len == orig_str_len) { // If nothing was stripped, don't bother to dup original string @@ -1811,7 +1811,7 @@ STATIC mp_obj_t str_islower(mp_obj_t self_in) { } #if MICROPY_CPYTHON_COMPAT -// These methods are superfluous in the presense of str() and bytes() +// These methods are superfluous in the presence of str() and bytes() // constructors. // TODO: should accept kwargs too STATIC mp_obj_t bytes_decode(size_t n_args, const mp_obj_t *args) { diff --git a/py/py.mk b/py/py.mk index 5ff1fd6a6..70891677d 100644 --- a/py/py.mk +++ b/py/py.mk @@ -25,7 +25,7 @@ ifeq ($(MICROPY_SSL_AXTLS),1) CFLAGS_MOD += -DMICROPY_SSL_AXTLS=1 -I../lib/axtls/ssl -I../lib/axtls/crypto -I../lib/axtls/config LDFLAGS_MOD += -Lbuild -laxtls else ifeq ($(MICROPY_SSL_MBEDTLS),1) -# Can be overriden by ports which have "builtin" mbedTLS +# Can be overridden by ports which have "builtin" mbedTLS MICROPY_SSL_MBEDTLS_INCLUDE ?= ../lib/mbedtls/include CFLAGS_MOD += -DMICROPY_SSL_MBEDTLS=1 -I$(MICROPY_SSL_MBEDTLS_INCLUDE) LDFLAGS_MOD += -L../lib/mbedtls/library -lmbedx509 -lmbedtls -lmbedcrypto diff --git a/py/ringbuf.h b/py/ringbuf.h index 5662594f7..5e108afad 100644 --- a/py/ringbuf.h +++ b/py/ringbuf.h @@ -33,7 +33,7 @@ typedef struct _ringbuf_t { uint16_t iput; } ringbuf_t; -// Static initalization: +// Static initialization: // byte buf_array[N]; // ringbuf_t buf = {buf_array, sizeof(buf_array)}; diff --git a/py/stream.c b/py/stream.c index c915110e0..d3fc767bb 100644 --- a/py/stream.c +++ b/py/stream.c @@ -51,7 +51,7 @@ STATIC mp_obj_t stream_readall(mp_obj_t self_in); #define STREAM_CONTENT_TYPE(stream) (((stream)->is_text) ? &mp_type_str : &mp_type_bytes) // Returns error condition in *errcode, if non-zero, return value is number of bytes written -// before error condition occured. If *errcode == 0, returns total bytes written (which will +// before error condition occurred. If *errcode == 0, returns total bytes written (which will // be equal to input size). mp_uint_t mp_stream_rw(mp_obj_t stream, void *buf_, mp_uint_t size, int *errcode, byte flags) { byte *buf = buf_; diff --git a/py/vm.c b/py/vm.c index 5094e3e45..ad3d9e29c 100644 --- a/py/vm.c +++ b/py/vm.c @@ -947,7 +947,7 @@ unwind_jump:; DECODE_UINT; // unum & 0xff == n_positional // (unum >> 8) & 0xff == n_keyword - // We have folowing stack layout here: + // We have following stack layout here: // fun arg0 arg1 ... kw0 val0 kw1 val1 ... seq dict <- TOS sp -= (unum & 0xff) + ((unum >> 7) & 0x1fe) + 2; #if MICROPY_STACKLESS @@ -1018,7 +1018,7 @@ unwind_jump:; DECODE_UINT; // unum & 0xff == n_positional // (unum >> 8) & 0xff == n_keyword - // We have folowing stack layout here: + // We have following stack layout here: // fun self arg0 arg1 ... kw0 val0 kw1 val1 ... seq dict <- TOS sp -= (unum & 0xff) + ((unum >> 7) & 0x1fe) + 3; #if MICROPY_STACKLESS diff --git a/qemu-arm/README.md b/qemu-arm/README.md index 329ae4d92..0cf93c7d5 100644 --- a/qemu-arm/README.md +++ b/qemu-arm/README.md @@ -4,7 +4,7 @@ provided by QEMU (http://qemu.org). The purposes of this port are to enable: 1. Continuous integration - - run tests agains architecture-specific parts of code base + - run tests against architecture-specific parts of code base 2. Experimentation - simulation & prototyping of anything that has architecture-specific code diff --git a/tests/basics/namedtuple1.py b/tests/basics/namedtuple1.py index 132dcf96b..70372f7ca 100644 --- a/tests/basics/namedtuple1.py +++ b/tests/basics/namedtuple1.py @@ -76,7 +76,7 @@ T4 = namedtuple("TupTuple", ("foo", "bar")) t = T4(1, 2) print(t.foo, t.bar) -# Try single string with comma field seperator +# Try single string with comma field separator # Not implemented so far #T2 = namedtuple("TupComma", "foo,bar") #t = T2(1, 2) diff --git a/tests/basics/try_reraise2.py b/tests/basics/try_reraise2.py index d9434397c..5648d2467 100644 --- a/tests/basics/try_reraise2.py +++ b/tests/basics/try_reraise2.py @@ -1,4 +1,4 @@ -# Reraise not the latest occured exception +# Reraise not the latest occurred exception def f(): try: raise ValueError("val", 3) diff --git a/tests/pyb/can.py b/tests/pyb/can.py index 617eb7ccc..7f2d070ec 100644 --- a/tests/pyb/can.py +++ b/tests/pyb/can.py @@ -158,7 +158,7 @@ print(can.recv(1)) del can -# Testing asyncronous send +# Testing asynchronous send can = CAN(1, CAN.LOOPBACK) can.setfilter(0, CAN.MASK16, 0, (0, 0, 0, 0)) diff --git a/tests/thread/stress_aes.py b/tests/thread/stress_aes.py index ecc963c92..df75e616c 100644 --- a/tests/thread/stress_aes.py +++ b/tests/thread/stress_aes.py @@ -8,7 +8,7 @@ # # The AES code comes first (code originates from a C version authored by D.P.George) # and then the test harness at the bottom. It can be tuned to be more/less -# agressive by changing the amount of data to encrypt, the number of loops and +# aggressive by changing the amount of data to encrypt, the number of loops and # the number of threads. # # MIT license; Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd diff --git a/tests/wipy/uart.py b/tests/wipy/uart.py index a3a1c14e8..8e794015d 100644 --- a/tests/wipy/uart.py +++ b/tests/wipy/uart.py @@ -95,7 +95,7 @@ print(uart1.read() == None) print(uart1.write(b'123') == 3) print(uart0.read() == b'123') -# no pin assignemnt +# no pin assignment uart0 = UART(0, 1000000, pins=(None, None)) print(uart0.write(b'123456789') == 9) print(uart1.read() == None) diff --git a/tools/insert-usb-ids.py b/tools/insert-usb-ids.py index 420db34c5..cdccd3be9 100644 --- a/tools/insert-usb-ids.py +++ b/tools/insert-usb-ids.py @@ -1,4 +1,4 @@ -# Reads the USB VID and PID from the file specifed by sys.arg[1] and then +# Reads the USB VID and PID from the file specified by sys.argv[1] and then # inserts those values into the template file specified by sys.argv[2], # printing the result to stdout diff --git a/tools/pyboard.py b/tools/pyboard.py index 5eac030bd..921ffc52d 100755 --- a/tools/pyboard.py +++ b/tools/pyboard.py @@ -69,7 +69,7 @@ class TelnetToSerial: self.tn.write(bytes(password, 'ascii') + b"\r\n") if b'for more information.' in self.tn.read_until(b'Type "help()" for more information.', timeout=read_timeout): - # login succesful + # login successful from collections import deque self.fifo = deque() return diff --git a/unix/Makefile b/unix/Makefile index 837ddf2b7..006bce0ef 100644 --- a/unix/Makefile +++ b/unix/Makefile @@ -262,7 +262,7 @@ coverage_test: coverage gcov -o build-coverage/extmod ../extmod/*.c # Value of configure's --host= option (required for cross-compilation). -# Deduce it from CROSS_COMPILE by default, but can be overriden. +# Deduce it from CROSS_COMPILE by default, but can be overridden. ifneq ($(CROSS_COMPILE),) CROSS_COMPILE_HOST = --host=$(patsubst %-,%,$(CROSS_COMPILE)) else diff --git a/unix/modsocket.c b/unix/modsocket.c index 9ca04b88b..c7be6461e 100644 --- a/unix/modsocket.c +++ b/unix/modsocket.c @@ -58,7 +58,7 @@ from socket_more_funcs2 import * ------------------- I.e. this module should stay lean, and more functions (if needed) - should be add to seperate modules (C or Python level). + should be add to separate modules (C or Python level). */ #define MICROPY_SOCKET_EXTRA (0) diff --git a/windows/windows_mphal.c b/windows/windows_mphal.c index 1dd3105d8..a73140e54 100644 --- a/windows/windows_mphal.c +++ b/windows/windows_mphal.c @@ -72,7 +72,7 @@ void mp_hal_stdio_mode_orig(void) { // Previous versions of the mp_hal code would install a handler whenever Ctrl-C input is // allowed and remove the handler again when it is not. That is not necessary though (1), // and it might introduce problems (2) because console notifications are delivered to the -// application in a seperate thread. +// application in a separate thread. // (1) mp_hal_set_interrupt_char effectively enables/disables processing of Ctrl-C via the // ENABLE_PROCESSED_INPUT flag so in raw mode console_sighandler won't be called. // (2) if mp_hal_set_interrupt_char would remove the handler while Ctrl-C was issued earlier, diff --git a/zephyr/modutime.c b/zephyr/modutime.c index 378068bb3..0c268046a 100644 --- a/zephyr/modutime.c +++ b/zephyr/modutime.c @@ -36,7 +36,7 @@ #include "extmod/utime_mphal.h" STATIC mp_obj_t mod_time_time(void) { - /* The absense of FP support is deliberate. The Zephyr port uses + /* The absence of FP support is deliberate. The Zephyr port uses * single precision floats so the fraction component will start to * lose precision on devices with a long uptime. */ -- cgit v1.2.3 From 7400d88762570b110d70752dea741fbca778818c Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 2 Jun 2017 13:08:18 +1000 Subject: tests/basics/string_rsplit: Add tests for negative "maxsplit" argument. --- tests/basics/string_rsplit.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'tests/basics') diff --git a/tests/basics/string_rsplit.py b/tests/basics/string_rsplit.py index 563b64f1c..b92b8f359 100644 --- a/tests/basics/string_rsplit.py +++ b/tests/basics/string_rsplit.py @@ -52,3 +52,7 @@ print("/*10/*11/*12/*".rsplit("/*", 4)) print("/*10/*11/*12/*".rsplit("/*", 5)) print(b"abcabc".rsplit(b"bc", 2)) + +# negative "maxsplit" should delegate to .split() +print('abaca'.rsplit('a', -1)) +print('abaca'.rsplit('a', -2)) -- cgit v1.2.3 From a2803b74f48849cb3a11fb492fee891044ecc1f4 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sat, 10 Jun 2017 20:03:01 +0300 Subject: tests/basics: Convert "sys.exit()" to "raise SystemExit". --- tests/basics/array1.py | 3 +-- tests/basics/array_add.py | 3 +-- tests/basics/array_construct.py | 3 +-- tests/basics/array_construct2.py | 3 +-- tests/basics/array_construct_endian.py | 3 +-- tests/basics/array_intbig.py | 3 +-- tests/basics/array_micropython.py | 3 +-- tests/basics/attrtuple1.py | 3 +-- tests/basics/builtin_delattr.py | 3 +-- tests/basics/builtin_help.py | 3 +-- tests/basics/builtin_minmax.py | 3 +-- tests/basics/builtin_override.py | 3 +-- tests/basics/builtin_pow3.py | 3 +-- tests/basics/builtin_pow3_intbig.py | 3 +-- tests/basics/builtin_property.py | 3 +-- tests/basics/builtin_range_attrs.py | 3 +-- tests/basics/builtin_reversed.py | 3 +-- tests/basics/builtin_sorted.py | 3 +-- tests/basics/bytearray_construct_array.py | 3 +-- tests/basics/bytearray_construct_endian.py | 3 +-- tests/basics/bytearray_slice_assign.py | 3 +-- tests/basics/bytes_add_array.py | 3 +-- tests/basics/bytes_add_endian.py | 3 +-- tests/basics/bytes_compare_array.py | 3 +-- tests/basics/bytes_construct_array.py | 3 +-- tests/basics/bytes_construct_endian.py | 3 +-- tests/basics/bytes_partition.py | 3 +-- tests/basics/class_delattr_setattr.py | 3 +-- tests/basics/class_descriptor.py | 3 +-- tests/basics/class_new.py | 3 +-- tests/basics/class_store_class.py | 3 +-- tests/basics/class_super_object.py | 3 +-- tests/basics/dict_fromkeys2.py | 3 +-- tests/basics/enumerate.py | 3 +-- tests/basics/errno1.py | 3 +-- tests/basics/filter.py | 3 +-- tests/basics/frozenset1.py | 3 +-- tests/basics/frozenset_add.py | 3 +-- tests/basics/frozenset_binop.py | 3 +-- tests/basics/frozenset_copy.py | 3 +-- tests/basics/frozenset_difference.py | 3 +-- tests/basics/frozenset_set.py | 3 +-- tests/basics/fun_error2.py | 3 +-- tests/basics/gc1.py | 3 +-- tests/basics/memoryview1.py | 3 +-- tests/basics/memoryview2.py | 3 +-- tests/basics/memoryview_gc.py | 3 +-- tests/basics/memoryview_intbig.py | 3 +-- tests/basics/namedtuple1.py | 3 +-- tests/basics/object_dict.py | 3 +-- tests/basics/object_new.py | 3 +-- tests/basics/op_error_memoryview.py | 3 +-- tests/basics/ordereddict1.py | 3 +-- tests/basics/ordereddict_eq.py | 3 +-- tests/basics/parser.py | 3 +-- tests/basics/set_type.py | 3 +-- tests/basics/slice_attrs.py | 3 +-- tests/basics/special_methods2.py | 3 +-- tests/basics/string_center.py | 3 +-- tests/basics/string_partition.py | 3 +-- tests/basics/string_rpartition.py | 3 +-- tests/basics/string_splitlines.py | 3 +-- tests/basics/struct1.py | 3 +-- tests/basics/struct1_intbig.py | 3 +-- tests/basics/struct2.py | 3 +-- tests/basics/struct_micropython.py | 3 +-- tests/basics/subclass_classmethod.py | 3 +-- tests/basics/sys1.py | 2 +- tests/basics/zip.py | 3 +-- 69 files changed, 69 insertions(+), 137 deletions(-) (limited to 'tests/basics') diff --git a/tests/basics/array1.py b/tests/basics/array1.py index 43f775b79..bad879035 100644 --- a/tests/basics/array1.py +++ b/tests/basics/array1.py @@ -1,9 +1,8 @@ try: import array except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit a = array.array('B', [1, 2, 3]) print(a, len(a)) diff --git a/tests/basics/array_add.py b/tests/basics/array_add.py index 41cd77b42..76ce59f76 100644 --- a/tests/basics/array_add.py +++ b/tests/basics/array_add.py @@ -2,9 +2,8 @@ try: import array except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit a1 = array.array('I', [1]) a2 = array.array('I', [2]) diff --git a/tests/basics/array_construct.py b/tests/basics/array_construct.py index cafa57784..2221de990 100644 --- a/tests/basics/array_construct.py +++ b/tests/basics/array_construct.py @@ -3,9 +3,8 @@ try: from array import array except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit # tuple, list print(array('b', (1, 2))) diff --git a/tests/basics/array_construct2.py b/tests/basics/array_construct2.py index d1c1a6c70..c305b7f01 100644 --- a/tests/basics/array_construct2.py +++ b/tests/basics/array_construct2.py @@ -1,9 +1,8 @@ try: from array import array except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit # construct from something with unknown length (requires generators) print(array('i', (i for i in range(10)))) diff --git a/tests/basics/array_construct_endian.py b/tests/basics/array_construct_endian.py index bf34b05d1..990d7b1ea 100644 --- a/tests/basics/array_construct_endian.py +++ b/tests/basics/array_construct_endian.py @@ -3,9 +3,8 @@ try: from array import array except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit # raw copy from bytes, bytearray print(array('h', b'12')) diff --git a/tests/basics/array_intbig.py b/tests/basics/array_intbig.py index 4a3b2a0d4..5702a8ae6 100644 --- a/tests/basics/array_intbig.py +++ b/tests/basics/array_intbig.py @@ -3,9 +3,8 @@ try: from array import array except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit print(array('L', [0, 2**32-1])) print(array('l', [-2**31, 0, 2**31-1])) diff --git a/tests/basics/array_micropython.py b/tests/basics/array_micropython.py index 0c1df0923..e26ad7ae9 100644 --- a/tests/basics/array_micropython.py +++ b/tests/basics/array_micropython.py @@ -2,9 +2,8 @@ try: import array except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit # arrays of objects a = array.array('O') diff --git a/tests/basics/attrtuple1.py b/tests/basics/attrtuple1.py index 597bfc2a3..78a0fbed1 100644 --- a/tests/basics/attrtuple1.py +++ b/tests/basics/attrtuple1.py @@ -8,9 +8,8 @@ t = sys.implementation try: t.name except AttributeError: - import sys print("SKIP") - sys.exit() + raise SystemExit # test printing of attrtuple diff --git a/tests/basics/builtin_delattr.py b/tests/basics/builtin_delattr.py index 9b38837e4..65bd0f210 100644 --- a/tests/basics/builtin_delattr.py +++ b/tests/basics/builtin_delattr.py @@ -2,9 +2,8 @@ try: delattr except: - import sys print("SKIP") - sys.exit() + raise SystemExit class A: pass a = A() diff --git a/tests/basics/builtin_help.py b/tests/basics/builtin_help.py index d554f308d..6ec39653f 100644 --- a/tests/basics/builtin_help.py +++ b/tests/basics/builtin_help.py @@ -4,8 +4,7 @@ try: help except NameError: print("SKIP") - import sys - sys.exit() + raise SystemExit help() # no args help(help) # help for a function diff --git a/tests/basics/builtin_minmax.py b/tests/basics/builtin_minmax.py index a925b3fe9..184398e64 100644 --- a/tests/basics/builtin_minmax.py +++ b/tests/basics/builtin_minmax.py @@ -3,9 +3,8 @@ try: min max except: - import sys print("SKIP") - sys.exit() + raise SystemExit print(min(0,1)) print(min(1,0)) diff --git a/tests/basics/builtin_override.py b/tests/basics/builtin_override.py index f3632e59a..9f91341ed 100644 --- a/tests/basics/builtin_override.py +++ b/tests/basics/builtin_override.py @@ -6,9 +6,8 @@ import builtins try: builtins.abs = lambda x: x + 1 except AttributeError: - import sys print("SKIP") - sys.exit() + raise SystemExit print(abs(1)) diff --git a/tests/basics/builtin_pow3.py b/tests/basics/builtin_pow3.py index dec7253bb..69b57e548 100644 --- a/tests/basics/builtin_pow3.py +++ b/tests/basics/builtin_pow3.py @@ -4,9 +4,8 @@ try: print(pow(3, 4, 7)) except NotImplementedError: - import sys print("SKIP") - sys.exit() + raise SystemExit # 3 arg pow is defined to only work on integers try: diff --git a/tests/basics/builtin_pow3_intbig.py b/tests/basics/builtin_pow3_intbig.py index 9f482cbde..bedc8b36b 100644 --- a/tests/basics/builtin_pow3_intbig.py +++ b/tests/basics/builtin_pow3_intbig.py @@ -4,9 +4,8 @@ try: print(pow(3, 4, 7)) except NotImplementedError: - import sys print("SKIP") - sys.exit() + raise SystemExit print(pow(555557, 1000002, 1000003)) diff --git a/tests/basics/builtin_property.py b/tests/basics/builtin_property.py index ff4ff073c..89c3d4936 100644 --- a/tests/basics/builtin_property.py +++ b/tests/basics/builtin_property.py @@ -2,9 +2,8 @@ try: property except: - import sys print("SKIP") - sys.exit() + raise SystemExit # create a property object explicitly property() diff --git a/tests/basics/builtin_range_attrs.py b/tests/basics/builtin_range_attrs.py index 9327c802a..05d666d13 100644 --- a/tests/basics/builtin_range_attrs.py +++ b/tests/basics/builtin_range_attrs.py @@ -3,9 +3,8 @@ try: range(0).start except AttributeError: - import sys print("SKIP") - sys.exit() + raise SystemExit # attrs print(range(1, 2, 3).start) diff --git a/tests/basics/builtin_reversed.py b/tests/basics/builtin_reversed.py index 59e9c7821..f43505a8b 100644 --- a/tests/basics/builtin_reversed.py +++ b/tests/basics/builtin_reversed.py @@ -2,9 +2,8 @@ try: reversed except: - import sys print("SKIP") - sys.exit() + raise SystemExit # list print(list(reversed([]))) diff --git a/tests/basics/builtin_sorted.py b/tests/basics/builtin_sorted.py index 68855b61b..6435f86d0 100644 --- a/tests/basics/builtin_sorted.py +++ b/tests/basics/builtin_sorted.py @@ -3,9 +3,8 @@ try: sorted set except: - import sys print("SKIP") - sys.exit() + raise SystemExit print(sorted(set(range(100)))) print(sorted(set(range(100)), key=lambda x: x + 100*(x % 2))) diff --git a/tests/basics/bytearray_construct_array.py b/tests/basics/bytearray_construct_array.py index 6d45cafda..bde5fa08b 100644 --- a/tests/basics/bytearray_construct_array.py +++ b/tests/basics/bytearray_construct_array.py @@ -2,9 +2,8 @@ try: from array import array except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit # arrays print(bytearray(array('b', [1, 2]))) diff --git a/tests/basics/bytearray_construct_endian.py b/tests/basics/bytearray_construct_endian.py index f68f9b89d..0002f19c5 100644 --- a/tests/basics/bytearray_construct_endian.py +++ b/tests/basics/bytearray_construct_endian.py @@ -2,9 +2,8 @@ try: from array import array except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit # arrays print(bytearray(array('h', [1, 2]))) diff --git a/tests/basics/bytearray_slice_assign.py b/tests/basics/bytearray_slice_assign.py index c4b5c43e3..48f5938a5 100644 --- a/tests/basics/bytearray_slice_assign.py +++ b/tests/basics/bytearray_slice_assign.py @@ -2,8 +2,7 @@ try: bytearray()[:] = bytearray() except TypeError: print("SKIP") - import sys - sys.exit() + raise SystemExit # test slices; only 2 argument version supported by Micro Python at the moment x = bytearray(range(10)) diff --git a/tests/basics/bytes_add_array.py b/tests/basics/bytes_add_array.py index 2b8cbccef..b17556d83 100644 --- a/tests/basics/bytes_add_array.py +++ b/tests/basics/bytes_add_array.py @@ -2,9 +2,8 @@ try: import array except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit # should be byteorder-neutral print(b"123" + array.array('h', [0x1515])) diff --git a/tests/basics/bytes_add_endian.py b/tests/basics/bytes_add_endian.py index 1bbd0f2c3..8cfffa7b6 100644 --- a/tests/basics/bytes_add_endian.py +++ b/tests/basics/bytes_add_endian.py @@ -2,8 +2,7 @@ try: import array except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit print(b"123" + array.array('i', [1])) diff --git a/tests/basics/bytes_compare_array.py b/tests/basics/bytes_compare_array.py index ad41d1d37..ad378de70 100644 --- a/tests/basics/bytes_compare_array.py +++ b/tests/basics/bytes_compare_array.py @@ -1,9 +1,8 @@ try: import array except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit print(array.array('b', [1, 2]) in b'\x01\x02\x03') # CPython gives False here diff --git a/tests/basics/bytes_construct_array.py b/tests/basics/bytes_construct_array.py index 72c2d0c58..453eb5901 100644 --- a/tests/basics/bytes_construct_array.py +++ b/tests/basics/bytes_construct_array.py @@ -2,9 +2,8 @@ try: from array import array except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit # arrays print(bytes(array('b', [1, 2]))) diff --git a/tests/basics/bytes_construct_endian.py b/tests/basics/bytes_construct_endian.py index 77e0eaaa5..cf1a9f408 100644 --- a/tests/basics/bytes_construct_endian.py +++ b/tests/basics/bytes_construct_endian.py @@ -3,9 +3,8 @@ try: from array import array except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit # arrays print(bytes(array('h', [1, 2]))) diff --git a/tests/basics/bytes_partition.py b/tests/basics/bytes_partition.py index 7d3ffaaaa..5b503f544 100644 --- a/tests/basics/bytes_partition.py +++ b/tests/basics/bytes_partition.py @@ -2,8 +2,7 @@ try: str.partition except AttributeError: print("SKIP") - import sys - sys.exit() + raise SystemExit print(b"asdf".partition(b'g')) print(b"asdf".partition(b'a')) diff --git a/tests/basics/class_delattr_setattr.py b/tests/basics/class_delattr_setattr.py index 0d061aee6..190b4875b 100644 --- a/tests/basics/class_delattr_setattr.py +++ b/tests/basics/class_delattr_setattr.py @@ -6,9 +6,8 @@ try: def __delattr__(self, attr): pass del Test().noexist except AttributeError: - import sys print('SKIP') - sys.exit() + raise SystemExit # this class just prints the calls to see if they were executed class A(): diff --git a/tests/basics/class_descriptor.py b/tests/basics/class_descriptor.py index 7f295f071..eb88ba7b9 100644 --- a/tests/basics/class_descriptor.py +++ b/tests/basics/class_descriptor.py @@ -21,9 +21,8 @@ m = Main() try: m.__class__ except AttributeError: - import sys print("SKIP") - sys.exit() + raise SystemExit r = m.Forward if 'Descriptor' in repr(r.__class__): diff --git a/tests/basics/class_new.py b/tests/basics/class_new.py index 0198456b2..9a7072ad0 100644 --- a/tests/basics/class_new.py +++ b/tests/basics/class_new.py @@ -3,9 +3,8 @@ try: # nothing to test. object.__new__ except AttributeError: - import sys print("SKIP") - sys.exit() + raise SystemExit class A: def __new__(cls): print("A.__new__") diff --git a/tests/basics/class_store_class.py b/tests/basics/class_store_class.py index 00a291586..797f88f85 100644 --- a/tests/basics/class_store_class.py +++ b/tests/basics/class_store_class.py @@ -8,9 +8,8 @@ except ImportError: try: from ucollections import namedtuple except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit _DefragResultBase = namedtuple('DefragResult', [ 'foo', 'bar' ]) diff --git a/tests/basics/class_super_object.py b/tests/basics/class_super_object.py index a841d34ab..1fddbb38f 100644 --- a/tests/basics/class_super_object.py +++ b/tests/basics/class_super_object.py @@ -4,9 +4,8 @@ try: # nothing to test. object.__init__ except AttributeError: - import sys print("SKIP") - sys.exit() + raise SystemExit class Test(object): def __init__(self): diff --git a/tests/basics/dict_fromkeys2.py b/tests/basics/dict_fromkeys2.py index 7ea0cc5b3..dce1e8ef5 100644 --- a/tests/basics/dict_fromkeys2.py +++ b/tests/basics/dict_fromkeys2.py @@ -1,9 +1,8 @@ try: reversed except: - import sys print("SKIP") - sys.exit() + raise SystemExit # argument to fromkeys has no __len__ d = dict.fromkeys(reversed(range(1))) diff --git a/tests/basics/enumerate.py b/tests/basics/enumerate.py index 3cc1350a0..4f8239bf7 100644 --- a/tests/basics/enumerate.py +++ b/tests/basics/enumerate.py @@ -1,9 +1,8 @@ try: enumerate except: - import sys print("SKIP") - sys.exit() + raise SystemExit print(list(enumerate([]))) print(list(enumerate([1, 2, 3]))) diff --git a/tests/basics/errno1.py b/tests/basics/errno1.py index eae1bbe1b..63930b767 100644 --- a/tests/basics/errno1.py +++ b/tests/basics/errno1.py @@ -4,8 +4,7 @@ try: import uerrno except ImportError: print("SKIP") - import sys - sys.exit() + raise SystemExit # check that constants exist and are integers print(type(uerrno.EIO)) diff --git a/tests/basics/filter.py b/tests/basics/filter.py index d0b36733c..c6d97cf9b 100644 --- a/tests/basics/filter.py +++ b/tests/basics/filter.py @@ -1,9 +1,8 @@ try: filter except: - import sys print("SKIP") - sys.exit() + raise SystemExit print(list(filter(lambda x: x & 1, range(-3, 4)))) print(list(filter(None, range(-3, 4)))) diff --git a/tests/basics/frozenset1.py b/tests/basics/frozenset1.py index 7a4a33540..7bec24c29 100644 --- a/tests/basics/frozenset1.py +++ b/tests/basics/frozenset1.py @@ -4,8 +4,7 @@ try: frozenset except NameError: print("SKIP") - import sys - sys.exit() + raise SystemExit s = frozenset() print(s) diff --git a/tests/basics/frozenset_add.py b/tests/basics/frozenset_add.py index 415a8c2e1..fe24fbaf1 100644 --- a/tests/basics/frozenset_add.py +++ b/tests/basics/frozenset_add.py @@ -2,8 +2,7 @@ try: frozenset except NameError: print("SKIP") - import sys - sys.exit() + raise SystemExit s = frozenset({1, 2, 3, 4}) try: diff --git a/tests/basics/frozenset_binop.py b/tests/basics/frozenset_binop.py index 5cc07e9e1..61af07a23 100644 --- a/tests/basics/frozenset_binop.py +++ b/tests/basics/frozenset_binop.py @@ -2,8 +2,7 @@ try: frozenset except NameError: print("SKIP") - import sys - sys.exit() + raise SystemExit sets = [ frozenset(), frozenset({1}), frozenset({1, 2}), frozenset({1, 2, 3}), frozenset({2, 3}), diff --git a/tests/basics/frozenset_copy.py b/tests/basics/frozenset_copy.py index 92e115d34..c90f541a1 100644 --- a/tests/basics/frozenset_copy.py +++ b/tests/basics/frozenset_copy.py @@ -2,8 +2,7 @@ try: frozenset except NameError: print("SKIP") - import sys - sys.exit() + raise SystemExit s = frozenset({1, 2, 3, 4}) t = s.copy() diff --git a/tests/basics/frozenset_difference.py b/tests/basics/frozenset_difference.py index 3d142f959..bc8b9c21c 100644 --- a/tests/basics/frozenset_difference.py +++ b/tests/basics/frozenset_difference.py @@ -2,8 +2,7 @@ try: frozenset except NameError: print("SKIP") - import sys - sys.exit() + raise SystemExit l = [1, 2, 3, 4] s = frozenset(l) diff --git a/tests/basics/frozenset_set.py b/tests/basics/frozenset_set.py index b334694b5..3bf456acf 100644 --- a/tests/basics/frozenset_set.py +++ b/tests/basics/frozenset_set.py @@ -2,8 +2,7 @@ try: frozenset except NameError: print("SKIP") - import sys - sys.exit() + raise SystemExit # Examples from https://docs.python.org/3/library/stdtypes.html#set # "Instances of set are compared to instances of frozenset based on their diff --git a/tests/basics/fun_error2.py b/tests/basics/fun_error2.py index c4d2c0b64..2a00396e6 100644 --- a/tests/basics/fun_error2.py +++ b/tests/basics/fun_error2.py @@ -3,8 +3,7 @@ try: enumerate except: print("SKIP") - import sys - sys.exit() + raise SystemExit def test_exc(code, exc): try: diff --git a/tests/basics/gc1.py b/tests/basics/gc1.py index be6c6faed..dcbe0bfcf 100644 --- a/tests/basics/gc1.py +++ b/tests/basics/gc1.py @@ -4,8 +4,7 @@ try: import gc except ImportError: print("SKIP") - import sys - sys.exit() + raise SystemExit print(gc.isenabled()) gc.disable() diff --git a/tests/basics/memoryview1.py b/tests/basics/memoryview1.py index a771acdda..c4cc6ffab 100644 --- a/tests/basics/memoryview1.py +++ b/tests/basics/memoryview1.py @@ -2,9 +2,8 @@ try: memoryview except: - import sys print("SKIP") - sys.exit() + raise SystemExit # test reading from bytes b = b'1234' diff --git a/tests/basics/memoryview2.py b/tests/basics/memoryview2.py index 4b5af852b..06a7be59f 100644 --- a/tests/basics/memoryview2.py +++ b/tests/basics/memoryview2.py @@ -3,9 +3,8 @@ try: from array import array memoryview except: - import sys print("SKIP") - sys.exit() + raise SystemExit print(list(memoryview(b'\x7f\x80\x81\xff'))) print(list(memoryview(array('b', [0x7f, -0x80])))) diff --git a/tests/basics/memoryview_gc.py b/tests/basics/memoryview_gc.py index 9d4857e36..d366cbbb1 100644 --- a/tests/basics/memoryview_gc.py +++ b/tests/basics/memoryview_gc.py @@ -2,9 +2,8 @@ try: memoryview except: - import sys print("SKIP") - sys.exit() + raise SystemExit b = bytearray(10) m = memoryview(b)[1:] diff --git a/tests/basics/memoryview_intbig.py b/tests/basics/memoryview_intbig.py index 180f15d18..a76d9cbec 100644 --- a/tests/basics/memoryview_intbig.py +++ b/tests/basics/memoryview_intbig.py @@ -3,9 +3,8 @@ try: from array import array memoryview except: - import sys print("SKIP") - sys.exit() + raise SystemExit print(list(memoryview(array('i', [0x7f000000, -0x80000000])))) print(list(memoryview(array('I', [0x7f000000, 0x80000000, 0x81000000, 0xffffffff])))) diff --git a/tests/basics/namedtuple1.py b/tests/basics/namedtuple1.py index 70372f7ca..b9a007240 100644 --- a/tests/basics/namedtuple1.py +++ b/tests/basics/namedtuple1.py @@ -4,9 +4,8 @@ try: except ImportError: from ucollections import namedtuple except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit T = namedtuple("Tup", ["foo", "bar"]) # CPython prints fully qualified name, what we don't bother to do so far diff --git a/tests/basics/object_dict.py b/tests/basics/object_dict.py index e6fb7b3d9..7bf7094e3 100644 --- a/tests/basics/object_dict.py +++ b/tests/basics/object_dict.py @@ -1,4 +1,3 @@ -import sys class Foo: @@ -9,6 +8,6 @@ class Foo: o = Foo() if not hasattr(o, "__dict__"): print("SKIP") - sys.exit() + raise SystemExit print(o.__dict__ == {'a': 1, 'b': 'bar'}) diff --git a/tests/basics/object_new.py b/tests/basics/object_new.py index 568feccda..a9c9482cb 100644 --- a/tests/basics/object_new.py +++ b/tests/basics/object_new.py @@ -7,9 +7,8 @@ try: # nothing to test. object.__new__ except AttributeError: - import sys print("SKIP") - sys.exit() + raise SystemExit class Foo: diff --git a/tests/basics/op_error_memoryview.py b/tests/basics/op_error_memoryview.py index 658ededc8..8d4403f77 100644 --- a/tests/basics/op_error_memoryview.py +++ b/tests/basics/op_error_memoryview.py @@ -2,9 +2,8 @@ try: memoryview except: - import sys print("SKIP") - sys.exit() + raise SystemExit def test_exc(code, exc): try: diff --git a/tests/basics/ordereddict1.py b/tests/basics/ordereddict1.py index 7147968c5..d1633f0bb 100644 --- a/tests/basics/ordereddict1.py +++ b/tests/basics/ordereddict1.py @@ -5,8 +5,7 @@ except ImportError: from ucollections import OrderedDict except ImportError: print("SKIP") - import sys - sys.exit() + raise SystemExit d = OrderedDict([(10, 20), ("b", 100), (1, 2)]) print(len(d)) diff --git a/tests/basics/ordereddict_eq.py b/tests/basics/ordereddict_eq.py index 274660877..c69daf880 100644 --- a/tests/basics/ordereddict_eq.py +++ b/tests/basics/ordereddict_eq.py @@ -5,8 +5,7 @@ except ImportError: from ucollections import OrderedDict except ImportError: print("SKIP") - import sys - sys.exit() + raise SystemExit x = OrderedDict() y = OrderedDict() diff --git a/tests/basics/parser.py b/tests/basics/parser.py index 8fb2a49bf..626b67ad7 100644 --- a/tests/basics/parser.py +++ b/tests/basics/parser.py @@ -4,8 +4,7 @@ try: compile except NameError: print("SKIP") - import sys - sys.exit() + raise SystemExit # completely empty string # uPy and CPy differ for this case diff --git a/tests/basics/set_type.py b/tests/basics/set_type.py index d790fa062..787a99e81 100644 --- a/tests/basics/set_type.py +++ b/tests/basics/set_type.py @@ -5,9 +5,8 @@ try: set except NameError: - import sys print("SKIP") - sys.exit() + raise SystemExit print(set) diff --git a/tests/basics/slice_attrs.py b/tests/basics/slice_attrs.py index 67456ff8e..e85ead4ba 100644 --- a/tests/basics/slice_attrs.py +++ b/tests/basics/slice_attrs.py @@ -8,9 +8,8 @@ class A: try: t = A()[1:2] except: - import sys print("SKIP") - sys.exit() + raise SystemExit A()[1:2:3] diff --git a/tests/basics/special_methods2.py b/tests/basics/special_methods2.py index 3623b30dc..ba7cf27cd 100644 --- a/tests/basics/special_methods2.py +++ b/tests/basics/special_methods2.py @@ -100,9 +100,8 @@ cud2 = Cud() try: +cud1 except TypeError: - import sys print("SKIP") - sys.exit() + raise SystemExit # the following require MICROPY_PY_ALL_SPECIAL_METHODS +cud1 diff --git a/tests/basics/string_center.py b/tests/basics/string_center.py index a2739201a..40e8af4b8 100644 --- a/tests/basics/string_center.py +++ b/tests/basics/string_center.py @@ -1,9 +1,8 @@ try: str.center except: - import sys print("SKIP") - sys.exit() + raise SystemExit print("foo".center(0)) print("foo".center(1)) diff --git a/tests/basics/string_partition.py b/tests/basics/string_partition.py index b3b2f0907..bc36388fd 100644 --- a/tests/basics/string_partition.py +++ b/tests/basics/string_partition.py @@ -2,8 +2,7 @@ try: str.partition except AttributeError: print("SKIP") - import sys - sys.exit() + raise SystemExit print("asdf".partition('g')) print("asdf".partition('a')) diff --git a/tests/basics/string_rpartition.py b/tests/basics/string_rpartition.py index 84e0031fb..6d65dfaf2 100644 --- a/tests/basics/string_rpartition.py +++ b/tests/basics/string_rpartition.py @@ -2,8 +2,7 @@ try: str.partition except AttributeError: print("SKIP") - import sys - sys.exit() + raise SystemExit print("asdf".rpartition('g')) print("asdf".rpartition('a')) diff --git a/tests/basics/string_splitlines.py b/tests/basics/string_splitlines.py index 1d08f6e6d..c4c3fcb80 100644 --- a/tests/basics/string_splitlines.py +++ b/tests/basics/string_splitlines.py @@ -3,9 +3,8 @@ try: str.splitlines except: - import sys print("SKIP") - sys.exit() + raise SystemExit # test \n as newline print("foo\nbar".splitlines()) diff --git a/tests/basics/struct1.py b/tests/basics/struct1.py index bb6877c78..a442beb1e 100644 --- a/tests/basics/struct1.py +++ b/tests/basics/struct1.py @@ -4,9 +4,8 @@ except: try: import struct except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit print(struct.calcsize("