summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_asyncgen.py
diff options
context:
space:
mode:
authorYury Selivanov <yury@magic.io>2018-06-08 01:32:43 (GMT)
committerGitHub <noreply@github.com>2018-06-08 01:32:43 (GMT)
commit8de73d5a6914cfe55c23b0ad829cd2ba8954bc2e (patch)
tree0b349a6a16a4eef4480ce9b346cd6f41a8babb9f /Lib/test/test_asyncgen.py
parentd071ab12c85636cd15c8ef33647dad9db8441afb (diff)
downloadcpython-8de73d5a6914cfe55c23b0ad829cd2ba8954bc2e.zip
cpython-8de73d5a6914cfe55c23b0ad829cd2ba8954bc2e.tar.gz
cpython-8de73d5a6914cfe55c23b0ad829cd2ba8954bc2e.tar.bz2
bpo-33786: Fix asynchronous generators to handle GeneratorExit in athrow() (GH-7467) (GH-7507)
Diffstat (limited to 'Lib/test/test_asyncgen.py')
-rw-r--r--Lib/test/test_asyncgen.py56
1 files changed, 56 insertions, 0 deletions
diff --git a/Lib/test/test_asyncgen.py b/Lib/test/test_asyncgen.py
index 34ab8a0..45cc275 100644
--- a/Lib/test/test_asyncgen.py
+++ b/Lib/test/test_asyncgen.py
@@ -114,6 +114,31 @@ class AsyncGenTest(unittest.TestCase):
def async_iterate(g):
res = []
while True:
+ an = g.__anext__()
+ try:
+ while True:
+ try:
+ an.__next__()
+ except StopIteration as ex:
+ if ex.args:
+ res.append(ex.args[0])
+ break
+ else:
+ res.append('EMPTY StopIteration')
+ break
+ except StopAsyncIteration:
+ raise
+ except Exception as ex:
+ res.append(str(type(ex)))
+ break
+ except StopAsyncIteration:
+ res.append('STOP')
+ break
+ return res
+
+ def async_iterate(g):
+ res = []
+ while True:
try:
g.__anext__().__next__()
except StopAsyncIteration:
@@ -300,6 +325,37 @@ class AsyncGenTest(unittest.TestCase):
"non-None value .* async generator"):
gen().__anext__().send(100)
+ def test_async_gen_exception_11(self):
+ def sync_gen():
+ yield 10
+ yield 20
+
+ def sync_gen_wrapper():
+ yield 1
+ sg = sync_gen()
+ sg.send(None)
+ try:
+ sg.throw(GeneratorExit())
+ except GeneratorExit:
+ yield 2
+ yield 3
+
+ async def async_gen():
+ yield 10
+ yield 20
+
+ async def async_gen_wrapper():
+ yield 1
+ asg = async_gen()
+ await asg.asend(None)
+ try:
+ await asg.athrow(GeneratorExit())
+ except GeneratorExit:
+ yield 2
+ yield 3
+
+ self.compare_generators(sync_gen_wrapper(), async_gen_wrapper())
+
def test_async_gen_api_01(self):
async def gen():
yield 123