diff options
| author | Guido van Rossum <guido@dropbox.com> | 2015-10-05 23:26:00 (GMT) |
|---|---|---|
| committer | Guido van Rossum <guido@dropbox.com> | 2015-10-05 23:26:00 (GMT) |
| commit | 8ab4169f5a267d6942aebf377a4756ea3ddab17b (patch) | |
| tree | 529ed07e8494b5d46e7b41e39fbf20606a7b0ab0 /Lib/test/test_asyncio/test_tasks.py | |
| parent | f536386ca95ccd2f6798435887ffb0a137d8359e (diff) | |
| parent | 5db034acfaa79447cb5c310f6ad7071737474027 (diff) | |
| download | cpython-8ab4169f5a267d6942aebf377a4756ea3ddab17b.zip cpython-8ab4169f5a267d6942aebf377a4756ea3ddab17b.tar.gz cpython-8ab4169f5a267d6942aebf377a4756ea3ddab17b.tar.bz2 | |
Docs and one small improvement for issue #25304, by Vincent Michel. (Merge 3.5->3.6.)
Diffstat (limited to 'Lib/test/test_asyncio/test_tasks.py')
| -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() |
