summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_asyncio
diff options
context:
space:
mode:
authorYury Selivanov <yselivanov@sprymix.com>2015-05-11 18:23:38 (GMT)
committerYury Selivanov <yselivanov@sprymix.com>2015-05-11 18:23:38 (GMT)
commit740169cd24fc108913e4480e98e608f0517a7b8a (patch)
treebf801141261edb778f7957aa777343a6c8cd1978 /Lib/test/test_asyncio
parent37c4f78390ae3f2c839b44939446f783b948d9d3 (diff)
downloadcpython-740169cd24fc108913e4480e98e608f0517a7b8a.zip
cpython-740169cd24fc108913e4480e98e608f0517a7b8a.tar.gz
cpython-740169cd24fc108913e4480e98e608f0517a7b8a.tar.bz2
Sync asyncio changes from the main repo.
Diffstat (limited to 'Lib/test/test_asyncio')
-rw-r--r--Lib/test/test_asyncio/test_base_events.py45
-rw-r--r--Lib/test/test_asyncio/test_tasks.py9
2 files changed, 50 insertions, 4 deletions
diff --git a/Lib/test/test_asyncio/test_base_events.py b/Lib/test/test_asyncio/test_base_events.py
index 9e7c50c..fd864ce 100644
--- a/Lib/test/test_asyncio/test_base_events.py
+++ b/Lib/test/test_asyncio/test_base_events.py
@@ -16,10 +16,15 @@ from asyncio import constants
from asyncio import test_utils
try:
from test import support
- from test.script_helper import assert_python_ok
except ImportError:
from asyncio import test_support as support
- from asyncio.test_support import assert_python_ok
+try:
+ from test.support.script_helper import assert_python_ok
+except ImportError:
+ try:
+ from test.script_helper import assert_python_ok
+ except ImportError:
+ from asyncio.test_support import assert_python_ok
MOCK_ANY = mock.ANY
@@ -623,6 +628,42 @@ class BaseEventLoopTests(test_utils.TestCase):
self.assertIs(type(_context['context']['exception']),
ZeroDivisionError)
+ def test_set_task_factory_invalid(self):
+ with self.assertRaisesRegex(
+ TypeError, 'task factory must be a callable or None'):
+
+ self.loop.set_task_factory(1)
+
+ self.assertIsNone(self.loop.get_task_factory())
+
+ def test_set_task_factory(self):
+ self.loop._process_events = mock.Mock()
+
+ class MyTask(asyncio.Task):
+ pass
+
+ @asyncio.coroutine
+ def coro():
+ pass
+
+ factory = lambda loop, coro: MyTask(coro, loop=loop)
+
+ self.assertIsNone(self.loop.get_task_factory())
+ self.loop.set_task_factory(factory)
+ self.assertIs(self.loop.get_task_factory(), factory)
+
+ task = self.loop.create_task(coro())
+ self.assertTrue(isinstance(task, MyTask))
+ self.loop.run_until_complete(task)
+
+ self.loop.set_task_factory(None)
+ self.assertIsNone(self.loop.get_task_factory())
+
+ task = self.loop.create_task(coro())
+ self.assertTrue(isinstance(task, asyncio.Task))
+ self.assertFalse(isinstance(task, MyTask))
+ self.loop.run_until_complete(task)
+
def test_env_var_debug(self):
code = '\n'.join((
'import asyncio',
diff --git a/Lib/test/test_asyncio/test_tasks.py b/Lib/test/test_asyncio/test_tasks.py
index ab61462..5b49e76 100644
--- a/Lib/test/test_asyncio/test_tasks.py
+++ b/Lib/test/test_asyncio/test_tasks.py
@@ -15,10 +15,15 @@ from asyncio import coroutines
from asyncio import test_utils
try:
from test import support
- from test.script_helper import assert_python_ok
except ImportError:
from asyncio import test_support as support
- from asyncio.test_support import assert_python_ok
+try:
+ from test.support.script_helper import assert_python_ok
+except ImportError:
+ try:
+ from test.script_helper import assert_python_ok
+ except ImportError:
+ from asyncio.test_support import assert_python_ok
PY34 = (sys.version_info >= (3, 4))