summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_asyncgen.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_asyncgen.py')
-rw-r--r--Lib/test/test_asyncgen.py48
1 files changed, 48 insertions, 0 deletions
diff --git a/Lib/test/test_asyncgen.py b/Lib/test/test_asyncgen.py
index 1985ede..4f2278b 100644
--- a/Lib/test/test_asyncgen.py
+++ b/Lib/test/test_asyncgen.py
@@ -571,6 +571,54 @@ class AsyncGenTest(unittest.TestCase):
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):