diff options
author | Yury Selivanov <yury@magic.io> | 2017-12-15 01:53:26 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-15 01:53:26 (GMT) |
commit | 19a44f63c738388ef3c8515348b4ffc061dfd627 (patch) | |
tree | 6de5ddd62a1bdee7a90e5fe8fc59348fe7c4f4f8 /Lib/test/test_asyncio/test_tasks.py | |
parent | 41264f1cd4d6066b2797ff07cae465c1e06ff3b2 (diff) | |
download | cpython-19a44f63c738388ef3c8515348b4ffc061dfd627.zip cpython-19a44f63c738388ef3c8515348b4ffc061dfd627.tar.gz cpython-19a44f63c738388ef3c8515348b4ffc061dfd627.tar.bz2 |
bpo-32327: Convert asyncio functions documented as coroutines to coroutines. (#4872)
Diffstat (limited to 'Lib/test/test_asyncio/test_tasks.py')
-rw-r--r-- | Lib/test/test_asyncio/test_tasks.py | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/Lib/test/test_asyncio/test_tasks.py b/Lib/test/test_asyncio/test_tasks.py index 0838ebf..a5563ba 100644 --- a/Lib/test/test_asyncio/test_tasks.py +++ b/Lib/test/test_asyncio/test_tasks.py @@ -2545,19 +2545,26 @@ class RunCoroutineThreadsafeTests(test_utils.TestCase): def test_run_coroutine_threadsafe_task_factory_exception(self): """Test coroutine submission from a tread to an event loop when the task factory raise an exception.""" - # Schedule the target - future = self.loop.run_in_executor( - None, lambda: self.target(advance_coro=True)) - # Set corrupted task factory - self.loop.set_task_factory(lambda loop, coro: wrong_name) + + def task_factory(loop, coro): + raise NameError + + run = self.loop.create_task( + self.loop.run_in_executor( + None, lambda: self.target(advance_coro=True))) + # Set exception handler callback = test_utils.MockCallback() self.loop.set_exception_handler(callback) + + # Set corrupted task factory + self.loop.set_task_factory(task_factory) + # Run event loop with self.assertRaises(NameError) as exc_context: - self.loop.run_until_complete(future) + self.loop.run_until_complete(run) + # Check exceptions - self.assertIn('wrong_name', exc_context.exception.args[0]) self.assertEqual(len(callback.call_args_list), 1) (loop, context), kwargs = callback.call_args self.assertEqual(context['exception'], exc_context.exception) |