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

Method test_cancel_current_task

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

Source from the content-addressed store, hash-verified

955 self.assertFalse(t.cancelled())
956
957 def test_cancel_current_task(self):
958 loop = asyncio.new_event_loop()
959 self.set_event_loop(loop)
960
961 async def task():
962 t.cancel()
963 self.assertTrue(t._must_cancel) # White-box test.
964 # The sleep should be cancelled immediately.
965 await asyncio.sleep(100)
966 return 12
967
968 t = self.new_task(loop, task())
969 self.assertFalse(t.cancelled())
970 self.assertRaises(
971 asyncio.CancelledError, loop.run_until_complete, t)
972 self.assertTrue(t.done())
973 self.assertTrue(t.cancelled())
974 self.assertFalse(t._must_cancel) # White-box test.
975 self.assertFalse(t.cancel())
976
977 def test_cancel_at_end(self):
978 """coroutine end right after task is cancelled"""

Callers

nothing calls this directly

Calls 10

new_taskMethod · 0.95
taskFunction · 0.85
assertFalseMethod · 0.80
assertTrueMethod · 0.80
new_event_loopMethod · 0.45
set_event_loopMethod · 0.45
cancelledMethod · 0.45
assertRaisesMethod · 0.45
doneMethod · 0.45
cancelMethod · 0.45

Tested by

no test coverage detected