Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e351047

Browse filesBrowse files
committed
test athrow().close() and asend().close() raises RuntimeError
1 parent b190119 commit e351047
Copy full SHA for e351047

File tree

Expand file treeCollapse file tree

1 file changed

+48
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+48
-0
lines changed

‎Lib/test/test_asyncgen.py

Copy file name to clipboardExpand all lines: Lib/test/test_asyncgen.py
+48Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,54 @@ async def gen():
571571
self.assertTrue(inspect.isawaitable(aclose))
572572
aclose.close()
573573

574+
def test_async_gen_asend_close_runtime_error(self):
575+
import types
576+
577+
@types.coroutine
578+
def _async_yield(v):
579+
return (yield v)
580+
581+
async def agenfn():
582+
try:
583+
await _async_yield(None)
584+
except GeneratorExit:
585+
await _async_yield(None)
586+
return
587+
yield
588+
589+
agen = agenfn()
590+
gen = agen.asend(None)
591+
gen.send(None)
592+
with self.assertRaisesRegex(RuntimeError, "coroutine ignored GeneratorExit"):
593+
gen.close()
594+
595+
def test_async_gen_athrow_close_runtime_error(self):
596+
import types
597+
598+
@types.coroutine
599+
def _async_yield(v):
600+
return (yield v)
601+
602+
class MyExc(Exception):
603+
pass
604+
605+
async def agenfn():
606+
try:
607+
yield
608+
except MyExc:
609+
try:
610+
await _async_yield(None)
611+
except GeneratorExit:
612+
await _async_yield(None)
613+
614+
agen = agenfn()
615+
with self.assertRaises(StopIteration):
616+
agen.asend(None).send(None)
617+
gen = agen.athrow(MyExc)
618+
gen.send(None)
619+
with self.assertRaisesRegex(RuntimeError, "coroutine ignored GeneratorExit"):
620+
gen.close()
621+
574622

575623
class AsyncGenAsyncioTest(unittest.TestCase):
576624

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.