mirror of
https://github.com/python/cpython.git
synced 2025-10-14 18:59:46 +00:00
bpo-32327: Convert asyncio functions documented as coroutines to coroutines. (#4872)
This commit is contained in:
parent
41264f1cd4
commit
19a44f63c7
11 changed files with 170 additions and 195 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue