MCPcopy Create free account
hub / github.com/MagicStack/contextvars / test_context_getset_3

Method test_context_getset_3

tests/test_basics.py:268–290  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

266
267 @isolated_context
268 def test_context_getset_3(self):
269 c = contextvars.ContextVar('c', default=42)
270 ctx = contextvars.Context()
271
272 def fun():
273 self.assertEqual(c.get(), 42)
274 with self.assertRaises(KeyError):
275 ctx[c]
276 self.assertIsNone(ctx.get(c))
277 self.assertEqual(ctx.get(c, 'spam'), 'spam')
278 self.assertNotIn(c, ctx)
279 self.assertEqual(list(ctx.keys()), [])
280
281 t = c.set(1)
282 self.assertEqual(list(ctx.keys()), [c])
283 self.assertEqual(ctx[c], 1)
284
285 c.reset(t)
286 self.assertEqual(list(ctx.keys()), [])
287 with self.assertRaises(KeyError):
288 ctx[c]
289
290 ctx.run(fun)
291
292 @isolated_context
293 def test_context_getset_4(self):

Callers

nothing calls this directly

Calls 1

runMethod · 0.95

Tested by

no test coverage detected