Skip to content

Commit

Permalink
tests/basics: Add tests to test repeated throw into the same generator.
Browse files Browse the repository at this point in the history
Signed-off-by: Damien George <damien@micropython.org>
  • Loading branch information
dpgeorge committed Jun 21, 2024
1 parent 038125b commit 0619f26
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tests/basics/gen_yield_from_throw_repeat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Test throwing repeatedly into the same generator, where that generator
# is yielding from another generator.


def yielder():
yield 4
yield 5


def gen():
while True:
try:
print("gen received:", (yield from yielder()))
except ValueError as exc:
print(repr(exc))


g = gen()
for i in range(2):
print("send, got:", g.send(None))
print("throw, got:", g.throw(ValueError("a", i)))
print("throw, got:", g.throw(ValueError("b", i)))
16 changes: 16 additions & 0 deletions tests/basics/generator_throw_repeat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Test throwing repeatedly into the same generator.


def gen():
while True:
try:
print("gen received:", (yield "value"))
except ValueError as exc:
print(repr(exc))


g = gen()
for i in range(2):
print("send, got:", g.send(None))
print("throw, got:", g.throw(ValueError("a", i)))
print("throw, got:", g.throw(ValueError("b", i)))

0 comments on commit 0619f26

Please sign in to comment.