Skip to content

Commit 5e22afc

Browse files
committed
tests: Improve test coverage of py/compile.c.
1 parent e49153f commit 5e22afc

File tree

15 files changed

+60
-2
lines changed

15 files changed

+60
-2
lines changed

tests/basics/async_def.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# test async def
2+
3+
def dec(f):
4+
print('decorator')
5+
return f
6+
7+
# test definition with a decorator
8+
@dec
9+
async def foo():
10+
print('foo')
11+
12+
coro = foo()
13+
try:
14+
coro.send(None)
15+
except StopIteration:
16+
print('StopIteration')

tests/basics/async_def.py.exp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
decorator
2+
foo
3+
StopIteration

tests/basics/async_with.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
class AContext:
44
async def __aenter__(self):
55
print('enter')
6+
return 1
67
async def __aexit__(self, exc_type, exc, tb):
78
print('exit', exc_type, exc)
89

@@ -17,7 +18,8 @@ async def f():
1718
print('finished')
1819

1920
async def g():
20-
async with AContext():
21+
async with AContext() as ac:
22+
print(ac)
2123
raise ValueError('error')
2224

2325
o = g()

tests/basics/async_with.py.exp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ body
33
exit None None
44
finished
55
enter
6+
1
67
exit <class 'ValueError'> error
78
ValueError

tests/basics/del_global.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,8 @@ def do_del():
5454
print(c)
5555
except NameError:
5656
print("NameError")
57+
58+
a = 1
59+
b = 2
60+
c = 3
61+
del (a, (b, c))

tests/basics/for_range.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@
3434
print(x)
3535
except TypeError:
3636
print('TypeError')
37+
try:
38+
for x in range(start=0, end=1):
39+
print(x)
40+
except TypeError:
41+
print('TypeError')
3742
try:
3843
for x in range(0, 1, step=1):
3944
print(x)

tests/basics/syntaxerror.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ def test_syntax(code):
4949
# can't assign to empty tuple
5050
test_syntax("() = 1")
5151

52+
# can't have *x on RHS
53+
test_syntax("x = *x")
54+
5255
# can't have multiple *x on LHS
5356
test_syntax("*a, *b = c")
5457

@@ -76,6 +79,7 @@ def test_syntax(code):
7679
test_syntax("return")
7780
test_syntax("yield")
7881
test_syntax("nonlocal a")
82+
test_syntax("await 1")
7983

8084
# error on uPy, warning on CPy
8185
#test_syntax("def f():\n a = 1\n global a")

tests/basics/unpack1.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
(a,) = range(1); print(a)
1313
(a, b) = range(2); print(a, b)
1414
(a, b, c) = range(3); print(a, b, c)
15+
(a, (b, c)) = [-1, range(2)]; print(a, b, c)
1516

1617
# lists
1718

tests/cmdline/repl_basic.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
# basic REPL tests
22
print(1)
33

4+
2

tests/cmdline/repl_basic.py.exp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ Use \.\+
55
1
66
>>> print(1)
77
1
8+
>>> 2
9+
2
810
>>>

0 commit comments

Comments
 (0)