Skip to content

Commit 0619f26

Browse files
committed
tests/basics: Add tests to test repeated throw into the same generator.
Signed-off-by: Damien George <[email protected]>
1 parent 038125b commit 0619f26

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Test throwing repeatedly into the same generator, where that generator
2+
# is yielding from another generator.
3+
4+
5+
def yielder():
6+
yield 4
7+
yield 5
8+
9+
10+
def gen():
11+
while True:
12+
try:
13+
print("gen received:", (yield from yielder()))
14+
except ValueError as exc:
15+
print(repr(exc))
16+
17+
18+
g = gen()
19+
for i in range(2):
20+
print("send, got:", g.send(None))
21+
print("throw, got:", g.throw(ValueError("a", i)))
22+
print("throw, got:", g.throw(ValueError("b", i)))
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Test throwing repeatedly into the same generator.
2+
3+
4+
def gen():
5+
while True:
6+
try:
7+
print("gen received:", (yield "value"))
8+
except ValueError as exc:
9+
print(repr(exc))
10+
11+
12+
g = gen()
13+
for i in range(2):
14+
print("send, got:", g.send(None))
15+
print("throw, got:", g.throw(ValueError("a", i)))
16+
print("throw, got:", g.throw(ValueError("b", i)))

0 commit comments

Comments
 (0)