diff options
| author | Damien George <damien@micropython.org> | 2022-05-18 15:22:22 +1000 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2022-05-18 15:23:11 +1000 |
| commit | 761d2f67415ba43f64c7b04b6ea72fd4b65afc50 (patch) | |
| tree | bad0158d0bffdcd44919eb981c1581fbfb7c071d | |
| parent | 80938839c1513370d50d3aa6c9fc66a8b3ca1162 (diff) | |
tests/micropython: Add more test cases for native generators.
Signed-off-by: Damien George <damien@micropython.org>
| -rw-r--r-- | tests/micropython/native_gen.py | 31 | ||||
| -rw-r--r-- | tests/micropython/native_gen.py.exp | 6 |
2 files changed, 37 insertions, 0 deletions
diff --git a/tests/micropython/native_gen.py b/tests/micropython/native_gen.py index fb42f9e25..62c324634 100644 --- a/tests/micropython/native_gen.py +++ b/tests/micropython/native_gen.py @@ -23,3 +23,34 @@ def gen2(x): 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()) diff --git a/tests/micropython/native_gen.py.exp b/tests/micropython/native_gen.py.exp index cc09e309f..fba4e558c 100644 --- a/tests/micropython/native_gen.py.exp +++ b/tests/micropython/native_gen.py.exp @@ -2,3 +2,9 @@ 4 5 [0, 1, 2] +1 +caught ValueError(42,) +3 +1 +raising GeneratorExit +None |
