]> granicus.if.org Git - python/commitdiff
asyncio: Add a test for asyncio.iscoroutine().
authorYury Selivanov <yselivanov@sprymix.com>
Wed, 13 May 2015 19:34:12 +0000 (15:34 -0400)
committerYury Selivanov <yselivanov@sprymix.com>
Wed, 13 May 2015 19:34:12 +0000 (15:34 -0400)
Test that asyncio.iscoroutine() supports 'async def' coroutines and
collections.abc.Coroutine types.

Lib/test/test_asyncio/test_pep492.py

index 3d8d1b8c7a338c62c4c1530e6a968385421e0f92..6e235c60fe9883dacf4e25384826836b1630eb78 100644 (file)
@@ -1,6 +1,10 @@
 """Tests support for new syntax introduced by PEP 492."""
 
+import collections.abc
+import gc
 import unittest
+
+from test import support
 from unittest import mock
 
 import asyncio
@@ -83,5 +87,30 @@ class StreamReaderTests(BaseTest):
         self.assertEqual(data, [b'line1\n', b'line2\n', b'line3'])
 
 
+class CoroutineTests(BaseTest):
+
+    def test_iscoroutine(self):
+        async def foo(): pass
+
+        f = foo()
+        try:
+            self.assertTrue(asyncio.iscoroutine(f))
+        finally:
+            f.close() # silence warning
+
+        class FakeCoro(collections.abc.Coroutine):
+            def send(self, value): pass
+            def throw(self, typ, val=None, tb=None): pass
+
+        fc = FakeCoro()
+        try:
+            self.assertTrue(asyncio.iscoroutine(fc))
+        finally:
+            # To make sure that ABCMeta caches are freed
+            # from FakeCoro ASAP.
+            fc = FakeCoro = None
+            support.gc_collect()
+
+
 if __name__ == '__main__':
     unittest.main()