Skip to content

Commit

Permalink
test re-using aclose().throw(...)
Browse files Browse the repository at this point in the history
  • Loading branch information
graingert committed Apr 13, 2024
1 parent da89a69 commit 797e0d5
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions Lib/test/test_asyncgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -1671,6 +1671,42 @@ async def run():

self.loop.run_until_complete(run())

def test_async_gen_throw_same_aclose_coro_twice(self):
async def async_iterate():
yield 1
yield 2

it = async_iterate()
nxt = it.aclose()
with self.assertRaises(StopIteration):
nxt.throw(GeneratorExit)

with self.assertRaisesRegex(
RuntimeError,
r"cannot reuse already awaited aclose\(\)/athrow\(\)"
):
nxt.throw(GeneratorExit)

def test_async_gen_throw_custom_same_aclose_coro_twice(self):
async def async_iterate():
yield 1
yield 2

it = async_iterate()

class MyException(Exception):
pass

nxt = it.aclose()
with self.assertRaises(MyException):
nxt.throw(MyException)

with self.assertRaisesRegex(
RuntimeError,
r"cannot reuse already awaited aclose\(\)/athrow\(\)"
):
nxt.throw(MyException)

def test_async_gen_aclose_twice_with_different_coros(self):
# Regression test for https://bugs.python.org/issue39606
async def async_iterate():
Expand Down

0 comments on commit 797e0d5

Please sign in to comment.