summaryrefslogtreecommitdiff
path: root/Lib/test/test_asyncio
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_asyncio')
-rw-r--r--Lib/test/test_asyncio/test_tasks.py37
-rw-r--r--Lib/test/test_asyncio/utils.py3
2 files changed, 39 insertions, 1 deletions
diff --git a/Lib/test/test_asyncio/test_tasks.py b/Lib/test/test_asyncio/test_tasks.py
index a5563ba9c6..a32dca1311 100644
--- a/Lib/test/test_asyncio/test_tasks.py
+++ b/Lib/test/test_asyncio/test_tasks.py
@@ -2054,6 +2054,43 @@ class BaseTaskTests:
self.assertEqual(self.Task.all_tasks(self.loop), set())
+ def test_create_task_with_noncoroutine(self):
+ with self.assertRaisesRegex(TypeError,
+ "a coroutine was expected, got 123"):
+ self.new_task(self.loop, 123)
+
+ def test_create_task_with_oldstyle_coroutine(self):
+
+ @asyncio.coroutine
+ def coro():
+ pass
+
+ task = self.new_task(self.loop, coro())
+ self.assertIsInstance(task, self.Task)
+ self.loop.run_until_complete(task)
+
+ def test_create_task_with_async_function(self):
+
+ async def coro():
+ pass
+
+ task = self.new_task(self.loop, coro())
+ self.assertIsInstance(task, self.Task)
+ self.loop.run_until_complete(task)
+
+ def test_bare_create_task(self):
+
+ async def inner():
+ return 1
+
+ async def coro():
+ task = asyncio.create_task(inner())
+ self.assertIsInstance(task, self.Task)
+ ret = await task
+ self.assertEqual(1, ret)
+
+ self.loop.run_until_complete(coro())
+
def add_subclass_tests(cls):
BaseTask = cls.Task
diff --git a/Lib/test/test_asyncio/utils.py b/Lib/test/test_asyncio/utils.py
index 560db9f562..a1a9bb3684 100644
--- a/Lib/test/test_asyncio/utils.py
+++ b/Lib/test/test_asyncio/utils.py
@@ -28,6 +28,7 @@ except ImportError: # pragma: no cover
from asyncio import base_events
from asyncio import events
+from asyncio import format_helpers
from asyncio import futures
from asyncio import tasks
from asyncio.log import logger
@@ -429,7 +430,7 @@ class MockPattern(str):
def get_function_source(func):
- source = events._get_function_source(func)
+ source = format_helpers._get_function_source(func)
if source is None:
raise ValueError("unable to get the source of %r" % (func,))
return source