bpo-32327: Convert asyncio functions documented as coroutines to coroutines. (#4872)

This commit is contained in:
Yury Selivanov 2017-12-14 20:53:26 -05:00 committed by GitHub
parent 41264f1cd4
commit 19a44f63c7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 170 additions and 195 deletions

View file

@ -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)