diff options
Diffstat (limited to 'tests')
34 files changed, 383 insertions, 38 deletions
diff --git a/tests/basics/array1.py b/tests/basics/array1.py index e5ea6683c..c45b883c9 100644 --- a/tests/basics/array1.py +++ b/tests/basics/array1.py @@ -21,6 +21,10 @@ print(array.array('i')) print(bool(array.array('i'))) print(bool(array.array('i', [1]))) +# containment, with incorrect type +print('12' in array.array('B', b'12')) +print([] in array.array('B', b'12')) + # bad typecode try: array.array('X') diff --git a/tests/basics/async_def.py b/tests/basics/async_def.py new file mode 100644 index 000000000..e345703d7 --- /dev/null +++ b/tests/basics/async_def.py @@ -0,0 +1,16 @@ +# test async def + +def dec(f): + print('decorator') + return f + +# test definition with a decorator +@dec +async def foo(): + print('foo') + +coro = foo() +try: + coro.send(None) +except StopIteration: + print('StopIteration') diff --git a/tests/basics/async_def.py.exp b/tests/basics/async_def.py.exp new file mode 100644 index 000000000..f555ace99 --- /dev/null +++ b/tests/basics/async_def.py.exp @@ -0,0 +1,3 @@ +decorator +foo +StopIteration diff --git a/tests/basics/async_with.py b/tests/basics/async_with.py index 9eccfd816..5af0c5d95 100644 --- a/tests/basics/async_with.py +++ b/tests/basics/async_with.py @@ -3,6 +3,7 @@ class AContext: async def __aenter__(self): print('enter') + return 1 async def __aexit__(self, exc_type, exc, tb): print('exit', exc_type, exc) @@ -17,7 +18,8 @@ except StopIteration: print('finished') async def g(): - async with AContext(): + async with AContext() as ac: + print(ac) raise ValueError('error') o = g() diff --git a/tests/basics/async_with.py.exp b/tests/basics/async_with.py.exp index 6072a3e0b..d00b18c96 100644 --- a/tests/basics/async_with.py.exp +++ b/tests/basics/async_with.py.exp @@ -3,5 +3,6 @@ body exit None None finished enter +1 exit <class 'ValueError'> error ValueError diff --git a/tests/basics/builtin_range.py b/tests/basics/builtin_range.py index 9110cf12c..59fc0344a 100644 --- a/tests/basics/builtin_range.py +++ b/tests/basics/builtin_range.py @@ -50,3 +50,9 @@ 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/del_global.py b/tests/basics/del_global.py index 77d11cb3c..d740357b0 100644 --- a/tests/basics/del_global.py +++ b/tests/basics/del_global.py @@ -54,3 +54,8 @@ try: print(c) except NameError: print("NameError") + +a = 1 +b = 2 +c = 3 +del (a, (b, c)) diff --git a/tests/basics/dict1.py b/tests/basics/dict1.py index c70ca588a..20fa9def3 100644 --- a/tests/basics/dict1.py +++ b/tests/basics/dict1.py @@ -16,3 +16,27 @@ while x < 100: d[x] = x x += 1 print(d[50]) + +# equality operator on dicts of different size +print({} == {1:1}) + +# equality operator on dicts of same size but with different keys +print({1:1} == {2:1}) + +# value not found +try: + {}[0] +except KeyError as er: + print('KeyError', er, repr(er), er.args) + +# unsupported unary op +try: + +{} +except TypeError: + print('TypeError') + +# unsupported binary op +try: + {} + {} +except TypeError: + print('TypeError') diff --git a/tests/basics/dict_views.py b/tests/basics/dict_views.py index fbf63fa0a..7ebcc1f56 100644 --- a/tests/basics/dict_views.py +++ b/tests/basics/dict_views.py @@ -3,4 +3,19 @@ for m in d.items, d.values, d.keys: print(m()) print(list(m())) +# print a view with more than one item +print({1:1, 2:1}.values()) + +# unsupported binary op on a dict values view +try: + {1:1}.values() + 1 +except TypeError: + print('TypeError') + +# unsupported binary op on a dict keys view +try: + {1:1}.keys() + 1 +except TypeError: + print('TypeError') + # set operations still to come diff --git a/tests/basics/for_range.py b/tests/basics/for_range.py index ddff5ebd4..58a8f7caa 100644 --- a/tests/basics/for_range.py +++ b/tests/basics/for_range.py @@ -35,6 +35,11 @@ try: except TypeError: print('TypeError') try: + for x in range(start=0, end=1): + print(x) +except TypeError: + print('TypeError') +try: for x in range(0, 1, step=1): print(x) except TypeError: diff --git a/tests/basics/int_constfolding.py b/tests/basics/int_constfolding.py index c01f964da..aa38fa6b8 100644 --- a/tests/basics/int_constfolding.py +++ b/tests/basics/int_constfolding.py @@ -38,3 +38,8 @@ 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/slice_attrs.py b/tests/basics/slice_attrs.py index 76368a78c..67456ff8e 100644 --- a/tests/basics/slice_attrs.py +++ b/tests/basics/slice_attrs.py @@ -14,3 +14,12 @@ except: A()[1:2:3] + +# test storing to attr (shouldn't be allowed) +class B: + def __getitem__(self, idx): + try: + idx.start = 0 + except AttributeError: + print('AttributeError') +B()[:] diff --git a/tests/basics/syntaxerror.py b/tests/basics/syntaxerror.py index 2ae0183f8..e5cbbac06 100644 --- a/tests/basics/syntaxerror.py +++ b/tests/basics/syntaxerror.py @@ -49,6 +49,9 @@ 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") + # can't have multiple *x on LHS test_syntax("*a, *b = c") @@ -76,6 +79,7 @@ test_syntax("continue") test_syntax("return") test_syntax("yield") test_syntax("nonlocal a") +test_syntax("await 1") # error on uPy, warning on CPy #test_syntax("def f():\n a = 1\n global a") diff --git a/tests/basics/unpack1.py b/tests/basics/unpack1.py index 10e01dea0..0e8ec592c 100644 --- a/tests/basics/unpack1.py +++ b/tests/basics/unpack1.py @@ -12,6 +12,7 @@ a, b, c = range(3); print(a, b, c) (a,) = range(1); print(a) (a, b) = range(2); print(a, b) (a, b, c) = range(3); print(a, b, c) +(a, (b, c)) = [-1, range(2)]; print(a, b, c) # lists diff --git a/tests/cmdline/cmd_showbc.py b/tests/cmdline/cmd_showbc.py index 9989a7229..2f4e953bb 100644 --- a/tests/cmdline/cmd_showbc.py +++ b/tests/cmdline/cmd_showbc.py @@ -34,12 +34,14 @@ def f(): # subscript p = b[0] b[0] = p + b[0] += p # slice a = b[::] # sequenc unpacking a, b = c + a, *a = a # tuple swapping a, b = b, a @@ -79,6 +81,7 @@ def f(): b while not a: b + a = a or a # for loop for a in b: @@ -92,6 +95,11 @@ def f(): b finally: c + while a: + try: + break + except: + pass # with with a: @@ -117,6 +125,12 @@ def f(): return return 1 +# function with lots of locals +def f(): + l1 = l2 = l3 = l4 = l5 = l6 = l7 = l8 = l9 = l10 = 1 + m1 = m2 = m3 = m4 = m5 = m6 = m7 = m8 = m9 = m10 = 2 + l10 + m10 + # functions with default args def f(a=1): pass @@ -133,3 +147,6 @@ def f(): # class class Class: pass + +# delete name +del Class diff --git a/tests/cmdline/cmd_showbc.py.exp b/tests/cmdline/cmd_showbc.py.exp index 0e5c55942..1f0c054cf 100644 --- a/tests/cmdline/cmd_showbc.py.exp +++ b/tests/cmdline/cmd_showbc.py.exp @@ -7,9 +7,11 @@ arg names: (N_EXC_STACK 0) bc=-1 line=1 ######## - bc=\\d\+ line=134 + bc=\\d\+ line=152 00 MAKE_FUNCTION \.\+ \\d\+ STORE_NAME f +\\d\+ MAKE_FUNCTION \.\+ +\\d\+ STORE_NAME f \\d\+ LOAD_CONST_SMALL_INT 1 \\d\+ BUILD_TUPLE 1 \\d\+ LOAD_NULL @@ -22,6 +24,7 @@ arg names: \\d\+ LOAD_CONST_STRING 'Class' \\d\+ CALL_FUNCTION n=2 nkw=0 \\d\+ STORE_NAME Class +\\d\+ DELETE_NAME Class \\d\+ LOAD_CONST_NONE \\d\+ RETURN_VALUE File cmdline/cmd_showbc.py, code block 'f' (descriptor: \.\+, bytecode @\.\+ bytes) @@ -35,7 +38,7 @@ Raw bytecode (code_info_size=\\d\+, bytecode_size=\\d\+): (INIT_CELL 16) bc=-4 line=1 ######## - bc=\\d\+ line=118 + bc=\\d\+ line=126 00 LOAD_CONST_NONE 01 LOAD_CONST_FALSE 02 BINARY_OP 5 __add__ @@ -123,6 +126,14 @@ Raw bytecode (code_info_size=\\d\+, bytecode_size=\\d\+): \\d\+ LOAD_CONST_SMALL_INT 0 \\d\+ STORE_SUBSCR \\d\+ LOAD_DEREF 14 +\\d\+ LOAD_CONST_SMALL_INT 0 +\\d\+ DUP_TOP_TWO +\\d\+ LOAD_SUBSCR +\\d\+ LOAD_FAST 12 +\\d\+ BINARY_OP 18 __iadd__ +\\d\+ ROT_THREE +\\d\+ STORE_SUBSCR +\\d\+ LOAD_DEREF 14 \\d\+ LOAD_CONST_NONE \\d\+ LOAD_CONST_NONE \\d\+ BUILD_SLICE 2 @@ -132,6 +143,10 @@ Raw bytecode (code_info_size=\\d\+, bytecode_size=\\d\+): \\d\+ UNPACK_SEQUENCE 2 \\d\+ STORE_FAST 0 \\d\+ STORE_DEREF 14 +\\d\+ LOAD_FAST 0 +\\d\+ UNPACK_EX 1 +\\d\+ STORE_FAST 0 +\\d\+ STORE_FAST 0 \\d\+ LOAD_DEREF 14 \\d\+ LOAD_FAST 0 \\d\+ ROT_TWO @@ -225,6 +240,10 @@ Raw bytecode (code_info_size=\\d\+, bytecode_size=\\d\+): \\d\+ POP_TOP \\d\+ LOAD_FAST 0 \\d\+ POP_JUMP_IF_FALSE \\d\+ +\\d\+ LOAD_FAST 0 +\\d\+ JUMP_IF_TRUE_OR_POP \\d\+ +\\d\+ LOAD_FAST 0 +\\d\+ STORE_FAST 0 \\d\+ LOAD_DEREF 14 \\d\+ GET_ITER \\d\+ FOR_ITER \\d\+ @@ -251,6 +270,17 @@ Raw bytecode (code_info_size=\\d\+, bytecode_size=\\d\+): \\d\+ LOAD_FAST 1 \\d\+ POP_TOP \\d\+ END_FINALLY +\\d\+ JUMP \\d\+ +\\d\+ SETUP_EXCEPT \\d\+ +\\d\+ UNWIND_JUMP \\d\+ 1 +\\d\+ POP_BLOCK +\\d\+ JUMP \\d\+ +\\d\+ POP_TOP +\\d\+ POP_EXCEPT +\\d\+ JUMP \\d\+ +\\d\+ END_FINALLY +\\d\+ LOAD_FAST 0 +\\d\+ POP_JUMP_IF_TRUE \\d\+ \\d\+ LOAD_FAST 0 \\d\+ SETUP_WITH \\d\+ \\d\+ POP_TOP @@ -291,13 +321,68 @@ Raw bytecode (code_info_size=\\d\+, bytecode_size=\\d\+): File cmdline/cmd_showbc.py, code block 'f' (descriptor: \.\+, bytecode @\.\+ bytes) Raw bytecode (code_info_size=\\d\+, bytecode_size=\\d\+): ######## +\.\+rg names: +(N_STATE 22) +(N_EXC_STACK 0) + bc=-1 line=1 +######## + bc=\\d\+ line=132 +00 LOAD_CONST_SMALL_INT 1 +01 DUP_TOP +02 STORE_FAST 0 +03 DUP_TOP +04 STORE_FAST 1 +05 DUP_TOP +06 STORE_FAST 2 +07 DUP_TOP +08 STORE_FAST 3 +09 DUP_TOP +10 STORE_FAST 4 +11 DUP_TOP +12 STORE_FAST 5 +13 DUP_TOP +14 STORE_FAST 6 +15 DUP_TOP +16 STORE_FAST 7 +17 DUP_TOP +18 STORE_FAST 8 +19 STORE_FAST 9 +20 LOAD_CONST_SMALL_INT 2 +21 DUP_TOP +22 STORE_FAST 10 +23 DUP_TOP +24 STORE_FAST 11 +25 DUP_TOP +26 STORE_FAST 12 +27 DUP_TOP +28 STORE_FAST 13 +29 DUP_TOP +30 STORE_FAST 14 +31 DUP_TOP +32 STORE_FAST 15 +33 DUP_TOP +34 STORE_FAST_N 16 +36 DUP_TOP +37 STORE_FAST_N 17 +39 DUP_TOP +40 STORE_FAST_N 18 +42 STORE_FAST_N 19 +44 LOAD_FAST 9 +45 LOAD_FAST_N 19 +47 BINARY_OP 5 __add__ +48 POP_TOP +49 LOAD_CONST_NONE +50 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: a (N_STATE 5) (N_EXC_STACK 0) (INIT_CELL 0) ######## - bc=\\d\+ line=124 + bc=\\d\+ line=138 00 LOAD_CONST_SMALL_INT 2 01 BUILD_TUPLE 1 03 LOAD_NULL @@ -314,9 +399,9 @@ arg names: (N_STATE 2) (N_EXC_STACK 0) bc=-1 line=1 - bc=0 line=129 - bc=3 line=130 - bc=6 line=131 + bc=0 line=143 + bc=3 line=144 + bc=6 line=145 00 LOAD_CONST_NONE 01 YIELD_VALUE 02 POP_TOP @@ -338,7 +423,7 @@ arg names: (N_STATE 1) (N_EXC_STACK 0) bc=-1 line=1 - bc=13 line=135 + bc=13 line=149 00 LOAD_NAME __name__ (cache=0) 04 STORE_NAME __module__ 07 LOAD_CONST_STRING 'Class' @@ -411,7 +496,7 @@ arg names: * (N_EXC_STACK 0) bc=-\\d\+ line=1 ######## - bc=\\d\+ line=105 + bc=\\d\+ line=113 00 LOAD_DEREF 0 02 LOAD_CONST_SMALL_INT 1 03 BINARY_OP 5 __add__ @@ -430,7 +515,7 @@ arg names: * b (N_EXC_STACK 0) bc=-\\d\+ line=1 ######## - bc=\\d\+ line=125 + bc=\\d\+ line=139 00 LOAD_FAST 1 01 LOAD_DEREF 0 03 BINARY_OP 5 __add__ diff --git a/tests/cmdline/repl_basic.py b/tests/cmdline/repl_basic.py index b416493dc..cbd5d3a4a 100644 --- a/tests/cmdline/repl_basic.py +++ b/tests/cmdline/repl_basic.py @@ -1,3 +1,4 @@ # basic REPL tests print(1) [A +2 diff --git a/tests/cmdline/repl_basic.py.exp b/tests/cmdline/repl_basic.py.exp index 96b8c28dc..2b390ea98 100644 --- a/tests/cmdline/repl_basic.py.exp +++ b/tests/cmdline/repl_basic.py.exp @@ -5,4 +5,6 @@ Use \.\+ 1 >>> print(1) 1 +>>> 2 +2 >>> diff --git a/tests/extmod/ujson_load.py b/tests/extmod/ujson_load.py new file mode 100644 index 000000000..bf484a207 --- /dev/null +++ b/tests/extmod/ujson_load.py @@ -0,0 +1,11 @@ +try: + from uio import StringIO + import ujson as json +except: + from io import StringIO + import json + +print(json.load(StringIO('null'))) +print(json.load(StringIO('"abc\\u0064e"'))) +print(json.load(StringIO('[false, true, 1, -2]'))) +print(json.load(StringIO('{"a":true}'))) diff --git a/tests/extmod/vfs_fat_ramdisk.py b/tests/extmod/vfs_fat_ramdisk.py index f470dbcfe..6380761c6 100644 --- a/tests/extmod/vfs_fat_ramdisk.py +++ b/tests/extmod/vfs_fat_ramdisk.py @@ -41,8 +41,8 @@ except MemoryError: uos.VfsFat.mkfs(bdev) -assert b"FOO_FILETXT" not in bdev.data -assert b"hello!" not in bdev.data +print(b"FOO_FILETXT" not in bdev.data) +print(b"hello!" not in bdev.data) vfs = uos.VfsFat(bdev, "/ramdisk") print("statvfs:", vfs.statvfs("/ramdisk")) @@ -57,44 +57,66 @@ f2 = vfs.open("foo_file.txt") print(f2.read()) f2.close() -assert b"FOO_FILETXT" in bdev.data -assert b"hello!" in bdev.data +print(b"FOO_FILETXT" in bdev.data) +print(b"hello!" in bdev.data) -assert vfs.listdir() == ['foo_file.txt'] +print(vfs.listdir()) + +try: + vfs.rmdir("foo_file.txt") +except OSError as e: + print(e.args[0] == 20) # uerrno.ENOTDIR vfs.remove('foo_file.txt') -assert vfs.listdir() == [] +print(vfs.listdir()) vfs.mkdir("foo_dir") -assert vfs.listdir() == ['foo_dir'] +print(vfs.listdir()) + +try: + vfs.remove("foo_dir") +except OSError as e: + print(e.args[0] == uerrno.EISDIR) + f = vfs.open("foo_dir/file-in-dir.txt", "w") f.write("data in file") f.close() -assert vfs.listdir("foo_dir") == ['file-in-dir.txt'] +print(vfs.listdir("foo_dir")) vfs.rename("foo_dir/file-in-dir.txt", "moved-to-root.txt") -assert vfs.listdir() == ['foo_dir', 'moved-to-root.txt'] +print(vfs.listdir()) vfs.chdir("foo_dir") print("getcwd:", vfs.getcwd()) -assert vfs.listdir() == [] +print(vfs.listdir()) with vfs.open("sub_file.txt", "w") as f: f.write("test2") -assert vfs.listdir() == ["sub_file.txt"] +print(vfs.listdir()) + +try: + vfs.chdir("sub_file.txt") +except OSError as e: + print(e.args[0] == uerrno.ENOENT) vfs.chdir("..") print("getcwd:", vfs.getcwd()) +try: + vfs.rmdir("foo_dir") +except OSError as e: + print(e.args[0] == uerrno.EACCES) + +vfs.remove("foo_dir/sub_file.txt") +vfs.rmdir("foo_dir") +print(vfs.listdir()) vfs.umount() try: vfs.listdir() except OSError as e: - assert e.args[0] == uerrno.ENODEV -else: - raise AssertionError("expected OSError not thrown") + print(e.args[0] == uerrno.ENODEV) vfs = uos.VfsFat(bdev, "/ramdisk") -assert vfs.listdir() == ['foo_dir', 'moved-to-root.txt'] +print(vfs.listdir()) diff --git a/tests/extmod/vfs_fat_ramdisk.py.exp b/tests/extmod/vfs_fat_ramdisk.py.exp index fd893b6e4..8a498b2fc 100644 --- a/tests/extmod/vfs_fat_ramdisk.py.exp +++ b/tests/extmod/vfs_fat_ramdisk.py.exp @@ -1,5 +1,23 @@ +True +True statvfs: (512, 512, 14, 14, 14, 0, 0, 0, 0, 255) getcwd: /ramdisk hello! +True +True +['foo_file.txt'] +True +[] +['foo_dir'] +True +['file-in-dir.txt'] +['foo_dir', 'moved-to-root.txt'] getcwd: /ramdisk/foo_dir +[] +['sub_file.txt'] +True getcwd: /ramdisk +True +['moved-to-root.txt'] +True +['moved-to-root.txt'] diff --git a/tests/import/import2a.py b/tests/import/import2a.py index ce32b10b1..def6aeb6a 100644 --- a/tests/import/import2a.py +++ b/tests/import/import2a.py @@ -1,2 +1,5 @@ from import1b import var print(var) + +from import1b import var as var2 +print(var2) diff --git a/tests/micropython/emg_exc.py b/tests/micropython/emg_exc.py new file mode 100644 index 000000000..d228e6faa --- /dev/null +++ b/tests/micropython/emg_exc.py @@ -0,0 +1,20 @@ +# test that emergency exceptions work + +import micropython +import sys + +# some ports need to allocate heap for the emg exc +try: + micropython.alloc_emergency_exception_buf(256) +except AttributeError: + pass + +def f(): + micropython.heap_lock() + try: + raise ValueError(1) + except ValueError as er: + sys.print_exception(er) + micropython.heap_unlock() + +f() diff --git a/tests/micropython/emg_exc.py.exp b/tests/micropython/emg_exc.py.exp new file mode 100644 index 000000000..82b10b5f5 --- /dev/null +++ b/tests/micropython/emg_exc.py.exp @@ -0,0 +1 @@ +ValueError: diff --git a/tests/micropython/heap_lock.py b/tests/micropython/heap_lock.py new file mode 100644 index 000000000..0f0a70eff --- /dev/null +++ b/tests/micropython/heap_lock.py @@ -0,0 +1,14 @@ +# check that heap_lock/heap_unlock work as expected + +import micropython + +micropython.heap_lock() + +try: + print([]) +except MemoryError: + print('MemoryError') + +micropython.heap_unlock() + +print([]) diff --git a/tests/micropython/heap_lock.py.exp b/tests/micropython/heap_lock.py.exp new file mode 100644 index 000000000..67b208cfc --- /dev/null +++ b/tests/micropython/heap_lock.py.exp @@ -0,0 +1,2 @@ +MemoryError +[] diff --git a/tests/micropython/heapalloc.py b/tests/micropython/heapalloc.py index 2dc7fa5e7..a651158ca 100644 --- a/tests/micropython/heapalloc.py +++ b/tests/micropython/heapalloc.py @@ -1,6 +1,6 @@ # check that we can do certain things without allocating heap memory -import gc +import micropython def f1(a): print(a) @@ -28,12 +28,7 @@ def test(): f2(i, i) # 2 args f3(1, 2, 3, 4) # function with lots of local state -# call h with heap allocation disabled and all memory used up -gc.disable() -try: - while True: - 'a'.lower # allocates 1 cell for boundmeth -except MemoryError: - pass +# call test() with heap allocation disabled +micropython.heap_lock() test() -gc.enable() +micropython.heap_unlock() diff --git a/tests/micropython/opt_level.py b/tests/micropython/opt_level.py new file mode 100644 index 000000000..4e2f2f4ea --- /dev/null +++ b/tests/micropython/opt_level.py @@ -0,0 +1,14 @@ +import micropython as micropython + +# check we can get and set the level +micropython.opt_level(0) +print(micropython.opt_level()) +micropython.opt_level(1) +print(micropython.opt_level()) + +# check that the optimisation levels actually differ +micropython.opt_level(0) +exec('print(__debug__)') +micropython.opt_level(1) +exec('print(__debug__)') +exec('assert 0') diff --git a/tests/micropython/opt_level.py.exp b/tests/micropython/opt_level.py.exp new file mode 100644 index 000000000..74b3dd74e --- /dev/null +++ b/tests/micropython/opt_level.py.exp @@ -0,0 +1,4 @@ +0 +1 +True +False diff --git a/tests/micropython/viper_args.py b/tests/micropython/viper_args.py index ca2a5e670..2aebe1b04 100644 --- a/tests/micropython/viper_args.py +++ b/tests/micropython/viper_args.py @@ -26,3 +26,11 @@ def f4(x1:int, x2:int, x3:int, x4:int): f4(1, 2, 3, 4) # only up to 4 arguments currently supported + +# test compiling *x, **x, * args (currently unsupported at runtime) +@micropython.viper +def f(*x, **y): + pass +@micropython.viper +def f(*): + pass diff --git a/tests/misc/non_compliant.py b/tests/misc/non_compliant.py index 1157ff8b2..677438b83 100644 --- a/tests/misc/non_compliant.py +++ b/tests/misc/non_compliant.py @@ -3,6 +3,18 @@ import array import ustruct +# when super can't find self +try: + exec('def f(): super()') +except SyntaxError: + print('SyntaxError') + +# store to exception attribute is not allowed +try: + ValueError().x = 0 +except AttributeError: + print('AttributeError') + # array deletion not implemented try: a = array.array('b', (1, 2, 3)) @@ -17,6 +29,12 @@ try: except NotImplementedError: print('NotImplementedError') +# containment, looking for integer not implemented +try: + print(1 in array.array('B', b'12')) +except NotImplementedError: + print('NotImplementedError') + # should raise type error try: print(set('12') >= '1') @@ -59,6 +77,12 @@ try: except NotImplementedError: print('NotImplementedError') +# str subscr with step!=1 not implemented +try: + print('abc'[1:2:3]) +except NotImplementedError: + print('NotImplementedError') + # bytes(...) with keywords not implemented try: bytes('abc', encoding='utf8') diff --git a/tests/misc/non_compliant.py.exp b/tests/misc/non_compliant.py.exp index c03580442..737650e9e 100644 --- a/tests/misc/non_compliant.py.exp +++ b/tests/misc/non_compliant.py.exp @@ -1,5 +1,8 @@ +SyntaxError +AttributeError TypeError NotImplementedError +NotImplementedError True True TypeError, ValueError @@ -12,5 +15,6 @@ NotImplementedError NotImplementedError NotImplementedError NotImplementedError +NotImplementedError b'\x01\x02' b'\x01\x00' diff --git a/tests/run-tests b/tests/run-tests index cb920c094..4ac7d8e28 100755 --- a/tests/run-tests +++ b/tests/run-tests @@ -237,7 +237,6 @@ def run_tests(pyb, tests, args): skip_tests.add('float/float_divmod.py') # tested by float/float_divmod_relaxed.py instead skip_tests.add('float/float2int_doubleprec.py') # requires double precision floating point to work skip_tests.add('micropython/meminfo.py') # output is very different to PC output - skip_tests.add('extmod/machine1.py') # raw memory access not supported skip_tests.add('extmod/machine_mem.py') # raw memory access not supported if args.target == 'wipy': @@ -273,7 +272,7 @@ def run_tests(pyb, tests, args): 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 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 'await await2 for for2 with with2'.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 skip_tests.update({'basics/%s.py' % t for t in 'with_break with_continue with_return'.split()}) # require complete with support skip_tests.add('basics/array_construct2.py') # requires generators diff --git a/tests/unicode/unicode.py b/tests/unicode/unicode.py index b31f064e9..5f29bc1c9 100644 --- a/tests/unicode/unicode.py +++ b/tests/unicode/unicode.py @@ -18,8 +18,9 @@ enc = s.encode() print(enc, enc.decode() == s) # printing of unicode chars using repr -# TODO we don't do this correctly -#print(repr(s)) +# NOTE: for some characters (eg \u10ff) we differ to CPython +print(repr('a\uffff')) +print(repr('a\U0001ffff')) # test invalid escape code try: |
