mirror of
https://github.com/micropython/micropython.git
synced 2026-01-07 12:40:15 +01:00
tests: Improve test coverage of py/compile.c.
This commit is contained in:
16
tests/basics/async_def.py
Normal file
16
tests/basics/async_def.py
Normal file
@@ -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')
|
||||
3
tests/basics/async_def.py.exp
Normal file
3
tests/basics/async_def.py.exp
Normal file
@@ -0,0 +1,3 @@
|
||||
decorator
|
||||
foo
|
||||
StopIteration
|
||||
@@ -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()
|
||||
|
||||
@@ -3,5 +3,6 @@ body
|
||||
exit None None
|
||||
finished
|
||||
enter
|
||||
1
|
||||
exit <class 'ValueError'> error
|
||||
ValueError
|
||||
|
||||
@@ -54,3 +54,8 @@ try:
|
||||
print(c)
|
||||
except NameError:
|
||||
print("NameError")
|
||||
|
||||
a = 1
|
||||
b = 2
|
||||
c = 3
|
||||
del (a, (b, c))
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user