Author: Ronan Lamy <[email protected]>
Branch: py3.6
Changeset: r97701:d3b503bab689
Date: 2019-10-01 21:26 +0100
http://bitbucket.org/pypy/pypy/changeset/d3b503bab689/

Log:    Use suspend() helper in more tests to avoid importing types from
        lib-python

diff --git a/pypy/interpreter/test/apptest_coroutine.py 
b/pypy/interpreter/test/apptest_coroutine.py
--- a/pypy/interpreter/test/apptest_coroutine.py
+++ b/pypy/interpreter/test/apptest_coroutine.py
@@ -4,6 +4,18 @@
 import sys
 
 
+class suspend:
+    """
+    A simple awaitable that returns control to the "event loop" with `msg`
+    as value.
+    """
+    def __init__(self, msg=None):
+        self.msg = msg
+
+    def __await__(self):
+        yield self.msg
+
+
 def test_cannot_iterate():
     async def f(x):
         pass
@@ -111,7 +123,6 @@
     sys.set_coroutine_wrapper(None)
     assert sys.get_coroutine_wrapper() is None
 
-
 def test_async_with():
     seen = []
     class X:
@@ -519,12 +530,6 @@
     raises(RuntimeError, run().send, None)
 
 def test_async_aclose_await_in_finally():
-    import types
-
-    @types.coroutine
-    def coro():
-        yield 'coro'
-
     state = 0
     async def ag():
         nonlocal state
@@ -532,7 +537,7 @@
             yield
         finally:
             state = 1
-            await coro()
+            await suspend('coro')
             state = 2
 
     async def run():
@@ -551,12 +556,6 @@
     assert state == 2
 
 def test_async_aclose_await_in_finally_with_exception():
-    import types
-
-    @types.coroutine
-    def coro():
-        yield 'coro'
-
     state = 0
     async def ag():
         nonlocal state
@@ -565,7 +564,7 @@
         finally:
             state = 1
             try:
-                await coro()
+                await suspend('coro')
             except Exception as exc:
                 state = exc
 
@@ -586,17 +585,12 @@
     assert state == exc
 
 def test_agen_aclose_await_and_yield_in_finally():
-    import types
-    @types.coroutine
-    def bar():
-        yield 42
-
     async def foo():
         try:
             yield 1
             1 / 0
         finally:
-            await bar()
+            await suspend(42)
             yield 12
 
     async def run():
@@ -612,12 +606,6 @@
 
 def test_async_aclose_in_finalize_hook_await_in_finally():
     import gc
-    import types
-
-    @types.coroutine
-    def coro():
-        yield 'coro'
-
     state = 0
     async def ag():
         nonlocal state
@@ -625,7 +613,7 @@
             yield
         finally:
             state = 1
-            await coro()
+            await suspend('coro')
             state = 2
 
     async def run():
@@ -730,17 +718,6 @@
 
     run_async(run())
 
-class suspend:
-    """
-    A simple awaitable that returns control to the "event loop" with `msg`
-    as value.
-    """
-    def __init__(self, msg=None):
-        self.msg = msg
-
-    def __await__(self):
-        yield self.msg
-
 def test_asyncgen_hooks_shutdown():
     finalized = 0
     asyncgens = []
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to