tests/micropython: Add more test cases for native generators.

Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
Damien George 2022-05-18 15:22:22 +10:00
parent 80938839c1
commit 761d2f6741
2 changed files with 37 additions and 0 deletions

View File

@ -23,3 +23,34 @@ def gen2(x):
print(list(gen2(3))) print(list(gen2(3)))
# catching an exception from .throw()
@micropython.native
def gen3():
try:
yield 1
yield 2
except Exception as er:
print("caught", repr(er))
yield 3
g = gen3()
print(next(g))
print(g.throw(ValueError(42)))
# responding to .close()
@micropython.native
def gen4():
try:
yield 1
except:
print("raising GeneratorExit")
raise GeneratorExit
g = gen4()
print(next(g))
print(g.close())

View File

@ -2,3 +2,9 @@
4 4
5 5
[0, 1, 2] [0, 1, 2]
1
caught ValueError(42,)
3
1
raising GeneratorExit
None