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

Method test_cancel

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

Source from the content-addressed store, hash-verified

711 loop.close()
712
713 def test_cancel(self):
714
715 def gen():
716 when = yield
717 self.assertAlmostEqual(10.0, when)
718 yield 0
719
720 loop = self.new_test_loop(gen)
721
722 async def task():
723 await asyncio.sleep(10.0)
724 return 12
725
726 t = self.new_task(loop, task())
727 loop.call_soon(t.cancel)
728 with self.assertRaises(asyncio.CancelledError):
729 loop.run_until_complete(t)
730 self.assertTrue(t.done())
731 self.assertTrue(t.cancelled())
732 self.assertFalse(t.cancel())
733
734 def test_cancel_with_message_then_future_result(self):
735 # Test Future.result() after calling cancel() with a message.

Callers

nothing calls this directly

Calls 11

new_taskMethod · 0.95
taskFunction · 0.85
new_test_loopMethod · 0.80
assertTrueMethod · 0.80
assertFalseMethod · 0.80
call_soonMethod · 0.45
assertRaisesMethod · 0.45
run_until_completeMethod · 0.45
doneMethod · 0.45
cancelledMethod · 0.45
cancelMethod · 0.45

Tested by

no test coverage detected