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

Method test_shield_effect

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

Source from the content-addressed store, hash-verified

2163 self.assertEqual(res, 42)
2164
2165 def test_shield_effect(self):
2166 # Cancelling outer() does not affect inner().
2167 proof = 0
2168 waiter = self.new_future(self.loop)
2169
2170 async def inner():
2171 nonlocal proof
2172 await waiter
2173 proof += 1
2174
2175 async def outer():
2176 nonlocal proof
2177 await asyncio.shield(inner())
2178 proof += 100
2179
2180 f = asyncio.ensure_future(outer(), loop=self.loop)
2181 test_utils.run_briefly(self.loop)
2182 f.cancel()
2183 with self.assertRaises(asyncio.CancelledError):
2184 self.loop.run_until_complete(f)
2185 waiter.set_result(None)
2186 test_utils.run_briefly(self.loop)
2187 self.assertEqual(proof, 1)
2188
2189 def test_shield_gather(self):
2190 child1 = self.new_future(self.loop)

Callers

nothing calls this directly

Calls 8

new_futureMethod · 0.95
run_brieflyMethod · 0.80
outerFunction · 0.50
cancelMethod · 0.45
assertRaisesMethod · 0.45
run_until_completeMethod · 0.45
set_resultMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected