tests: Improve test coverage of py/compile.c.
This commit is contained in:
parent
e49153fb98
commit
5e22afce41
|
@ -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')
|
|
@ -0,0 +1,3 @@
|
||||||
|
decorator
|
||||||
|
foo
|
||||||
|
StopIteration
|
|
@ -3,6 +3,7 @@
|
||||||
class AContext:
|
class AContext:
|
||||||
async def __aenter__(self):
|
async def __aenter__(self):
|
||||||
print('enter')
|
print('enter')
|
||||||
|
return 1
|
||||||
async def __aexit__(self, exc_type, exc, tb):
|
async def __aexit__(self, exc_type, exc, tb):
|
||||||
print('exit', exc_type, exc)
|
print('exit', exc_type, exc)
|
||||||
|
|
||||||
|
@ -17,7 +18,8 @@ except StopIteration:
|
||||||
print('finished')
|
print('finished')
|
||||||
|
|
||||||
async def g():
|
async def g():
|
||||||
async with AContext():
|
async with AContext() as ac:
|
||||||
|
print(ac)
|
||||||
raise ValueError('error')
|
raise ValueError('error')
|
||||||
|
|
||||||
o = g()
|
o = g()
|
||||||
|
|
|
@ -3,5 +3,6 @@ body
|
||||||
exit None None
|
exit None None
|
||||||
finished
|
finished
|
||||||
enter
|
enter
|
||||||
|
1
|
||||||
exit <class 'ValueError'> error
|
exit <class 'ValueError'> error
|
||||||
ValueError
|
ValueError
|
||||||
|
|
|
@ -54,3 +54,8 @@ try:
|
||||||
print(c)
|
print(c)
|
||||||
except NameError:
|
except NameError:
|
||||||
print("NameError")
|
print("NameError")
|
||||||
|
|
||||||
|
a = 1
|
||||||
|
b = 2
|
||||||
|
c = 3
|
||||||
|
del (a, (b, c))
|
||||||
|
|
|
@ -34,6 +34,11 @@ try:
|
||||||
print(x)
|
print(x)
|
||||||
except TypeError:
|
except TypeError:
|
||||||
print('TypeError')
|
print('TypeError')
|
||||||
|
try:
|
||||||
|
for x in range(start=0, end=1):
|
||||||
|
print(x)
|
||||||
|
except TypeError:
|
||||||
|
print('TypeError')
|
||||||
try:
|
try:
|
||||||
for x in range(0, 1, step=1):
|
for x in range(0, 1, step=1):
|
||||||
print(x)
|
print(x)
|
||||||
|
|
|
@ -49,6 +49,9 @@ test_syntax("f[0]**2 = 1")
|
||||||
# can't assign to empty tuple
|
# can't assign to empty tuple
|
||||||
test_syntax("() = 1")
|
test_syntax("() = 1")
|
||||||
|
|
||||||
|
# can't have *x on RHS
|
||||||
|
test_syntax("x = *x")
|
||||||
|
|
||||||
# can't have multiple *x on LHS
|
# can't have multiple *x on LHS
|
||||||
test_syntax("*a, *b = c")
|
test_syntax("*a, *b = c")
|
||||||
|
|
||||||
|
@ -76,6 +79,7 @@ test_syntax("continue")
|
||||||
test_syntax("return")
|
test_syntax("return")
|
||||||
test_syntax("yield")
|
test_syntax("yield")
|
||||||
test_syntax("nonlocal a")
|
test_syntax("nonlocal a")
|
||||||
|
test_syntax("await 1")
|
||||||
|
|
||||||
# error on uPy, warning on CPy
|
# error on uPy, warning on CPy
|
||||||
#test_syntax("def f():\n a = 1\n global a")
|
#test_syntax("def f():\n a = 1\n global a")
|
||||||
|
|
|
@ -12,6 +12,7 @@ a, b, c = range(3); print(a, b, c)
|
||||||
(a,) = range(1); print(a)
|
(a,) = range(1); print(a)
|
||||||
(a, b) = range(2); print(a, b)
|
(a, b) = range(2); print(a, b)
|
||||||
(a, b, c) = range(3); print(a, b, c)
|
(a, b, c) = range(3); print(a, b, c)
|
||||||
|
(a, (b, c)) = [-1, range(2)]; print(a, b, c)
|
||||||
|
|
||||||
# lists
|
# lists
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
# basic REPL tests
|
# basic REPL tests
|
||||||
print(1)
|
print(1)
|
||||||
[A
|
[A
|
||||||
|
2
|
||||||
|
|
|
@ -5,4 +5,6 @@ Use \.\+
|
||||||
1
|
1
|
||||||
>>> print(1)
|
>>> print(1)
|
||||||
1
|
1
|
||||||
|
>>> 2
|
||||||
|
2
|
||||||
>>>
|
>>>
|
||||||
|
|
|
@ -1,2 +1,5 @@
|
||||||
from import1b import var
|
from import1b import var
|
||||||
print(var)
|
print(var)
|
||||||
|
|
||||||
|
from import1b import var as var2
|
||||||
|
print(var2)
|
||||||
|
|
|
@ -26,3 +26,11 @@ def f4(x1:int, x2:int, x3:int, x4:int):
|
||||||
f4(1, 2, 3, 4)
|
f4(1, 2, 3, 4)
|
||||||
|
|
||||||
# only up to 4 arguments currently supported
|
# 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
|
||||||
|
|
|
@ -3,6 +3,12 @@
|
||||||
import array
|
import array
|
||||||
import ustruct
|
import ustruct
|
||||||
|
|
||||||
|
# when super can't find self
|
||||||
|
try:
|
||||||
|
exec('def f(): super()')
|
||||||
|
except SyntaxError:
|
||||||
|
print('SyntaxError')
|
||||||
|
|
||||||
# array deletion not implemented
|
# array deletion not implemented
|
||||||
try:
|
try:
|
||||||
a = array.array('b', (1, 2, 3))
|
a = array.array('b', (1, 2, 3))
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
SyntaxError
|
||||||
TypeError
|
TypeError
|
||||||
NotImplementedError
|
NotImplementedError
|
||||||
True
|
True
|
||||||
|
|
|
@ -273,7 +273,7 @@ def run_tests(pyb, tests, args):
|
||||||
if args.emit == 'native':
|
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 '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/%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 '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.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
|
skip_tests.add('basics/array_construct2.py') # requires generators
|
||||||
|
|
Loading…
Reference in New Issue