Skip to content

Commit

Permalink
test athrow().close() and asend().close() raises RuntimeError
Browse files Browse the repository at this point in the history
  • Loading branch information
graingert committed Apr 24, 2024
1 parent 7d2217a commit 8e1fb97
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions Lib/test/test_asyncgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,54 @@ async def gen():
self.assertTrue(inspect.isawaitable(aclose))
aclose.close()

def test_async_gen_asend_close_runtime_error(self):
import types

@types.coroutine
def _async_yield(v):
return (yield v)

async def agenfn():
try:
await _async_yield(None)
except GeneratorExit:
await _async_yield(None)
return
yield

agen = agenfn()
gen = agen.asend(None)
gen.send(None)
with self.assertRaisesRegex(RuntimeError, "coroutine ignored GeneratorExit"):
gen.close()

def test_async_gen_athrow_close_runtime_error(self):
import types

@types.coroutine
def _async_yield(v):
return (yield v)

class MyExc(Exception):
pass

async def agenfn():
try:
yield
except MyExc:
try:
await _async_yield(None)
except GeneratorExit:
await _async_yield(None)

agen = agenfn()
with self.assertRaises(StopIteration):
agen.asend(None).send(None)
gen = agen.athrow(MyExc)
gen.send(None)
with self.assertRaisesRegex(RuntimeError, "coroutine ignored GeneratorExit"):
gen.close()


class AsyncGenAsyncioTest(unittest.TestCase):

Expand Down

0 comments on commit 8e1fb97

Please sign in to comment.