Author: Mariano Anaya <[email protected]>
Branch: py3.6
Changeset: r91909:b6e947786fa5
Date: 2017-07-16 17:00 +0200
http://bitbucket.org/pypy/pypy/changeset/b6e947786fa5/

Log:    Add test for async generator fail while running

        Check when an exception is thrown by calling `.athrow()` while on
        the middle of the execution.

diff --git a/pypy/interpreter/test/test_coroutine.py 
b/pypy/interpreter/test/test_coroutine.py
--- a/pypy/interpreter/test/test_coroutine.py
+++ b/pypy/interpreter/test/test_coroutine.py
@@ -421,3 +421,30 @@
         raises(RuntimeError, ag().athrow(ValueError).throw, LookupError)
         # CPython's message makes little sense; PyPy's message is different
     """
+
+    def test_async_yield_athrow_while_running(self): """
+        values = []
+        async def ag():
+            try:
+                received = yield 1
+            except ValueError:
+                values.append(42)
+                return
+            yield 2
+
+
+        async def run():
+            running = ag()
+            x = await running.asend(None)
+            assert x == 1
+            try:
+                await running.athrow(ValueError)
+            except StopAsyncIteration:
+                pass
+
+
+        try:
+            run().send(None)
+        except StopIteration:
+            assert values == [42]
+    """
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to