MCPcopy Index your code
hub / github.com/python/cpython / test_cancel_task_catching

Method test_cancel_task_catching

Lib/test/test_asyncio/test_tasks.py:904–925  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

902 self.assertTrue(t.cancelled())
903
904 def test_cancel_task_catching(self):
905 fut1 = self.new_future(self.loop)
906 fut2 = self.new_future(self.loop)
907
908 async def task():
909 await fut1
910 try:
911 await fut2
912 except asyncio.CancelledError:
913 return 42
914
915 t = self.new_task(self.loop, task())
916 test_utils.run_briefly(self.loop)
917 self.assertIs(t._fut_waiter, fut1) # White-box test.
918 fut1.set_result(None)
919 test_utils.run_briefly(self.loop)
920 self.assertIs(t._fut_waiter, fut2) # White-box test.
921 t.cancel()
922 self.assertTrue(fut2.cancelled())
923 res = self.loop.run_until_complete(t)
924 self.assertEqual(res, 42)
925 self.assertFalse(t.cancelled())
926
927 def test_cancel_task_ignoring(self):
928 fut1 = self.new_future(self.loop)

Callers

nothing calls this directly

Calls 12

new_futureMethod · 0.95
new_taskMethod · 0.95
taskFunction · 0.85
run_brieflyMethod · 0.80
assertTrueMethod · 0.80
assertFalseMethod · 0.80
assertIsMethod · 0.45
set_resultMethod · 0.45
cancelMethod · 0.45
cancelledMethod · 0.45
run_until_completeMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected