diff --git a/tests/basics/async_def.py b/tests/basics/async_def.py new file mode 100644 index 0000000000000000000000000000000000000000..e345703d7473b8dfa1a82af2b2a7cf3b8a75fdfd --- /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 0000000000000000000000000000000000000000..f555ace99ab20477ac440f817db1246b3b617675 --- /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 9eccfd816c3884b9f3f9ab1480d24a8ef6ea4b8c..5af0c5d955ccb597d8da0a9d6b7c5c794405b68e 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 6072a3e0b33d30384e12be4a3d34662e1c828c4a..d00b18c9693e20bd6a34c66639c378cc061edb3c 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/del_global.py b/tests/basics/del_global.py index 77d11cb3c4fad11dca7cdb0cf764864b1f796d94..d740357b0332d627c5233e40452e8fd9af0dffdf 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/for_range.py b/tests/basics/for_range.py index ddff5ebd44357e5c4d25610e188ec6de85e94996..58a8f7caa732b693e7def90b312af09943e88f8f 100644 --- a/tests/basics/for_range.py +++ b/tests/basics/for_range.py @@ -34,6 +34,11 @@ try: print(x) 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) diff --git a/tests/basics/syntaxerror.py b/tests/basics/syntaxerror.py index 2ae0183f8ba16ddc342344601f6a3d75b2faa383..e5cbbac060e61df1df41bb3d2de3ffed3485d565 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 10e01dea06b429257e5a2d466d45214860b183ff..0e8ec592c930c0f1dbf65e79806accb1aada81bf 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/repl_basic.py b/tests/cmdline/repl_basic.py index b416493dcebfdf34989f7c91545d38700df8e3dd..cbd5d3a4acbb00a3ce73bf5e3455191f64b455aa 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 96b8c28dce3bb2711d3be040ec32390d475f416e..2b390ea98bb755931e2bbbfbbc33ff04d584d390 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/import/import2a.py b/tests/import/import2a.py index ce32b10b1b956e5b27e73b1b34c2a2776c6f4d1a..def6aeb6aa3830704aca915213f13783fc394b0d 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/viper_args.py b/tests/micropython/viper_args.py index ca2a5e670444785af397b7ef73644791ba2bb697..2aebe1b048b6b2d80090e3c96057f11ffc42d94b 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 1157ff8b29e11e1fb92c7fed85736b3f0b6a803b..e0b07c3ad6316ee35fb3e354fd8d5e703e92515d 100644 --- a/tests/misc/non_compliant.py +++ b/tests/misc/non_compliant.py @@ -3,6 +3,12 @@ import array import ustruct +# when super can't find self +try: + exec('def f(): super()') +except SyntaxError: + print('SyntaxError') + # array deletion not implemented try: a = array.array('b', (1, 2, 3)) diff --git a/tests/misc/non_compliant.py.exp b/tests/misc/non_compliant.py.exp index c03580442d262b6751eb1261eb7779afec6d3188..3095441ad05c4d8d23c185b21edfc34f27b6095d 100644 --- a/tests/misc/non_compliant.py.exp +++ b/tests/misc/non_compliant.py.exp @@ -1,3 +1,4 @@ +SyntaxError TypeError NotImplementedError True diff --git a/tests/run-tests b/tests/run-tests index cb920c094601a51951808bbe6a2104baa6c613c3..422d7463aff15912ff55f732cea4be09014ff2e1 100755 --- a/tests/run-tests +++ b/tests/run-tests @@ -273,7 +273,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