diff options
author | Yury Selivanov <yselivanov@sprymix.com> | 2015-05-13 19:34:12 (GMT) |
---|---|---|
committer | Yury Selivanov <yselivanov@sprymix.com> | 2015-05-13 19:34:12 (GMT) |
commit | 6c792bd65a22830192c6ce4ee619e805c2daed7c (patch) | |
tree | dbed89a65920eda651c04bc447d2b3b69c86f004 | |
parent | af928b65fce14ef2d5bb5bd3bc90381e61d71e34 (diff) | |
download | cpython-6c792bd65a22830192c6ce4ee619e805c2daed7c.zip cpython-6c792bd65a22830192c6ce4ee619e805c2daed7c.tar.gz cpython-6c792bd65a22830192c6ce4ee619e805c2daed7c.tar.bz2 |
asyncio: Add a test for asyncio.iscoroutine().
Test that asyncio.iscoroutine() supports 'async def' coroutines and
collections.abc.Coroutine types.
-rw-r--r-- | Lib/test/test_asyncio/test_pep492.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/Lib/test/test_asyncio/test_pep492.py b/Lib/test/test_asyncio/test_pep492.py index 3d8d1b8..6e235c6 100644 --- a/Lib/test/test_asyncio/test_pep492.py +++ b/Lib/test/test_asyncio/test_pep492.py @@ -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() |