summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_asyncio
diff options
context:
space:
mode:
authorYury Selivanov <yselivanov@sprymix.com>2015-10-02 19:05:59 (GMT)
committerYury Selivanov <yselivanov@sprymix.com>2015-10-02 19:05:59 (GMT)
commit43d71e2512707b959cc1cc850b85c2de99fee138 (patch)
tree4b71d141004abe07e19883318bb1dafafb3232d6 /Lib/test/test_asyncio
parent987f21514122b83e42b04f9782f53b6f77edb174 (diff)
parent620279b9ace3fff66245672bf7efbb62b2969a30 (diff)
downloadcpython-43d71e2512707b959cc1cc850b85c2de99fee138.zip
cpython-43d71e2512707b959cc1cc850b85c2de99fee138.tar.gz
cpython-43d71e2512707b959cc1cc850b85c2de99fee138.tar.bz2
asyncio: Make ensure_future() accept all kinds of awaitables.
Diffstat (limited to 'Lib/test/test_asyncio')
-rw-r--r--Lib/test/test_asyncio/test_tasks.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/Lib/test/test_asyncio/test_tasks.py b/Lib/test/test_asyncio/test_tasks.py
index 0426787..16d3d9d 100644
--- a/Lib/test/test_asyncio/test_tasks.py
+++ b/Lib/test/test_asyncio/test_tasks.py
@@ -153,6 +153,24 @@ class TaskTests(test_utils.TestCase):
t = asyncio.ensure_future(t_orig, loop=self.loop)
self.assertIs(t, t_orig)
+ @unittest.skipUnless(PY35, 'need python 3.5 or later')
+ def test_ensure_future_awaitable(self):
+ class Aw:
+ def __init__(self, coro):
+ self.coro = coro
+ def __await__(self):
+ return (yield from self.coro)
+
+ @asyncio.coroutine
+ def coro():
+ return 'ok'
+
+ loop = asyncio.new_event_loop()
+ self.set_event_loop(loop)
+ fut = asyncio.ensure_future(Aw(coro()), loop=loop)
+ loop.run_until_complete(fut)
+ assert fut.result() == 'ok'
+
def test_ensure_future_neither(self):
with self.assertRaises(TypeError):
asyncio.ensure_future('ok')