From fb5838041b2349c7df5b2f90317b6cc7ec657f84 Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 19 Jan 2017 23:38:11 +1100 Subject: tests/micropython/opt_level: Add test for opt_level 3. --- tests/micropython/opt_level.py | 4 ++++ tests/micropython/opt_level.py.exp | 3 +++ 2 files changed, 7 insertions(+) (limited to 'tests/micropython') diff --git a/tests/micropython/opt_level.py b/tests/micropython/opt_level.py index 4e2f2f4ea..e067ec651 100644 --- a/tests/micropython/opt_level.py +++ b/tests/micropython/opt_level.py @@ -12,3 +12,7 @@ exec('print(__debug__)') micropython.opt_level(1) exec('print(__debug__)') exec('assert 0') + +# check that level 3 doesn't store line numbers +micropython.opt_level(3) +exec('try:\n xyz\nexcept NameError as er:\n import sys\n sys.print_exception(er)') diff --git a/tests/micropython/opt_level.py.exp b/tests/micropython/opt_level.py.exp index 74b3dd74e..9b1bb4d24 100644 --- a/tests/micropython/opt_level.py.exp +++ b/tests/micropython/opt_level.py.exp @@ -2,3 +2,6 @@ 1 True False +Traceback (most recent call last): + File "", line 1, in +NameError: name 'xyz' is not defined -- cgit v1.2.3 From bd3dd9296b256d91e6021e481b7f4f5c6ae35a92 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sat, 21 Jan 2017 20:15:56 +0300 Subject: tests/heapalloc_int_from_bytes: Test that int.from_bytes() can work w/o alloc. For a small number of bytes, it's expected to return a small int without allocation. --- tests/micropython/heapalloc_int_from_bytes.py | 8 ++++++++ tests/micropython/heapalloc_int_from_bytes.py.exp | 2 ++ 2 files changed, 10 insertions(+) create mode 100644 tests/micropython/heapalloc_int_from_bytes.py create mode 100644 tests/micropython/heapalloc_int_from_bytes.py.exp (limited to 'tests/micropython') diff --git a/tests/micropython/heapalloc_int_from_bytes.py b/tests/micropython/heapalloc_int_from_bytes.py new file mode 100644 index 000000000..f8afd2280 --- /dev/null +++ b/tests/micropython/heapalloc_int_from_bytes.py @@ -0,0 +1,8 @@ +# Test that int.from_bytes() for small number of bytes generates +# small int. +import micropython + +micropython.heap_lock() +print(int.from_bytes(b"1", "little")) +print(int.from_bytes(b"12", "little")) +micropython.heap_unlock() diff --git a/tests/micropython/heapalloc_int_from_bytes.py.exp b/tests/micropython/heapalloc_int_from_bytes.py.exp new file mode 100644 index 000000000..7ceb19a38 --- /dev/null +++ b/tests/micropython/heapalloc_int_from_bytes.py.exp @@ -0,0 +1,2 @@ +49 +12849 -- cgit v1.2.3 From 9ffc3ae0e7355c69af212ba918c90ef9cb57be7b Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Fri, 27 Jan 2017 00:45:30 +0300 Subject: tests/heapalloc_str: Test for alloc-free string operations. Starts with concatenation with an empty string. --- tests/micropython/heapalloc_str.py | 14 ++++++++++++++ tests/micropython/heapalloc_str.py.exp | 0 2 files changed, 14 insertions(+) create mode 100644 tests/micropython/heapalloc_str.py create mode 100644 tests/micropython/heapalloc_str.py.exp (limited to 'tests/micropython') diff --git a/tests/micropython/heapalloc_str.py b/tests/micropython/heapalloc_str.py new file mode 100644 index 000000000..0df39d3c0 --- /dev/null +++ b/tests/micropython/heapalloc_str.py @@ -0,0 +1,14 @@ +# String operations which don't require allocation +import micropython + +micropython.heap_lock() + +b"" + b"" +b"" + b"1" +b"2" + b"" + +"" + "" +"" + "1" +"2" + "" + +micropython.heap_unlock() diff --git a/tests/micropython/heapalloc_str.py.exp b/tests/micropython/heapalloc_str.py.exp new file mode 100644 index 000000000..e69de29bb -- cgit v1.2.3 From b32880bd513b868465ad2ffd9b698c13ce7f964a Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Thu, 2 Feb 2017 00:38:38 +0300 Subject: tests/heapalloc_bytesio: Test for BytesIO with preallocates space. --- tests/micropython/heapalloc_bytesio.py | 13 +++++++++++++ tests/micropython/heapalloc_bytesio.py.exp | 1 + 2 files changed, 14 insertions(+) create mode 100644 tests/micropython/heapalloc_bytesio.py create mode 100644 tests/micropython/heapalloc_bytesio.py.exp (limited to 'tests/micropython') diff --git a/tests/micropython/heapalloc_bytesio.py b/tests/micropython/heapalloc_bytesio.py new file mode 100644 index 000000000..311632851 --- /dev/null +++ b/tests/micropython/heapalloc_bytesio.py @@ -0,0 +1,13 @@ +import uio +import micropython + +data = b"1234" * 16 +buf = uio.BytesIO(64) + +micropython.heap_lock() + +buf.write(data) + +micropython.heap_unlock() + +print(buf.getvalue()) diff --git a/tests/micropython/heapalloc_bytesio.py.exp b/tests/micropython/heapalloc_bytesio.py.exp new file mode 100644 index 000000000..675761c2b --- /dev/null +++ b/tests/micropython/heapalloc_bytesio.py.exp @@ -0,0 +1 @@ +b'1234123412341234123412341234123412341234123412341234123412341234' -- cgit v1.2.3 From 019048a6dc0783515e7fba4255dd2b22265d1059 Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 10 Feb 2017 16:09:20 +1100 Subject: tests/micropython: Add test for iterating with the heap locked. --- tests/micropython/heapalloc_iter.py | 49 +++++++++++++++++++++++++++++++++++++ tests/run-tests | 1 + 2 files changed, 50 insertions(+) create mode 100644 tests/micropython/heapalloc_iter.py (limited to 'tests/micropython') diff --git a/tests/micropython/heapalloc_iter.py b/tests/micropython/heapalloc_iter.py new file mode 100644 index 000000000..3315d78c3 --- /dev/null +++ b/tests/micropython/heapalloc_iter.py @@ -0,0 +1,49 @@ +# test that iterating doesn't use the heap + +try: + from micropython import heap_lock, heap_unlock +except (ImportError, AttributeError): + heap_lock = heap_unlock = lambda:0 +import array + +def do_iter(l): + for i in l: + print(i) + +def gen_func(): + yield 1 + yield 2 + +# pre-create collections to iterate over +ba = bytearray(b'123') +ar = array.array('H', (123, 456)) +t = (1, 2, 3) +l = [1, 2] +d = {1:2} +s = {1} +fs = frozenset((1,)) +g1 = (100 + x for x in range(2)) +g2 = gen_func() + +# test certain builtins with the heap locked +heap_lock() +print(all(t)) +print(any(t)) +print(min(t)) +print(max(t)) +print(sum(t)) +heap_unlock() + +# test iterating over collections with the heap locked +heap_lock() +do_iter(b'123') +do_iter(ba) +do_iter(ar) +do_iter(t) +do_iter(l) +do_iter(d) +do_iter(s) +do_iter(fs) +do_iter(g1) +do_iter(g2) +heap_unlock() diff --git a/tests/run-tests b/tests/run-tests index 4bebe8d47..6cca829b6 100755 --- a/tests/run-tests +++ b/tests/run-tests @@ -312,6 +312,7 @@ def run_tests(pyb, tests, args): skip_tests.add('misc/print_exception.py') # because native doesn't have proper traceback info skip_tests.add('misc/sys_exc_info.py') # sys.exc_info() is not supported for native skip_tests.add('micropython/heapalloc_traceback.py') # because native doesn't have proper traceback info + skip_tests.add('micropython/heapalloc_iter.py') # requires generators for test_file in tests: test_file = test_file.replace('\\', '/') -- cgit v1.2.3 From 7839b8b827199ce593bfb87bc62b426a2798fde6 Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 13 Feb 2017 15:45:24 +1100 Subject: tests/micropython/heapalloc_iter: Add tests for contains and unpack. --- tests/micropython/heapalloc_iter.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'tests/micropython') diff --git a/tests/micropython/heapalloc_iter.py b/tests/micropython/heapalloc_iter.py index 3315d78c3..e1ed3daa3 100644 --- a/tests/micropython/heapalloc_iter.py +++ b/tests/micropython/heapalloc_iter.py @@ -25,6 +25,22 @@ fs = frozenset((1,)) g1 = (100 + x for x in range(2)) g2 = gen_func() +# test containment (both success and failure) with the heap locked +heap_lock() +print(49 in b'123', 255 in b'123') +print(1 in t, -1 in t) +print(1 in l, -1 in l) +print(1 in d, -1 in d) +print(1 in s, -1 in s) +heap_unlock() + +# test unpacking with the heap locked +unp0 = unp1 = unp2 = None # preallocate slots for globals +heap_lock() +unp0, unp1, unp2 = t +print(unp0, unp1, unp2) +heap_unlock() + # test certain builtins with the heap locked heap_lock() print(all(t)) -- cgit v1.2.3 From 6fc6f10b1ec61ecaa1c72ed767a41fbf5bacaac9 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Mon, 20 Feb 2017 04:22:32 +0300 Subject: tests/heapalloc_exc_raise.py: Heap alloc test for raising/catching exc. --- tests/micropython/heapalloc_exc_raise.py | 23 +++++++++++++++++++++++ tests/micropython/heapalloc_exc_raise.py.exp | 2 ++ 2 files changed, 25 insertions(+) create mode 100644 tests/micropython/heapalloc_exc_raise.py create mode 100644 tests/micropython/heapalloc_exc_raise.py.exp (limited to 'tests/micropython') diff --git a/tests/micropython/heapalloc_exc_raise.py b/tests/micropython/heapalloc_exc_raise.py new file mode 100644 index 000000000..d60e14ce5 --- /dev/null +++ b/tests/micropython/heapalloc_exc_raise.py @@ -0,0 +1,23 @@ +# Test that we can raise and catch (preallocated) exception +# without memory allocation. +import micropython + +e = ValueError("error") + +def func(): + try: + # This works as is because traceback is not allocated + # if not possible (heap is locked, no memory). If heap + # is not locked, this would allocate a traceback entry. + # To avoid that, traceback should be warmed up (by raising + # it once after creation) and then cleared before each + # raise with: + # e.__traceback__ = None + raise e + except Exception as e2: + print(e2) + +micropython.heap_lock() +func() +print("ok") +micropython.heap_unlock() diff --git a/tests/micropython/heapalloc_exc_raise.py.exp b/tests/micropython/heapalloc_exc_raise.py.exp new file mode 100644 index 000000000..1e9edc75d --- /dev/null +++ b/tests/micropython/heapalloc_exc_raise.py.exp @@ -0,0 +1,2 @@ +error +ok -- cgit v1.2.3 From f62503dc4757902a1f68c55b938bcd6ddfd6e002 Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 24 Feb 2017 13:08:18 +1100 Subject: tests/micropython: Add test for consts that are bignums. --- tests/micropython/const_intbig.py | 13 +++++++++++++ tests/micropython/const_intbig.py.exp | 2 ++ 2 files changed, 15 insertions(+) create mode 100644 tests/micropython/const_intbig.py create mode 100644 tests/micropython/const_intbig.py.exp (limited to 'tests/micropython') diff --git a/tests/micropython/const_intbig.py b/tests/micropython/const_intbig.py new file mode 100644 index 000000000..e74902652 --- /dev/null +++ b/tests/micropython/const_intbig.py @@ -0,0 +1,13 @@ +# test constant optimisation, with consts that are bignums + +from micropython import const + +# check we can make consts from bignums +Z1 = const(0xffffffff) +Z2 = const(0xffffffffffffffff) +print(hex(Z1), hex(Z2)) + +# check arithmetic with bignum +Z3 = const(Z1 + Z2) +Z4 = const((1 << 100) + Z1) +print(hex(Z3), hex(Z4)) diff --git a/tests/micropython/const_intbig.py.exp b/tests/micropython/const_intbig.py.exp new file mode 100644 index 000000000..137f86cf8 --- /dev/null +++ b/tests/micropython/const_intbig.py.exp @@ -0,0 +1,2 @@ +0xffffffff 0xffffffffffffffff +0x100000000fffffffe 0x100000000000000000ffffffff -- cgit v1.2.3 From c98d7461a1c54b11b106ffb630ec079e1ab60993 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Tue, 7 Mar 2017 07:12:14 +0100 Subject: tests/micropython/: Split off intbig tests. --- tests/micropython/native_const.py | 7 ------- tests/micropython/native_const.py.exp | 1 - tests/micropython/native_const_intbig.py | 7 +++++++ tests/micropython/native_const_intbig.py.exp | 1 + tests/micropython/viper_misc.py | 7 ------- tests/micropython/viper_misc.py.exp | 1 - tests/micropython/viper_misc_intbig.py | 8 ++++++++ tests/micropython/viper_misc_intbig.py.exp | 1 + 8 files changed, 17 insertions(+), 16 deletions(-) delete mode 100644 tests/micropython/native_const.py delete mode 100644 tests/micropython/native_const.py.exp create mode 100644 tests/micropython/native_const_intbig.py create mode 100644 tests/micropython/native_const_intbig.py.exp create mode 100644 tests/micropython/viper_misc_intbig.py create mode 100644 tests/micropython/viper_misc_intbig.py.exp (limited to 'tests/micropython') diff --git a/tests/micropython/native_const.py b/tests/micropython/native_const.py deleted file mode 100644 index 611b39d8f..000000000 --- a/tests/micropython/native_const.py +++ /dev/null @@ -1,7 +0,0 @@ -# check loading constants - -@micropython.native -def f(): - return 123456789012345678901234567890 - -print(f()) diff --git a/tests/micropython/native_const.py.exp b/tests/micropython/native_const.py.exp deleted file mode 100644 index 1d52d220f..000000000 --- a/tests/micropython/native_const.py.exp +++ /dev/null @@ -1 +0,0 @@ -123456789012345678901234567890 diff --git a/tests/micropython/native_const_intbig.py b/tests/micropython/native_const_intbig.py new file mode 100644 index 000000000..611b39d8f --- /dev/null +++ b/tests/micropython/native_const_intbig.py @@ -0,0 +1,7 @@ +# check loading constants + +@micropython.native +def f(): + return 123456789012345678901234567890 + +print(f()) diff --git a/tests/micropython/native_const_intbig.py.exp b/tests/micropython/native_const_intbig.py.exp new file mode 100644 index 000000000..1d52d220f --- /dev/null +++ b/tests/micropython/native_const_intbig.py.exp @@ -0,0 +1 @@ +123456789012345678901234567890 diff --git a/tests/micropython/viper_misc.py b/tests/micropython/viper_misc.py index 8bf6cc638..021e03f2c 100644 --- a/tests/micropython/viper_misc.py +++ b/tests/micropython/viper_misc.py @@ -50,13 +50,6 @@ def viper_no_annotation(x, y): return x * y print(viper_no_annotation(4, 5)) -# unsigned ints -@micropython.viper -def viper_uint() -> uint: - return uint(-1) -import sys -print(viper_uint() == (sys.maxsize << 1 | 1)) - # a for loop @micropython.viper def viper_for(a:int, b:int) -> int: diff --git a/tests/micropython/viper_misc.py.exp b/tests/micropython/viper_misc.py.exp index 4800050d1..e4462771b 100644 --- a/tests/micropython/viper_misc.py.exp +++ b/tests/micropython/viper_misc.py.exp @@ -5,7 +5,6 @@ Ellipsis 6 7 20 -True 49994955 1 1 1 3 diff --git a/tests/micropython/viper_misc_intbig.py b/tests/micropython/viper_misc_intbig.py new file mode 100644 index 000000000..e036435c7 --- /dev/null +++ b/tests/micropython/viper_misc_intbig.py @@ -0,0 +1,8 @@ +import micropython + +# unsigned ints +@micropython.viper +def viper_uint() -> uint: + return uint(-1) +import sys +print(viper_uint() == (sys.maxsize << 1 | 1)) diff --git a/tests/micropython/viper_misc_intbig.py.exp b/tests/micropython/viper_misc_intbig.py.exp new file mode 100644 index 000000000..0ca95142b --- /dev/null +++ b/tests/micropython/viper_misc_intbig.py.exp @@ -0,0 +1 @@ +True -- cgit v1.2.3 From 1a71d30fb8fad17ea44de635d52e858f066ef308 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Thu, 9 Mar 2017 10:26:31 +0100 Subject: tests/micropython: Make uio-using tests skippable. --- tests/micropython/heapalloc_bytesio.py | 8 +++++++- tests/micropython/heapalloc_traceback.py | 7 ++++++- 2 files changed, 13 insertions(+), 2 deletions(-) (limited to 'tests/micropython') diff --git a/tests/micropython/heapalloc_bytesio.py b/tests/micropython/heapalloc_bytesio.py index 311632851..2a8d50abe 100644 --- a/tests/micropython/heapalloc_bytesio.py +++ b/tests/micropython/heapalloc_bytesio.py @@ -1,4 +1,10 @@ -import uio +try: + import uio +except ImportError: + import sys + print("SKIP") + sys.exit() + import micropython data = b"1234" * 16 diff --git a/tests/micropython/heapalloc_traceback.py b/tests/micropython/heapalloc_traceback.py index 808df0225..b3795293f 100644 --- a/tests/micropython/heapalloc_traceback.py +++ b/tests/micropython/heapalloc_traceback.py @@ -2,7 +2,12 @@ import micropython import sys -import uio +try: + import uio +except ImportError: + import sys + print("SKIP") + sys.exit() # preallocate exception instance with some room for a traceback global_exc = StopIteration() -- cgit v1.2.3 From 53018d5ad23c642a36efb67a862db5143080299d Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Thu, 9 Mar 2017 12:51:45 +0100 Subject: tests/micropython/heapalloc_traceback: Fix backtrace line # after refactor. --- tests/micropython/heapalloc_traceback.py.exp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/micropython') diff --git a/tests/micropython/heapalloc_traceback.py.exp b/tests/micropython/heapalloc_traceback.py.exp index 9ba10948d..facd0af13 100644 --- a/tests/micropython/heapalloc_traceback.py.exp +++ b/tests/micropython/heapalloc_traceback.py.exp @@ -1,5 +1,5 @@ StopIteration Traceback (most recent call last): - File , line 18, in test + File , line 23, in test StopIteration: -- cgit v1.2.3 From bc5bffbf65dee144744449a5ec60a3627830caa1 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Thu, 9 Mar 2017 23:21:37 +0100 Subject: tests/micropython/opt_level: Clarify the expected output for opt_level == 3. --- tests/micropython/opt_level.py | 1 + 1 file changed, 1 insertion(+) (limited to 'tests/micropython') diff --git a/tests/micropython/opt_level.py b/tests/micropython/opt_level.py index e067ec651..5a10047f0 100644 --- a/tests/micropython/opt_level.py +++ b/tests/micropython/opt_level.py @@ -14,5 +14,6 @@ exec('print(__debug__)') exec('assert 0') # check that level 3 doesn't store line numbers +# the expected output is that any line is printed as "line 1" micropython.opt_level(3) exec('try:\n xyz\nexcept NameError as er:\n import sys\n sys.print_exception(er)') -- cgit v1.2.3 From e29f704b6776ac9f7b95bb35d53d65948e995b38 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 14 Mar 2017 22:52:50 +1100 Subject: tests/micropython/viper_error: Add more tests to improve coverage. --- tests/micropython/viper_error.py | 24 +++++++++++++++++++++++- tests/micropython/viper_error.py.exp | 10 ++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) (limited to 'tests/micropython') diff --git a/tests/micropython/viper_error.py b/tests/micropython/viper_error.py index 116bd4ea0..847257285 100644 --- a/tests/micropython/viper_error.py +++ b/tests/micropython/viper_error.py @@ -3,13 +3,19 @@ def test(code): try: exec(code) - except (SyntaxError, ViperTypeError) as e: + except (SyntaxError, ViperTypeError, NotImplementedError) as e: print(repr(e)) # viper: annotations must be identifiers test("@micropython.viper\ndef f(a:1): pass") test("@micropython.viper\ndef f() -> 1: pass") +# unknown type +test("@micropython.viper\ndef f(x:unknown_type): pass") + +# too many arguments +test("@micropython.viper\ndef f(a, b, c, d, e): pass") + # local used before type known test(""" @micropython.viper @@ -49,6 +55,9 @@ test("@micropython.viper\ndef f(): 1[x]") # can't store test("@micropython.viper\ndef f(): 1[0] = 1") test("@micropython.viper\ndef f(): 1[x] = 1") +test("@micropython.viper\ndef f(x:int): x[0] = x") +test("@micropython.viper\ndef f(x:ptr32): x[0] = None") +test("@micropython.viper\ndef f(x:ptr32): x[x] = None") # must raise an object test("@micropython.viper\ndef f(): raise 1") @@ -57,3 +66,16 @@ test("@micropython.viper\ndef f(): raise 1") test("@micropython.viper\ndef f(x:int): +x") test("@micropython.viper\ndef f(x:int): -x") test("@micropython.viper\ndef f(x:int): ~x") + +# binary op not implemented +test("@micropython.viper\ndef f(x:int): res = x in x") + +# yield (from) not implemented +test("@micropython.viper\ndef f(): yield") +test("@micropython.viper\ndef f(): yield from f") + +# passing a ptr to a Python function not implemented +test("@micropython.viper\ndef f(): print(ptr(1))") + +# cast of a casting identifier not implemented +test("@micropython.viper\ndef f(): int(int)") diff --git a/tests/micropython/viper_error.py.exp b/tests/micropython/viper_error.py.exp index 1afcd4bdb..96be5a590 100644 --- a/tests/micropython/viper_error.py.exp +++ b/tests/micropython/viper_error.py.exp @@ -1,5 +1,7 @@ SyntaxError('parameter annotation must be an identifier',) SyntaxError('return annotation must be an identifier',) +ViperTypeError("unknown type 'unknown_type'",) +ViperTypeError("Viper functions don't currently support more than 4 arguments",) ViperTypeError("local 'x' used before type known",) ViperTypeError("local 'x' has type 'int' but source is 'object'",) ViperTypeError("can't implicitly convert 'ptr' to 'bool'",) @@ -9,7 +11,15 @@ ViperTypeError("can't load from 'int'",) ViperTypeError("can't load from 'int'",) ViperTypeError("can't store to 'int'",) ViperTypeError("can't store to 'int'",) +ViperTypeError("can't store to 'int'",) +ViperTypeError("can't store 'None'",) +ViperTypeError("can't store 'None'",) ViperTypeError('must raise an object',) ViperTypeError('unary op __pos__ not implemented',) ViperTypeError('unary op __neg__ not implemented',) ViperTypeError('unary op __invert__ not implemented',) +ViperTypeError('binary op __contains__ not implemented',) +NotImplementedError('native yield',) +NotImplementedError('native yield from',) +NotImplementedError('conversion to object',) +NotImplementedError('casting',) -- cgit v1.2.3 From c772817deea6f3e5fe63483db77a98b65974d833 Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 16 Mar 2017 18:05:00 +1100 Subject: tests/micropython: Add tests for micropython.schedule(). --- tests/micropython/schedule.py | 61 +++++++++++++++++++++++++++++++++++++++ tests/micropython/schedule.py.exp | 4 +++ tests/run-tests | 1 + 3 files changed, 66 insertions(+) create mode 100644 tests/micropython/schedule.py create mode 100644 tests/micropython/schedule.py.exp (limited to 'tests/micropython') diff --git a/tests/micropython/schedule.py b/tests/micropython/schedule.py new file mode 100644 index 000000000..3d584eea4 --- /dev/null +++ b/tests/micropython/schedule.py @@ -0,0 +1,61 @@ +# test micropython.schedule() function + +import micropython + +try: + micropython.schedule +except AttributeError: + print('SKIP') + import sys + sys.exit() + +# Basic test of scheduling a function. + +def callback(arg): + global done + print(arg) + done = True + +done = False +micropython.schedule(callback, 1) +while not done: + pass + +# Test that callbacks can be scheduled from within a callback, but +# that they don't execute until the outer callback is finished. + +def callback_inner(arg): + global done + print('inner') + done += 1 + +def callback_outer(arg): + global done + micropython.schedule(callback_inner, 0) + # need a loop so that the VM can check for pending events + for i in range(2): + pass + print('outer') + done += 1 + +done = 0 +micropython.schedule(callback_outer, 0) +while done != 2: + pass + +# Test that scheduling too many callbacks leads to an exception. To do this we +# must schedule from within a callback to guarantee that the scheduler is locked. + +def callback(arg): + global done + try: + for i in range(100): + micropython.schedule(lambda x:x, None) + except RuntimeError: + print('RuntimeError') + done = True + +done = False +micropython.schedule(callback, None) +while not done: + pass diff --git a/tests/micropython/schedule.py.exp b/tests/micropython/schedule.py.exp new file mode 100644 index 000000000..c4a3e1227 --- /dev/null +++ b/tests/micropython/schedule.py.exp @@ -0,0 +1,4 @@ +1 +outer +inner +RuntimeError diff --git a/tests/run-tests b/tests/run-tests index b1bb7dd84..e8dc2ba58 100755 --- a/tests/run-tests +++ b/tests/run-tests @@ -319,6 +319,7 @@ def run_tests(pyb, tests, args): skip_tests.add('misc/sys_exc_info.py') # sys.exc_info() is not supported for native skip_tests.add('micropython/heapalloc_traceback.py') # because native doesn't have proper traceback info skip_tests.add('micropython/heapalloc_iter.py') # requires generators + skip_tests.add('micropython/schedule.py') # native code doesn't check pending events for test_file in tests: test_file = test_file.replace('\\', '/') -- cgit v1.2.3 From 4a4bb84e9216a130050a13e20a19fbf476ed6e6c Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Wed, 22 Mar 2017 22:17:52 +0300 Subject: tests/heapalloc_str: Test no-replacement case for str.replace(). --- tests/micropython/heapalloc_str.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'tests/micropython') diff --git a/tests/micropython/heapalloc_str.py b/tests/micropython/heapalloc_str.py index 0df39d3c0..39aa56ccd 100644 --- a/tests/micropython/heapalloc_str.py +++ b/tests/micropython/heapalloc_str.py @@ -3,6 +3,7 @@ import micropython micropython.heap_lock() +# Concatenating empty string returns original string b"" + b"" b"" + b"1" b"2" + b"" @@ -11,4 +12,7 @@ b"2" + b"" "" + "1" "2" + "" +# If no replacements done, returns original string +"foo".replace(",", "_") + micropython.heap_unlock() -- cgit v1.2.3 From 806c07c8989e44e1be4832fd37688e2b5828b3af Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Mon, 3 Apr 2017 00:27:01 +0300 Subject: tests/micropython/heapalloc_iter: Improve skippability. --- tests/micropython/heapalloc_iter.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'tests/micropython') diff --git a/tests/micropython/heapalloc_iter.py b/tests/micropython/heapalloc_iter.py index e1ed3daa3..45d3519e4 100644 --- a/tests/micropython/heapalloc_iter.py +++ b/tests/micropython/heapalloc_iter.py @@ -1,10 +1,15 @@ # test that iterating doesn't use the heap +try: + import array +except ImportError: + import sys + print("SKIP") + sys.exit() try: from micropython import heap_lock, heap_unlock except (ImportError, AttributeError): heap_lock = heap_unlock = lambda:0 -import array def do_iter(l): for i in l: @@ -20,7 +25,7 @@ ar = array.array('H', (123, 456)) t = (1, 2, 3) l = [1, 2] d = {1:2} -s = {1} +s = set((1,)) fs = frozenset((1,)) g1 = (100 + x for x in range(2)) g2 = gen_func() -- cgit v1.2.3 From c7c14f163458046767b539c567a421076ea9a6b7 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 18 Apr 2017 16:21:47 +1000 Subject: tests/micropython: Add test for micropython.kbd_intr(). --- tests/micropython/kbd_intr.py | 13 +++++++++++++ tests/micropython/kbd_intr.py.exp | 0 2 files changed, 13 insertions(+) create mode 100644 tests/micropython/kbd_intr.py create mode 100644 tests/micropython/kbd_intr.py.exp (limited to 'tests/micropython') diff --git a/tests/micropython/kbd_intr.py b/tests/micropython/kbd_intr.py new file mode 100644 index 000000000..a7ce7464b --- /dev/null +++ b/tests/micropython/kbd_intr.py @@ -0,0 +1,13 @@ +# test the micropython.kbd_intr() function + +import micropython + +try: + micropython.kbd_intr +except AttributeError: + print('SKIP') + import sys + sys.exit() + +# just check we can actually call it +micropython.kbd_intr(3) diff --git a/tests/micropython/kbd_intr.py.exp b/tests/micropython/kbd_intr.py.exp new file mode 100644 index 000000000..e69de29bb -- 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/micropython') 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 dce7dd425977320b822f8bb529d123eafebe6e55 Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 5 May 2017 21:44:12 +1000 Subject: tests/micropython: Add test for int.from_bytes with many zero bytes. --- tests/micropython/heapalloc_int_from_bytes.py | 1 + tests/micropython/heapalloc_int_from_bytes.py.exp | 1 + 2 files changed, 2 insertions(+) (limited to 'tests/micropython') diff --git a/tests/micropython/heapalloc_int_from_bytes.py b/tests/micropython/heapalloc_int_from_bytes.py index f8afd2280..5fe50443a 100644 --- a/tests/micropython/heapalloc_int_from_bytes.py +++ b/tests/micropython/heapalloc_int_from_bytes.py @@ -5,4 +5,5 @@ import micropython micropython.heap_lock() print(int.from_bytes(b"1", "little")) print(int.from_bytes(b"12", "little")) +print(int.from_bytes(b"2\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", "little")) micropython.heap_unlock() diff --git a/tests/micropython/heapalloc_int_from_bytes.py.exp b/tests/micropython/heapalloc_int_from_bytes.py.exp index 7ceb19a38..5ac6a573f 100644 --- a/tests/micropython/heapalloc_int_from_bytes.py.exp +++ b/tests/micropython/heapalloc_int_from_bytes.py.exp @@ -1,2 +1,3 @@ 49 12849 +50 -- cgit v1.2.3 From 07241cd37a732e4219257e6b2fc67a84085b37f6 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Mon, 5 Jun 2017 23:54:21 +0300 Subject: py/objstringio: If created from immutable object, follow copy on write policy. Don't create copy of immutable object's contents until .write() is called on BytesIO. --- py/objstringio.c | 30 ++++++++++++++++++++++++++--- py/objstringio.h | 2 ++ tests/io/bytesio_cow.py | 20 +++++++++++++++++++ tests/micropython/heapalloc_bytesio2.py | 20 +++++++++++++++++++ tests/micropython/heapalloc_bytesio2.py.exp | 1 + 5 files changed, 70 insertions(+), 3 deletions(-) create mode 100644 tests/io/bytesio_cow.py create mode 100644 tests/micropython/heapalloc_bytesio2.py create mode 100644 tests/micropython/heapalloc_bytesio2.py.exp (limited to 'tests/micropython') diff --git a/py/objstringio.c b/py/objstringio.c index 9f4adeebb..645c441cb 100644 --- a/py/objstringio.c +++ b/py/objstringio.c @@ -68,10 +68,23 @@ STATIC mp_uint_t stringio_read(mp_obj_t o_in, void *buf, mp_uint_t size, int *er return size; } +STATIC void stringio_copy_on_write(mp_obj_stringio_t *o) { + const void *buf = o->vstr->buf; + o->vstr->buf = m_new(char, o->vstr->len); + memcpy(o->vstr->buf, buf, o->vstr->len); + o->vstr->fixed_buf = false; + o->ref_obj = MP_OBJ_NULL; +} + STATIC mp_uint_t stringio_write(mp_obj_t o_in, const void *buf, mp_uint_t size, int *errcode) { (void)errcode; mp_obj_stringio_t *o = MP_OBJ_TO_PTR(o_in); check_stringio_is_open(o); + + if (o->vstr->fixed_buf) { + stringio_copy_on_write(o); + } + mp_uint_t new_pos = o->pos + size; if (new_pos < size) { // Writing bytes will overflow o->pos beyond limit of mp_uint_t. @@ -155,11 +168,11 @@ STATIC mp_obj_t stringio___exit__(size_t n_args, const mp_obj_t *args) { } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(stringio___exit___obj, 4, 4, stringio___exit__); -STATIC mp_obj_stringio_t *stringio_new(const mp_obj_type_t *type, mp_uint_t alloc) { +STATIC mp_obj_stringio_t *stringio_new(const mp_obj_type_t *type) { mp_obj_stringio_t *o = m_new_obj(mp_obj_stringio_t); o->base.type = type; - o->vstr = vstr_new(alloc); o->pos = 0; + o->ref_obj = MP_OBJ_NULL; return o; } @@ -170,17 +183,28 @@ STATIC mp_obj_t stringio_make_new(const mp_obj_type_t *type_in, size_t n_args, s bool initdata = false; mp_buffer_info_t bufinfo; + mp_obj_stringio_t *o = stringio_new(type_in); + if (n_args > 0) { if (MP_OBJ_IS_INT(args[0])) { sz = mp_obj_get_int(args[0]); } else { mp_get_buffer_raise(args[0], &bufinfo, MP_BUFFER_READ); + + if (MP_OBJ_IS_STR_OR_BYTES(args[0])) { + o->vstr = m_new_obj(vstr_t); + vstr_init_fixed_buf(o->vstr, bufinfo.len, bufinfo.buf); + o->vstr->len = bufinfo.len; + o->ref_obj = args[0]; + return MP_OBJ_FROM_PTR(o); + } + sz = bufinfo.len; initdata = true; } } - mp_obj_stringio_t *o = stringio_new(type_in, sz); + o->vstr = vstr_new(sz); if (initdata) { stringio_write(MP_OBJ_FROM_PTR(o), bufinfo.buf, bufinfo.len, NULL); diff --git a/py/objstringio.h b/py/objstringio.h index 853bfb11b..56738f4e4 100644 --- a/py/objstringio.h +++ b/py/objstringio.h @@ -33,6 +33,8 @@ typedef struct _mp_obj_stringio_t { vstr_t *vstr; // StringIO has single pointer used for both reading and writing mp_uint_t pos; + // Underlying object buffered by this StringIO + mp_obj_t ref_obj; } mp_obj_stringio_t; #endif // MICROPY_INCLUDED_PY_OBJSTRINGIO_H diff --git a/tests/io/bytesio_cow.py b/tests/io/bytesio_cow.py new file mode 100644 index 000000000..92654a000 --- /dev/null +++ b/tests/io/bytesio_cow.py @@ -0,0 +1,20 @@ +# Make sure that write operations on io.BytesIO don't +# change original object it was constructed from. +try: + import uio as io +except ImportError: + import io + +b = b"foobar" + +a = io.BytesIO(b) +a.write(b"1") +print(b) +print(a.getvalue()) + +b = bytearray(b"foobar") + +a = io.BytesIO(b) +a.write(b"1") +print(b) +print(a.getvalue()) diff --git a/tests/micropython/heapalloc_bytesio2.py b/tests/micropython/heapalloc_bytesio2.py new file mode 100644 index 000000000..cd76f5807 --- /dev/null +++ b/tests/micropython/heapalloc_bytesio2.py @@ -0,0 +1,20 @@ +# Creating BytesIO from immutable object should not immediately +# copy its content. +try: + import uio + import micropython + micropython.mem_total +except (ImportError, AttributeError): + print("SKIP") + raise SystemExit + + +data = b"1234" * 256 + +before = micropython.mem_total() + +buf = uio.BytesIO(data) + +after = micropython.mem_total() + +print(after - before < len(data)) diff --git a/tests/micropython/heapalloc_bytesio2.py.exp b/tests/micropython/heapalloc_bytesio2.py.exp new file mode 100644 index 000000000..0ca95142b --- /dev/null +++ b/tests/micropython/heapalloc_bytesio2.py.exp @@ -0,0 +1 @@ +True -- cgit v1.2.3 From 85d809d1f4e35a511e0a56b3411126e05a31c01b Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sat, 10 Jun 2017 20:14:16 +0300 Subject: tests: Convert remaining "sys.exit()" to "raise SystemExit". --- tests/extmod/btree1.py | 3 +-- tests/extmod/framebuf1.py | 3 +-- tests/extmod/framebuf16.py | 3 +-- tests/extmod/framebuf4.py | 3 +-- tests/extmod/machine1.py | 3 +-- tests/extmod/machine_pinbase.py | 3 +-- tests/extmod/machine_pulse.py | 3 +-- tests/extmod/machine_signal.py | 3 +-- tests/extmod/time_ms_us.py | 3 +-- tests/extmod/ubinascii_a2b_base64.py | 3 +-- tests/extmod/ubinascii_b2a_base64.py | 3 +-- tests/extmod/ubinascii_crc32.py | 6 ++---- tests/extmod/ubinascii_hexlify.py | 3 +-- tests/extmod/ubinascii_micropython.py | 3 +-- tests/extmod/ubinascii_unhexlify.py | 3 +-- tests/extmod/uctypes_32bit_intbig.py | 3 +-- tests/extmod/uctypes_array_assign_le.py | 3 +-- tests/extmod/uctypes_array_assign_native_le.py | 4 ++-- tests/extmod/uctypes_array_assign_native_le_intbig.py | 4 ++-- tests/extmod/uctypes_bytearray.py | 3 +-- tests/extmod/uctypes_le.py | 3 +-- tests/extmod/uctypes_le_float.py | 3 +-- tests/extmod/uctypes_native_float.py | 3 +-- tests/extmod/uctypes_native_le.py | 4 ++-- tests/extmod/uctypes_print.py | 3 +-- tests/extmod/uctypes_ptr_le.py | 4 ++-- tests/extmod/uctypes_ptr_native_le.py | 4 ++-- tests/extmod/uctypes_sizeof.py | 3 +-- tests/extmod/uctypes_sizeof_native.py | 3 +-- tests/extmod/uhashlib_sha1.py | 5 ++--- tests/extmod/uhashlib_sha256.py | 3 +-- tests/extmod/uheapq1.py | 3 +-- tests/extmod/ujson_dumps.py | 3 +-- tests/extmod/ujson_dumps_extra.py | 3 +-- tests/extmod/ujson_dumps_float.py | 3 +-- tests/extmod/ujson_load.py | 3 +-- tests/extmod/ujson_loads.py | 3 +-- tests/extmod/ujson_loads_float.py | 3 +-- tests/extmod/urandom_basic.py | 3 +-- tests/extmod/urandom_extra.py | 6 ++---- tests/extmod/ure1.py | 3 +-- tests/extmod/ure_debug.py | 3 +-- tests/extmod/ure_error.py | 3 +-- tests/extmod/ure_group.py | 3 +-- tests/extmod/ure_namedclass.py | 3 +-- tests/extmod/ure_split.py | 3 +-- tests/extmod/ure_split_empty.py | 3 +-- tests/extmod/ure_split_notimpl.py | 3 +-- tests/extmod/ussl_basic.py | 3 +-- tests/extmod/utimeq1.py | 3 +-- tests/extmod/utimeq_stable.py | 3 +-- tests/extmod/uzlib_decompio.py | 3 +-- tests/extmod/uzlib_decompio_gz.py | 3 +-- tests/extmod/uzlib_decompress.py | 3 +-- tests/extmod/vfs_basic.py | 3 +-- tests/extmod/vfs_fat_fileio1.py | 7 +++---- tests/extmod/vfs_fat_fileio2.py | 7 +++---- tests/extmod/vfs_fat_more.py | 7 +++---- tests/extmod/vfs_fat_oldproto.py | 7 +++---- tests/extmod/vfs_fat_ramdisk.py | 7 +++---- tests/extmod/websocket_basic.py | 3 +-- tests/io/buffered_writer.py | 3 +-- tests/io/open_append.py | 3 +-- tests/io/open_plus.py | 3 +-- tests/io/resource_stream.py | 2 +- tests/io/write_ext.py | 3 +-- tests/jni/list.py | 3 +-- tests/jni/object.py | 3 +-- tests/jni/system_out.py | 3 +-- tests/micropython/heapalloc_bytesio.py | 3 +-- tests/micropython/heapalloc_iter.py | 3 +-- tests/micropython/heapalloc_traceback.py | 3 +-- tests/micropython/heapalloc_traceback.py.exp | 2 +- tests/micropython/kbd_intr.py | 3 +-- tests/micropython/schedule.py | 3 +-- tests/misc/non_compliant.py | 3 +-- tests/misc/print_exception.py | 2 +- tests/misc/recursive_data.py | 3 +-- tests/misc/recursive_iternext.py | 3 +-- tests/misc/sys_exc_info.py | 2 +- tests/pyb/can.py | 3 +-- tests/pyb/dac.py | 3 +-- tests/pyb/pyb_f405.py | 3 +-- tests/pyb/pyb_f411.py | 3 +-- tests/unix/extra_coverage.py | 3 +-- tests/unix/ffi_callback.py | 3 +-- tests/unix/ffi_float.py | 3 +-- tests/unix/ffi_float2.py | 5 ++--- 88 files changed, 107 insertions(+), 188 deletions(-) (limited to 'tests/micropython') diff --git a/tests/extmod/btree1.py b/tests/extmod/btree1.py index 2127554db..59638ef0a 100644 --- a/tests/extmod/btree1.py +++ b/tests/extmod/btree1.py @@ -4,8 +4,7 @@ try: import uerrno except ImportError: print("SKIP") - import sys - sys.exit() + raise SystemExit #f = open("_test.db", "w+b") f = uio.BytesIO() diff --git a/tests/extmod/framebuf1.py b/tests/extmod/framebuf1.py index 990b0b120..2c1366522 100644 --- a/tests/extmod/framebuf1.py +++ b/tests/extmod/framebuf1.py @@ -2,8 +2,7 @@ try: import framebuf except ImportError: print("SKIP") - import sys - sys.exit() + raise SystemExit w = 5 h = 16 diff --git a/tests/extmod/framebuf16.py b/tests/extmod/framebuf16.py index 3aa1d34de..fe81f7f93 100644 --- a/tests/extmod/framebuf16.py +++ b/tests/extmod/framebuf16.py @@ -2,8 +2,7 @@ try: import framebuf except ImportError: print("SKIP") - import sys - sys.exit() + raise SystemExit def printbuf(): print("--8<--") diff --git a/tests/extmod/framebuf4.py b/tests/extmod/framebuf4.py index 641f5bfc5..8358fa55b 100644 --- a/tests/extmod/framebuf4.py +++ b/tests/extmod/framebuf4.py @@ -2,8 +2,7 @@ try: import framebuf except ImportError: print("SKIP") - import sys - sys.exit() + raise SystemExit def printbuf(): print("--8<--") diff --git a/tests/extmod/machine1.py b/tests/extmod/machine1.py index e0c561168..6ff38cc05 100644 --- a/tests/extmod/machine1.py +++ b/tests/extmod/machine1.py @@ -8,8 +8,7 @@ try: machine.mem8 except: print("SKIP") - import sys - sys.exit() + raise SystemExit print(machine.mem8) diff --git a/tests/extmod/machine_pinbase.py b/tests/extmod/machine_pinbase.py index 5e82823ec..e91775504 100644 --- a/tests/extmod/machine_pinbase.py +++ b/tests/extmod/machine_pinbase.py @@ -6,8 +6,7 @@ try: machine.PinBase except AttributeError: print("SKIP") - import sys - sys.exit() + raise SystemExit class MyPin(machine.PinBase): diff --git a/tests/extmod/machine_pulse.py b/tests/extmod/machine_pulse.py index 6491b5409..d525974e0 100644 --- a/tests/extmod/machine_pulse.py +++ b/tests/extmod/machine_pulse.py @@ -7,8 +7,7 @@ try: machine.time_pulse_us except AttributeError: print("SKIP") - import sys - sys.exit() + raise SystemExit class ConstPin(machine.PinBase): diff --git a/tests/extmod/machine_signal.py b/tests/extmod/machine_signal.py index 96b8f43c7..53f4f5890 100644 --- a/tests/extmod/machine_signal.py +++ b/tests/extmod/machine_signal.py @@ -9,8 +9,7 @@ try: machine.Signal except AttributeError: print("SKIP") - import sys - sys.exit() + raise SystemExit class Pin(machine.PinBase): def __init__(self): diff --git a/tests/extmod/time_ms_us.py b/tests/extmod/time_ms_us.py index 2078f1bb5..31f07d31b 100644 --- a/tests/extmod/time_ms_us.py +++ b/tests/extmod/time_ms_us.py @@ -1,10 +1,9 @@ -import sys import utime try: utime.sleep_ms except AttributeError: print("SKIP") - sys.exit() + raise SystemExit utime.sleep_ms(1) utime.sleep_us(1) diff --git a/tests/extmod/ubinascii_a2b_base64.py b/tests/extmod/ubinascii_a2b_base64.py index 58eb0b50b..b35f26591 100644 --- a/tests/extmod/ubinascii_a2b_base64.py +++ b/tests/extmod/ubinascii_a2b_base64.py @@ -4,9 +4,8 @@ try: except ImportError: import binascii except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit print(binascii.a2b_base64(b'')) print(binascii.a2b_base64(b'Zg==')) diff --git a/tests/extmod/ubinascii_b2a_base64.py b/tests/extmod/ubinascii_b2a_base64.py index 1c0c30311..f4bb69fe0 100644 --- a/tests/extmod/ubinascii_b2a_base64.py +++ b/tests/extmod/ubinascii_b2a_base64.py @@ -4,9 +4,8 @@ try: except ImportError: import binascii except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit print(binascii.b2a_base64(b'')) print(binascii.b2a_base64(b'f')) diff --git a/tests/extmod/ubinascii_crc32.py b/tests/extmod/ubinascii_crc32.py index b82c44d6b..89664a9b3 100644 --- a/tests/extmod/ubinascii_crc32.py +++ b/tests/extmod/ubinascii_crc32.py @@ -4,16 +4,14 @@ try: except ImportError: import binascii except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit try: binascii.crc32 except AttributeError: print("SKIP") - import sys - sys.exit() + raise SystemExit print(hex(binascii.crc32(b'The quick brown fox jumps over the lazy dog'))) print(hex(binascii.crc32(b'\x00' * 32))) diff --git a/tests/extmod/ubinascii_hexlify.py b/tests/extmod/ubinascii_hexlify.py index 5d70bda96..bc9928747 100644 --- a/tests/extmod/ubinascii_hexlify.py +++ b/tests/extmod/ubinascii_hexlify.py @@ -4,9 +4,8 @@ try: except ImportError: import binascii except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit print(binascii.hexlify(b'\x00\x01\x02\x03\x04\x05\x06\x07')) print(binascii.hexlify(b'\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f')) diff --git a/tests/extmod/ubinascii_micropython.py b/tests/extmod/ubinascii_micropython.py index 96f566bd1..a4c00a2cb 100644 --- a/tests/extmod/ubinascii_micropython.py +++ b/tests/extmod/ubinascii_micropython.py @@ -4,9 +4,8 @@ try: except ImportError: import binascii except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit # two arguments supported in uPy but not CPython a = binascii.hexlify(b'123', ':') diff --git a/tests/extmod/ubinascii_unhexlify.py b/tests/extmod/ubinascii_unhexlify.py index e669789ba..865abfe3a 100644 --- a/tests/extmod/ubinascii_unhexlify.py +++ b/tests/extmod/ubinascii_unhexlify.py @@ -4,9 +4,8 @@ try: except ImportError: import binascii except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit print(binascii.unhexlify(b'0001020304050607')) print(binascii.unhexlify(b'08090a0b0c0d0e0f')) diff --git a/tests/extmod/uctypes_32bit_intbig.py b/tests/extmod/uctypes_32bit_intbig.py index a082dc370..6b4d3d76c 100644 --- a/tests/extmod/uctypes_32bit_intbig.py +++ b/tests/extmod/uctypes_32bit_intbig.py @@ -3,9 +3,8 @@ try: import uctypes except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit buf = b"12345678abcd" struct = uctypes.struct( diff --git a/tests/extmod/uctypes_array_assign_le.py b/tests/extmod/uctypes_array_assign_le.py index bae467d09..6afa7e0a2 100644 --- a/tests/extmod/uctypes_array_assign_le.py +++ b/tests/extmod/uctypes_array_assign_le.py @@ -1,9 +1,8 @@ try: import uctypes except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit desc = { # arr is array at offset 0, of UINT8 elements, array size is 2 diff --git a/tests/extmod/uctypes_array_assign_native_le.py b/tests/extmod/uctypes_array_assign_native_le.py index f0ecc0dad..a538bf9ad 100644 --- a/tests/extmod/uctypes_array_assign_native_le.py +++ b/tests/extmod/uctypes_array_assign_native_le.py @@ -3,11 +3,11 @@ try: import uctypes except ImportError: print("SKIP") - sys.exit() + raise SystemExit if sys.byteorder != "little": print("SKIP") - sys.exit() + raise SystemExit desc = { # arr is array at offset 0, of UINT8 elements, array size is 2 diff --git a/tests/extmod/uctypes_array_assign_native_le_intbig.py b/tests/extmod/uctypes_array_assign_native_le_intbig.py index f29a3b66e..84dfba0e2 100644 --- a/tests/extmod/uctypes_array_assign_native_le_intbig.py +++ b/tests/extmod/uctypes_array_assign_native_le_intbig.py @@ -3,11 +3,11 @@ try: import uctypes except ImportError: print("SKIP") - sys.exit() + raise SystemExit if sys.byteorder != "little": print("SKIP") - sys.exit() + raise SystemExit desc = { # arr is array at offset 0, of UINT8 elements, array size is 2 diff --git a/tests/extmod/uctypes_bytearray.py b/tests/extmod/uctypes_bytearray.py index bf7845ab2..61c7da271 100644 --- a/tests/extmod/uctypes_bytearray.py +++ b/tests/extmod/uctypes_bytearray.py @@ -1,9 +1,8 @@ try: import uctypes except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit desc = { "arr": (uctypes.ARRAY | 0, uctypes.UINT8 | 2), diff --git a/tests/extmod/uctypes_le.py b/tests/extmod/uctypes_le.py index 829beda58..7df5ac090 100644 --- a/tests/extmod/uctypes_le.py +++ b/tests/extmod/uctypes_le.py @@ -1,9 +1,8 @@ try: import uctypes except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit desc = { "s0": uctypes.UINT16 | 0, diff --git a/tests/extmod/uctypes_le_float.py b/tests/extmod/uctypes_le_float.py index a61305ba8..84ff2b84c 100644 --- a/tests/extmod/uctypes_le_float.py +++ b/tests/extmod/uctypes_le_float.py @@ -1,9 +1,8 @@ try: import uctypes except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit desc = { "f32": uctypes.FLOAT32 | 0, diff --git a/tests/extmod/uctypes_native_float.py b/tests/extmod/uctypes_native_float.py index 80cb54383..acef47036 100644 --- a/tests/extmod/uctypes_native_float.py +++ b/tests/extmod/uctypes_native_float.py @@ -1,9 +1,8 @@ try: import uctypes except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit desc = { "f32": uctypes.FLOAT32 | 0, diff --git a/tests/extmod/uctypes_native_le.py b/tests/extmod/uctypes_native_le.py index 5900224d4..8bba03b38 100644 --- a/tests/extmod/uctypes_native_le.py +++ b/tests/extmod/uctypes_native_le.py @@ -6,11 +6,11 @@ try: import uctypes except ImportError: print("SKIP") - sys.exit() + raise SystemExit if sys.byteorder != "little": print("SKIP") - sys.exit() + raise SystemExit desc = { diff --git a/tests/extmod/uctypes_print.py b/tests/extmod/uctypes_print.py index 76a009dc7..c310238e5 100644 --- a/tests/extmod/uctypes_print.py +++ b/tests/extmod/uctypes_print.py @@ -2,9 +2,8 @@ try: import uctypes except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit # we use an address of "0" because we just want to print something deterministic # and don't actually need to set/get any values in the struct diff --git a/tests/extmod/uctypes_ptr_le.py b/tests/extmod/uctypes_ptr_le.py index e8a6243ce..056e45650 100644 --- a/tests/extmod/uctypes_ptr_le.py +++ b/tests/extmod/uctypes_ptr_le.py @@ -3,11 +3,11 @@ try: import uctypes except ImportError: print("SKIP") - sys.exit() + raise SystemExit if sys.byteorder != "little": print("SKIP") - sys.exit() + raise SystemExit desc = { "ptr": (uctypes.PTR | 0, uctypes.UINT8), diff --git a/tests/extmod/uctypes_ptr_native_le.py b/tests/extmod/uctypes_ptr_native_le.py index 9b016c04d..24508b1cb 100644 --- a/tests/extmod/uctypes_ptr_native_le.py +++ b/tests/extmod/uctypes_ptr_native_le.py @@ -3,11 +3,11 @@ try: import uctypes except ImportError: print("SKIP") - sys.exit() + raise SystemExit if sys.byteorder != "little": print("SKIP") - sys.exit() + raise SystemExit desc = { diff --git a/tests/extmod/uctypes_sizeof.py b/tests/extmod/uctypes_sizeof.py index 266cd0694..5a6adb437 100644 --- a/tests/extmod/uctypes_sizeof.py +++ b/tests/extmod/uctypes_sizeof.py @@ -1,9 +1,8 @@ try: import uctypes except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit desc = { # arr is array at offset 0, of UINT8 elements, array size is 2 diff --git a/tests/extmod/uctypes_sizeof_native.py b/tests/extmod/uctypes_sizeof_native.py index f676c8c6d..32c740e77 100644 --- a/tests/extmod/uctypes_sizeof_native.py +++ b/tests/extmod/uctypes_sizeof_native.py @@ -1,9 +1,8 @@ try: import uctypes except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit S1 = {} assert uctypes.sizeof(S1) == 0 diff --git a/tests/extmod/uhashlib_sha1.py b/tests/extmod/uhashlib_sha1.py index f12fc649a..4f7066899 100644 --- a/tests/extmod/uhashlib_sha1.py +++ b/tests/extmod/uhashlib_sha1.py @@ -1,4 +1,3 @@ -import sys try: import uhashlib as hashlib except ImportError: @@ -8,14 +7,14 @@ except ImportError: # This is neither uPy, nor cPy, so must be uPy with # uhashlib module disabled. print("SKIP") - sys.exit() + raise SystemExit try: hashlib.sha1 except AttributeError: # SHA1 is only available on some ports print("SKIP") - sys.exit() + raise SystemExit sha1 = hashlib.sha1(b'hello') sha1.update(b'world') diff --git a/tests/extmod/uhashlib_sha256.py b/tests/extmod/uhashlib_sha256.py index ff51f2ffa..3200e8f5c 100644 --- a/tests/extmod/uhashlib_sha256.py +++ b/tests/extmod/uhashlib_sha256.py @@ -1,4 +1,3 @@ -import sys try: import uhashlib as hashlib except ImportError: @@ -8,7 +7,7 @@ except ImportError: # This is neither uPy, nor cPy, so must be uPy with # uhashlib module disabled. print("SKIP") - sys.exit() + raise SystemExit h = hashlib.sha256() diff --git a/tests/extmod/uheapq1.py b/tests/extmod/uheapq1.py index 4b0e5de57..7c1fe4e1e 100644 --- a/tests/extmod/uheapq1.py +++ b/tests/extmod/uheapq1.py @@ -4,9 +4,8 @@ except: try: import heapq except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit try: heapq.heappop([]) diff --git a/tests/extmod/ujson_dumps.py b/tests/extmod/ujson_dumps.py index 4a02f5170..d73271801 100644 --- a/tests/extmod/ujson_dumps.py +++ b/tests/extmod/ujson_dumps.py @@ -4,9 +4,8 @@ except ImportError: try: import json except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit print(json.dumps(False)) print(json.dumps(True)) diff --git a/tests/extmod/ujson_dumps_extra.py b/tests/extmod/ujson_dumps_extra.py index a52e8224c..21a388c32 100644 --- a/tests/extmod/ujson_dumps_extra.py +++ b/tests/extmod/ujson_dumps_extra.py @@ -3,8 +3,7 @@ try: import ujson except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit print(ujson.dumps(b'1234')) diff --git a/tests/extmod/ujson_dumps_float.py b/tests/extmod/ujson_dumps_float.py index d949ea6dd..e8cceb6f1 100644 --- a/tests/extmod/ujson_dumps_float.py +++ b/tests/extmod/ujson_dumps_float.py @@ -4,8 +4,7 @@ except ImportError: try: import json except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit print(json.dumps(1.2)) diff --git a/tests/extmod/ujson_load.py b/tests/extmod/ujson_load.py index 901132a5f..9725ab2dd 100644 --- a/tests/extmod/ujson_load.py +++ b/tests/extmod/ujson_load.py @@ -6,9 +6,8 @@ except: from io import StringIO import json except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit print(json.load(StringIO('null'))) print(json.load(StringIO('"abc\\u0064e"'))) diff --git a/tests/extmod/ujson_loads.py b/tests/extmod/ujson_loads.py index b2e18e3af..adba3c068 100644 --- a/tests/extmod/ujson_loads.py +++ b/tests/extmod/ujson_loads.py @@ -4,9 +4,8 @@ except ImportError: try: import json except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit def my_print(o): if isinstance(o, dict): diff --git a/tests/extmod/ujson_loads_float.py b/tests/extmod/ujson_loads_float.py index b20a412ff..f1b8cc364 100644 --- a/tests/extmod/ujson_loads_float.py +++ b/tests/extmod/ujson_loads_float.py @@ -4,9 +4,8 @@ except ImportError: try: import json except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit def my_print(o): print('%.3f' % o) diff --git a/tests/extmod/urandom_basic.py b/tests/extmod/urandom_basic.py index 885b8517f..57e6b26cb 100644 --- a/tests/extmod/urandom_basic.py +++ b/tests/extmod/urandom_basic.py @@ -4,9 +4,8 @@ except ImportError: try: import random except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit # check getrandbits returns a value within the bit range for b in (1, 2, 3, 4, 16, 32): diff --git a/tests/extmod/urandom_extra.py b/tests/extmod/urandom_extra.py index 925dd0dbc..f5a34e168 100644 --- a/tests/extmod/urandom_extra.py +++ b/tests/extmod/urandom_extra.py @@ -4,16 +4,14 @@ except ImportError: try: import random except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit try: random.randint except AttributeError: - import sys print('SKIP') - sys.exit() + raise SystemExit print('randrange') for i in range(50): diff --git a/tests/extmod/ure1.py b/tests/extmod/ure1.py index a867f1751..1f38b8087 100644 --- a/tests/extmod/ure1.py +++ b/tests/extmod/ure1.py @@ -4,9 +4,8 @@ except ImportError: try: import re except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit r = re.compile(".+") m = r.match("abc") diff --git a/tests/extmod/ure_debug.py b/tests/extmod/ure_debug.py index 252df21e3..cfb264bb6 100644 --- a/tests/extmod/ure_debug.py +++ b/tests/extmod/ure_debug.py @@ -2,8 +2,7 @@ try: import ure except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit ure.compile('^a|b[0-9]\w$', ure.DEBUG) diff --git a/tests/extmod/ure_error.py b/tests/extmod/ure_error.py index 3f16f9158..f52f735c7 100644 --- a/tests/extmod/ure_error.py +++ b/tests/extmod/ure_error.py @@ -6,9 +6,8 @@ except ImportError: try: import re except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit def test_re(r): try: diff --git a/tests/extmod/ure_group.py b/tests/extmod/ure_group.py index 98aae2a73..4e39468c5 100644 --- a/tests/extmod/ure_group.py +++ b/tests/extmod/ure_group.py @@ -6,9 +6,8 @@ except ImportError: try: import re except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit def print_groups(match): print('----') diff --git a/tests/extmod/ure_namedclass.py b/tests/extmod/ure_namedclass.py index e233f17c8..215d09613 100644 --- a/tests/extmod/ure_namedclass.py +++ b/tests/extmod/ure_namedclass.py @@ -6,9 +6,8 @@ except ImportError: try: import re except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit def print_groups(match): print('----') diff --git a/tests/extmod/ure_split.py b/tests/extmod/ure_split.py index 1e411c27c..317ca9892 100644 --- a/tests/extmod/ure_split.py +++ b/tests/extmod/ure_split.py @@ -4,9 +4,8 @@ except ImportError: try: import re except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit r = re.compile(" ") s = r.split("a b c foobar") diff --git a/tests/extmod/ure_split_empty.py b/tests/extmod/ure_split_empty.py index ad6334eba..76ce97ea6 100644 --- a/tests/extmod/ure_split_empty.py +++ b/tests/extmod/ure_split_empty.py @@ -7,9 +7,8 @@ try: import ure as re except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit r = re.compile(" *") s = r.split("a b c foobar") diff --git a/tests/extmod/ure_split_notimpl.py b/tests/extmod/ure_split_notimpl.py index eca3ea512..da6e9652d 100644 --- a/tests/extmod/ure_split_notimpl.py +++ b/tests/extmod/ure_split_notimpl.py @@ -1,9 +1,8 @@ try: import ure as re except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit r = re.compile('( )') try: diff --git a/tests/extmod/ussl_basic.py b/tests/extmod/ussl_basic.py index e9d435bca..9f8019a0b 100644 --- a/tests/extmod/ussl_basic.py +++ b/tests/extmod/ussl_basic.py @@ -5,8 +5,7 @@ try: import ussl as ssl except ImportError: print("SKIP") - import sys - sys.exit() + raise SystemExit # create in client mode try: diff --git a/tests/extmod/utimeq1.py b/tests/extmod/utimeq1.py index 68d69e25e..dc7f3b660 100644 --- a/tests/extmod/utimeq1.py +++ b/tests/extmod/utimeq1.py @@ -5,8 +5,7 @@ try: from utimeq import utimeq except ImportError: print("SKIP") - import sys - sys.exit() + raise SystemExit DEBUG = 0 diff --git a/tests/extmod/utimeq_stable.py b/tests/extmod/utimeq_stable.py index 9f6ba76d4..9fb522d51 100644 --- a/tests/extmod/utimeq_stable.py +++ b/tests/extmod/utimeq_stable.py @@ -2,8 +2,7 @@ try: from utimeq import utimeq except ImportError: print("SKIP") - import sys - sys.exit() + raise SystemExit h = utimeq(10) diff --git a/tests/extmod/uzlib_decompio.py b/tests/extmod/uzlib_decompio.py index 6f07c048c..112a82597 100644 --- a/tests/extmod/uzlib_decompio.py +++ b/tests/extmod/uzlib_decompio.py @@ -2,9 +2,8 @@ try: import uzlib as zlib import uio as io except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit # Raw DEFLATE bitstream diff --git a/tests/extmod/uzlib_decompio_gz.py b/tests/extmod/uzlib_decompio_gz.py index 7572e9693..02087f763 100644 --- a/tests/extmod/uzlib_decompio_gz.py +++ b/tests/extmod/uzlib_decompio_gz.py @@ -2,9 +2,8 @@ try: import uzlib as zlib import uio as io except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit # gzip bitstream diff --git a/tests/extmod/uzlib_decompress.py b/tests/extmod/uzlib_decompress.py index 10121ee7e..63247955c 100644 --- a/tests/extmod/uzlib_decompress.py +++ b/tests/extmod/uzlib_decompress.py @@ -4,9 +4,8 @@ except ImportError: try: import uzlib as zlib except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit PATTERNS = [ # Packed results produced by CPy's zlib.compress() diff --git a/tests/extmod/vfs_basic.py b/tests/extmod/vfs_basic.py index fc016b8d5..995874824 100644 --- a/tests/extmod/vfs_basic.py +++ b/tests/extmod/vfs_basic.py @@ -9,8 +9,7 @@ try: uos.mount except (ImportError, AttributeError): print("SKIP") - import sys - sys.exit() + raise SystemExit class Filesystem: diff --git a/tests/extmod/vfs_fat_fileio1.py b/tests/extmod/vfs_fat_fileio1.py index 9036df7a5..d19df120b 100644 --- a/tests/extmod/vfs_fat_fileio1.py +++ b/tests/extmod/vfs_fat_fileio1.py @@ -1,4 +1,3 @@ -import sys try: import uerrno try: @@ -8,13 +7,13 @@ try: import uos except ImportError: print("SKIP") - sys.exit() + raise SystemExit try: uos.VfsFat except AttributeError: print("SKIP") - sys.exit() + raise SystemExit class RAMFS: @@ -46,7 +45,7 @@ try: bdev = RAMFS(50) except MemoryError: print("SKIP") - sys.exit() + raise SystemExit uos.VfsFat.mkfs(bdev) vfs = uos.VfsFat(bdev) diff --git a/tests/extmod/vfs_fat_fileio2.py b/tests/extmod/vfs_fat_fileio2.py index b2a0ba70f..b5adb75c9 100644 --- a/tests/extmod/vfs_fat_fileio2.py +++ b/tests/extmod/vfs_fat_fileio2.py @@ -1,4 +1,3 @@ -import sys try: import uerrno try: @@ -8,13 +7,13 @@ try: import uos except ImportError: print("SKIP") - sys.exit() + raise SystemExit try: uos.VfsFat except AttributeError: print("SKIP") - sys.exit() + raise SystemExit class RAMFS: @@ -46,7 +45,7 @@ try: bdev = RAMFS(50) except MemoryError: print("SKIP") - sys.exit() + raise SystemExit uos.VfsFat.mkfs(bdev) vfs = uos.VfsFat(bdev) diff --git a/tests/extmod/vfs_fat_more.py b/tests/extmod/vfs_fat_more.py index dacb21553..baec96787 100644 --- a/tests/extmod/vfs_fat_more.py +++ b/tests/extmod/vfs_fat_more.py @@ -1,4 +1,3 @@ -import sys import uerrno try: try: @@ -8,13 +7,13 @@ try: import uos except ImportError: print("SKIP") - sys.exit() + raise SystemExit try: uos.VfsFat except AttributeError: print("SKIP") - sys.exit() + raise SystemExit class RAMFS: @@ -47,7 +46,7 @@ try: bdev2 = RAMFS(50) except MemoryError: print("SKIP") - sys.exit() + raise SystemExit # first we umount any existing mount points the target may have try: diff --git a/tests/extmod/vfs_fat_oldproto.py b/tests/extmod/vfs_fat_oldproto.py index 3e66758c3..ef4f1da78 100644 --- a/tests/extmod/vfs_fat_oldproto.py +++ b/tests/extmod/vfs_fat_oldproto.py @@ -1,4 +1,3 @@ -import sys try: import uerrno try: @@ -7,13 +6,13 @@ try: import uos except ImportError: print("SKIP") - sys.exit() + raise SystemExit try: uos.VfsFat except AttributeError: print("SKIP") - sys.exit() + raise SystemExit class RAMFS_OLD: @@ -43,7 +42,7 @@ try: bdev = RAMFS_OLD(50) except MemoryError: print("SKIP") - sys.exit() + raise SystemExit uos.VfsFat.mkfs(bdev) vfs = uos.VfsFat(bdev) diff --git a/tests/extmod/vfs_fat_ramdisk.py b/tests/extmod/vfs_fat_ramdisk.py index fe72a8bef..801c69786 100644 --- a/tests/extmod/vfs_fat_ramdisk.py +++ b/tests/extmod/vfs_fat_ramdisk.py @@ -1,4 +1,3 @@ -import sys try: import uerrno try: @@ -7,13 +6,13 @@ try: import uos except ImportError: print("SKIP") - sys.exit() + raise SystemExit try: uos.VfsFat except AttributeError: print("SKIP") - sys.exit() + raise SystemExit class RAMFS: @@ -45,7 +44,7 @@ try: bdev = RAMFS(50) except MemoryError: print("SKIP") - sys.exit() + raise SystemExit uos.VfsFat.mkfs(bdev) diff --git a/tests/extmod/websocket_basic.py b/tests/extmod/websocket_basic.py index 770836c8e..9a80503a0 100644 --- a/tests/extmod/websocket_basic.py +++ b/tests/extmod/websocket_basic.py @@ -3,9 +3,8 @@ try: import uerrno import websocket except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit # put raw data in the stream and do a websocket read def ws_read(msg, sz): diff --git a/tests/io/buffered_writer.py b/tests/io/buffered_writer.py index bb7b4e8db..c2cedb991 100644 --- a/tests/io/buffered_writer.py +++ b/tests/io/buffered_writer.py @@ -4,9 +4,8 @@ try: io.BytesIO io.BufferedWriter except AttributeError: - import sys print('SKIP') - sys.exit() + raise SystemExit bts = io.BytesIO() buf = io.BufferedWriter(bts, 8) diff --git a/tests/io/open_append.py b/tests/io/open_append.py index 2120b72f0..a696823bc 100644 --- a/tests/io/open_append.py +++ b/tests/io/open_append.py @@ -1,4 +1,3 @@ -import sys try: import uos as os except ImportError: @@ -6,7 +5,7 @@ except ImportError: if not hasattr(os, "unlink"): print("SKIP") - sys.exit() + raise SystemExit # cleanup in case testfile exists try: diff --git a/tests/io/open_plus.py b/tests/io/open_plus.py index 98598ee67..bba96fa2f 100644 --- a/tests/io/open_plus.py +++ b/tests/io/open_plus.py @@ -1,4 +1,3 @@ -import sys try: import uos as os except ImportError: @@ -6,7 +5,7 @@ except ImportError: if not hasattr(os, "unlink"): print("SKIP") - sys.exit() + raise SystemExit # cleanup in case testfile exists try: diff --git a/tests/io/resource_stream.py b/tests/io/resource_stream.py index 86975f118..37d985bf1 100644 --- a/tests/io/resource_stream.py +++ b/tests/io/resource_stream.py @@ -5,7 +5,7 @@ try: uio.resource_stream except AttributeError: print('SKIP') - sys.exit() + raise SystemExit buf = uio.resource_stream("data", "file2") print(buf.read()) diff --git a/tests/io/write_ext.py b/tests/io/write_ext.py index 19b616174..5a6eaa35c 100644 --- a/tests/io/write_ext.py +++ b/tests/io/write_ext.py @@ -5,9 +5,8 @@ import uio try: uio.BytesIO except AttributeError: - import sys print('SKIP') - sys.exit() + raise SystemExit buf = uio.BytesIO() diff --git a/tests/jni/list.py b/tests/jni/list.py index 6725abb5a..d58181d0b 100644 --- a/tests/jni/list.py +++ b/tests/jni/list.py @@ -1,10 +1,9 @@ -import sys import jni try: ArrayList = jni.cls("java/util/ArrayList") except: print("SKIP") - sys.exit() + raise SystemExit l = ArrayList() print(l) diff --git a/tests/jni/object.py b/tests/jni/object.py index 6cf936c4d..aa67615ec 100644 --- a/tests/jni/object.py +++ b/tests/jni/object.py @@ -1,10 +1,9 @@ -import sys import jni try: Integer = jni.cls("java/lang/Integer") except: print("SKIP") - sys.exit() + raise SystemExit # Create object i = Integer(42) diff --git a/tests/jni/system_out.py b/tests/jni/system_out.py index 7a1f18030..86c4b9e11 100644 --- a/tests/jni/system_out.py +++ b/tests/jni/system_out.py @@ -1,9 +1,8 @@ -import sys try: import jni System = jni.cls("java/lang/System") except: print("SKIP") - sys.exit() + raise SystemExit System.out.println("Hello, Java!") diff --git a/tests/micropython/heapalloc_bytesio.py b/tests/micropython/heapalloc_bytesio.py index 2a8d50abe..4aae2abf0 100644 --- a/tests/micropython/heapalloc_bytesio.py +++ b/tests/micropython/heapalloc_bytesio.py @@ -1,9 +1,8 @@ try: import uio except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit import micropython diff --git a/tests/micropython/heapalloc_iter.py b/tests/micropython/heapalloc_iter.py index 45d3519e4..79461f999 100644 --- a/tests/micropython/heapalloc_iter.py +++ b/tests/micropython/heapalloc_iter.py @@ -2,9 +2,8 @@ try: import array except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit try: from micropython import heap_lock, heap_unlock diff --git a/tests/micropython/heapalloc_traceback.py b/tests/micropython/heapalloc_traceback.py index b3795293f..f4212b6ce 100644 --- a/tests/micropython/heapalloc_traceback.py +++ b/tests/micropython/heapalloc_traceback.py @@ -5,9 +5,8 @@ import sys try: import uio except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit # preallocate exception instance with some room for a traceback global_exc = StopIteration() diff --git a/tests/micropython/heapalloc_traceback.py.exp b/tests/micropython/heapalloc_traceback.py.exp index facd0af13..291bbd697 100644 --- a/tests/micropython/heapalloc_traceback.py.exp +++ b/tests/micropython/heapalloc_traceback.py.exp @@ -1,5 +1,5 @@ StopIteration Traceback (most recent call last): - File , line 23, in test + File , line 22, in test StopIteration: diff --git a/tests/micropython/kbd_intr.py b/tests/micropython/kbd_intr.py index a7ce7464b..879c9a229 100644 --- a/tests/micropython/kbd_intr.py +++ b/tests/micropython/kbd_intr.py @@ -6,8 +6,7 @@ try: micropython.kbd_intr except AttributeError: print('SKIP') - import sys - sys.exit() + raise SystemExit # just check we can actually call it micropython.kbd_intr(3) diff --git a/tests/micropython/schedule.py b/tests/micropython/schedule.py index 3d584eea4..74f90cb2d 100644 --- a/tests/micropython/schedule.py +++ b/tests/micropython/schedule.py @@ -6,8 +6,7 @@ try: micropython.schedule except AttributeError: print('SKIP') - import sys - sys.exit() + raise SystemExit # Basic test of scheduling a function. diff --git a/tests/misc/non_compliant.py b/tests/misc/non_compliant.py index 31074ab01..b4c90e9fc 100644 --- a/tests/misc/non_compliant.py +++ b/tests/misc/non_compliant.py @@ -4,9 +4,8 @@ try: import array import ustruct except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit # when super can't find self try: diff --git a/tests/misc/print_exception.py b/tests/misc/print_exception.py index b833a7981..9ab8e728b 100644 --- a/tests/misc/print_exception.py +++ b/tests/misc/print_exception.py @@ -6,7 +6,7 @@ try: import io except ImportError: print("SKIP") - sys.exit() + raise SystemExit if hasattr(sys, 'print_exception'): print_exception = sys.print_exception diff --git a/tests/misc/recursive_data.py b/tests/misc/recursive_data.py index 383018945..3b7fa5095 100644 --- a/tests/misc/recursive_data.py +++ b/tests/misc/recursive_data.py @@ -2,9 +2,8 @@ try: import uio as io except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit l = [1, 2, 3, None] l[-1] = l diff --git a/tests/misc/recursive_iternext.py b/tests/misc/recursive_iternext.py index d90f17716..edb5a843f 100644 --- a/tests/misc/recursive_iternext.py +++ b/tests/misc/recursive_iternext.py @@ -6,9 +6,8 @@ try: max zip except: - import sys print("SKIP") - sys.exit() + raise SystemExit # We need to pick an N that is large enough to hit the recursion # limit, but not too large that we run out of heap memory. diff --git a/tests/misc/sys_exc_info.py b/tests/misc/sys_exc_info.py index de5b82562..4bb2c61e8 100644 --- a/tests/misc/sys_exc_info.py +++ b/tests/misc/sys_exc_info.py @@ -3,7 +3,7 @@ try: sys.exc_info except: print("SKIP") - sys.exit() + raise SystemExit def f(): print(sys.exc_info()[0:2]) diff --git a/tests/pyb/can.py b/tests/pyb/can.py index 7f2d070ec..0fd8c8368 100644 --- a/tests/pyb/can.py +++ b/tests/pyb/can.py @@ -2,8 +2,7 @@ try: from pyb import CAN except ImportError: print('SKIP') - import sys - sys.exit() + raise SystemExit import pyb diff --git a/tests/pyb/dac.py b/tests/pyb/dac.py index 942f30354..6f03bbc64 100644 --- a/tests/pyb/dac.py +++ b/tests/pyb/dac.py @@ -2,8 +2,7 @@ import pyb if not hasattr(pyb, 'DAC'): print('SKIP') - import sys - sys.exit() + raise SystemExit dac = pyb.DAC(1) print(dac) diff --git a/tests/pyb/pyb_f405.py b/tests/pyb/pyb_f405.py index 3c81fe109..2f161ae09 100644 --- a/tests/pyb/pyb_f405.py +++ b/tests/pyb/pyb_f405.py @@ -4,8 +4,7 @@ import os, pyb if not 'STM32F405' in os.uname().machine: print('SKIP') - import sys - sys.exit() + raise SystemExit print(pyb.freq()) print(type(pyb.rng())) diff --git a/tests/pyb/pyb_f411.py b/tests/pyb/pyb_f411.py index 328653965..50de30282 100644 --- a/tests/pyb/pyb_f411.py +++ b/tests/pyb/pyb_f411.py @@ -4,7 +4,6 @@ import os, pyb if not 'STM32F411' in os.uname().machine: print('SKIP') - import sys - sys.exit() + raise SystemExit print(pyb.freq()) diff --git a/tests/unix/extra_coverage.py b/tests/unix/extra_coverage.py index 870e7d5f2..7a496aa87 100644 --- a/tests/unix/extra_coverage.py +++ b/tests/unix/extra_coverage.py @@ -2,8 +2,7 @@ try: extra_coverage except NameError: print("SKIP") - import sys - sys.exit() + raise SystemExit import uerrno import uio diff --git a/tests/unix/ffi_callback.py b/tests/unix/ffi_callback.py index 7f8af15b3..23b058bce 100644 --- a/tests/unix/ffi_callback.py +++ b/tests/unix/ffi_callback.py @@ -1,9 +1,8 @@ -import sys try: import ffi except ImportError: print("SKIP") - sys.exit() + raise SystemExit def ffi_open(names): diff --git a/tests/unix/ffi_float.py b/tests/unix/ffi_float.py index cc12fa7ad..c92a39bcd 100644 --- a/tests/unix/ffi_float.py +++ b/tests/unix/ffi_float.py @@ -1,10 +1,9 @@ # test ffi float support -import sys try: import ffi except ImportError: print("SKIP") - sys.exit() + raise SystemExit def ffi_open(names): diff --git a/tests/unix/ffi_float2.py b/tests/unix/ffi_float2.py index d635a2714..721eb4d19 100644 --- a/tests/unix/ffi_float2.py +++ b/tests/unix/ffi_float2.py @@ -1,10 +1,9 @@ # test ffi float support -import sys try: import ffi except ImportError: print("SKIP") - sys.exit() + raise SystemExit def ffi_open(names): @@ -25,7 +24,7 @@ try: tgammaf = libm.func('f', 'tgammaf', 'f') except OSError: print("SKIP") - sys.exit() + raise SystemExit for fun in (tgammaf,): for val in (0.5, 1, 1.0, 1.5, 4, 4.0): -- cgit v1.2.3