[Python-checkins] bpo-32357: Fix tests in refleak mode (#4989)

Yury Selivanov webhook-mailer at python.org
Sat Dec 23 12:44:33 EST 2017


https://github.com/python/cpython/commit/558aa30f7971e087c4a00b1f49cc2ef3195c01ca
commit: 558aa30f7971e087c4a00b1f49cc2ef3195c01ca
branch: master
author: Yury Selivanov <yury at magic.io>
committer: GitHub <noreply at github.com>
date: 2017-12-23T12:44:29-05:00
summary:

bpo-32357: Fix tests in refleak mode (#4989)

files:
M Lib/test/test_asyncio/test_events.py
M Lib/test/test_asyncio/test_pep492.py

diff --git a/Lib/test/test_asyncio/test_events.py b/Lib/test/test_asyncio/test_events.py
index aefa33ba251..e5e41fc1a87 100644
--- a/Lib/test/test_asyncio/test_events.py
+++ b/Lib/test/test_asyncio/test_events.py
@@ -66,6 +66,20 @@ def _test_get_event_loop_new_process__sub_proc():
     return loop.run_until_complete(doit())
 
 
+class CoroLike:
+    def send(self, v):
+        pass
+
+    def throw(self, *exc):
+        pass
+
+    def close(self):
+        pass
+
+    def __await__(self):
+        pass
+
+
 ONLYCERT = data_file('ssl_cert.pem')
 ONLYKEY = data_file('ssl_key.pem')
 SIGNED_CERTFILE = data_file('keycert3.pem')
@@ -2365,20 +2379,7 @@ def test_coroutine_like_object_debug_formatting(self):
         # collections.abc.Coroutine, but lack cr_core or gi_code attributes
         # (such as ones compiled with Cython).
 
-        class Coro:
-            def send(self, v):
-                pass
-
-            def throw(self, *exc):
-                pass
-
-            def close(self):
-                pass
-
-            def __await__(self):
-                pass
-
-        coro = Coro()
+        coro = CoroLike()
         coro.__name__ = 'AAA'
         self.assertTrue(asyncio.iscoroutine(coro))
         self.assertEqual(coroutines._format_coroutine(coro), 'AAA()')
@@ -2389,10 +2390,10 @@ def __await__(self):
         coro.cr_running = True
         self.assertEqual(coroutines._format_coroutine(coro), 'BBB() running')
 
-        coro = Coro()
+        coro = CoroLike()
         # Some coroutines might not have '__name__', such as
         # built-in async_gen.asend().
-        self.assertEqual(coroutines._format_coroutine(coro), 'Coro()')
+        self.assertEqual(coroutines._format_coroutine(coro), 'CoroLike()')
 
 
 class TimerTests(unittest.TestCase):
diff --git a/Lib/test/test_asyncio/test_pep492.py b/Lib/test/test_asyncio/test_pep492.py
index 8dd0c25e7cf..289f7e59db7 100644
--- a/Lib/test/test_asyncio/test_pep492.py
+++ b/Lib/test/test_asyncio/test_pep492.py
@@ -10,6 +10,21 @@
 from test.test_asyncio import utils as test_utils
 
 
+# Test that asyncio.iscoroutine() uses collections.abc.Coroutine
+class FakeCoro:
+    def send(self, value):
+        pass
+
+    def throw(self, typ, val=None, tb=None):
+        pass
+
+    def close(self):
+        pass
+
+    def __await__(self):
+        yield
+
+
 class BaseTest(test_utils.TestCase):
 
     def setUp(self):
@@ -99,13 +114,6 @@ def test_iscoroutine(self):
         finally:
             f.close() # silence warning
 
-        # Test that asyncio.iscoroutine() uses collections.abc.Coroutine
-        class FakeCoro:
-            def send(self, value): pass
-            def throw(self, typ, val=None, tb=None): pass
-            def close(self): pass
-            def __await__(self): yield
-
         self.assertTrue(asyncio.iscoroutine(FakeCoro()))
 
     def test_iscoroutinefunction(self):



More information about the Python-checkins mailing list