diff options
author | Yury Selivanov <yury@magic.io> | 2016-10-05 23:32:49 (GMT) |
---|---|---|
committer | Yury Selivanov <yury@magic.io> | 2016-10-05 23:32:49 (GMT) |
commit | 8dc3e438398046c6bb989e038cd08280aa356982 (patch) | |
tree | 84019478ef27a0b2273cbda25d13de72f1dcfee2 /Lib/test/test_asyncio | |
parent | 0de3de6cbfe034654dc03f3808de0c25e28a0c38 (diff) | |
download | cpython-8dc3e438398046c6bb989e038cd08280aa356982.zip cpython-8dc3e438398046c6bb989e038cd08280aa356982.tar.gz cpython-8dc3e438398046c6bb989e038cd08280aa356982.tar.bz2 |
Issue #28372: Fix asyncio to support formatting of non-python coroutines
Diffstat (limited to 'Lib/test/test_asyncio')
-rw-r--r-- | Lib/test/test_asyncio/test_events.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/Lib/test/test_asyncio/test_events.py b/Lib/test/test_asyncio/test_events.py index b3f35ce..7df926f 100644 --- a/Lib/test/test_asyncio/test_events.py +++ b/Lib/test/test_asyncio/test_events.py @@ -1,5 +1,6 @@ """Tests for events.py.""" +import collections.abc import functools import gc import io @@ -25,6 +26,7 @@ if sys.platform != 'win32': import tty import asyncio +from asyncio import coroutines from asyncio import proactor_events from asyncio import selector_events from asyncio import sslproto @@ -2380,6 +2382,38 @@ class HandleTests(test_utils.TestCase): h = loop.call_later(0, noop) check_source_traceback(h) + @unittest.skipUnless(hasattr(collections.abc, 'Coroutine'), + 'No collections.abc.Coroutine') + def test_coroutine_like_object_debug_formatting(self): + # Test that asyncio can format coroutines that are instances of + # collections.abc.Coroutine, but lack cr_core or gi_code attributes + # (such as ones compiled with Cython). + + class Coro: + __name__ = 'AAA' + + def send(self, v): + pass + + def throw(self, *exc): + pass + + def close(self): + pass + + def __await__(self): + pass + + coro = Coro() + self.assertTrue(asyncio.iscoroutine(coro)) + self.assertEqual(coroutines._format_coroutine(coro), 'AAA()') + + coro.__qualname__ = 'BBB' + self.assertEqual(coroutines._format_coroutine(coro), 'BBB()') + + coro.cr_running = True + self.assertEqual(coroutines._format_coroutine(coro), 'BBB() running') + class TimerTests(unittest.TestCase): |