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

Method test_protocols_pickleable

Lib/test/test_typing.py:4256–4283  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

4254 self.assertEqual(Alias, Alias2)
4255
4256 def test_protocols_pickleable(self):
4257 global P, CP # pickle wants to reference the class by name
4258 T = TypeVar('T')
4259
4260 @runtime_checkable
4261 class P(Protocol[T]):
4262 x = 1
4263
4264 class CP(P[int]):
4265 pass
4266
4267 c = CP()
4268 c.foo = 42
4269 c.bar = 'abc'
4270 for proto in range(pickle.HIGHEST_PROTOCOL + 1):
4271 z = pickle.dumps(c, proto)
4272 x = pickle.loads(z)
4273 self.assertEqual(x.foo, 42)
4274 self.assertEqual(x.bar, 'abc')
4275 self.assertEqual(x.x, 1)
4276 self.assertEqual(x.__dict__, {'foo': 42, 'bar': 'abc'})
4277 s = pickle.dumps(P, proto)
4278 D = pickle.loads(s)
4279
4280 class E:
4281 x = 1
4282
4283 self.assertIsInstance(E(), D)
4284
4285 def test_runtime_checkable_with_match_args(self):
4286 @runtime_checkable

Callers

nothing calls this directly

Calls 6

CPClass · 0.85
assertIsInstanceMethod · 0.80
EClass · 0.70
dumpsMethod · 0.45
loadsMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected