[Python-checkins] cpython: asyncio: Add a test for asyncio.iscoroutine().
yury.selivanov
python-checkins at python.org
Wed May 13 21:34:55 CEST 2015
https://hg.python.org/cpython/rev/ae702d4f199b
changeset: 96035:ae702d4f199b
user: Yury Selivanov <yselivanov at sprymix.com>
date: Wed May 13 15:34:12 2015 -0400
summary:
asyncio: Add a test for asyncio.iscoroutine().
Test that asyncio.iscoroutine() supports 'async def' coroutines and
collections.abc.Coroutine types.
files:
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
--- 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 @@
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()
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list