diff options
author | Guido van Rossum <guido@python.org> | 2015-10-05 23:23:13 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2015-10-05 23:23:13 (GMT) |
commit | 5db034acfaa79447cb5c310f6ad7071737474027 (patch) | |
tree | 10e7f0bb14217141160e64c94fdf957785ec7637 /Lib/test/test_asyncio | |
parent | f0ccf02e5609890ffb1f928e1a1f74ebde1b5af7 (diff) | |
parent | 601953b67958572162d0ab7d3f24c07340ad9dbb (diff) | |
download | cpython-5db034acfaa79447cb5c310f6ad7071737474027.zip cpython-5db034acfaa79447cb5c310f6ad7071737474027.tar.gz cpython-5db034acfaa79447cb5c310f6ad7071737474027.tar.bz2 |
Docs and one small improvement for issue #25304, by Vincent Michel. (Merge 3.4->3.5.)
Diffstat (limited to 'Lib/test/test_asyncio')
-rw-r--r-- | Lib/test/test_asyncio/test_tasks.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/Lib/test/test_asyncio/test_tasks.py b/Lib/test/test_asyncio/test_tasks.py index 8ec5d9c..9772bae 100644 --- a/Lib/test/test_asyncio/test_tasks.py +++ b/Lib/test/test_asyncio/test_tasks.py @@ -2166,6 +2166,27 @@ class RunCoroutineThreadsafeTests(test_utils.TestCase): with self.assertRaises(asyncio.CancelledError): self.loop.run_until_complete(future) + 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.""" + # Clear the time generator + asyncio.ensure_future(self.add(1, 2), loop=self.loop) + # Schedule the target + future = self.loop.run_in_executor(None, self.target) + # Set corrupted task factory + self.loop.set_task_factory(lambda loop, coro: wrong_name) + # Set exception handler + callback = test_utils.MockCallback() + self.loop.set_exception_handler(callback) + # Run event loop + with self.assertRaises(NameError) as exc_context: + self.loop.run_until_complete(future) + # 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) + if __name__ == '__main__': unittest.main() |