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

Method test_dataclasses_pickleable

Lib/test/test_dataclasses/__init__.py:2186–2213  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

2184 self.assertEqual(Child.__mro__, (Child, Parent, Generic, object))
2185
2186 def test_dataclasses_pickleable(self):
2187 global P, Q, R
2188 @dataclass
2189 class P:
2190 x: int
2191 y: int = 0
2192 @dataclass
2193 class Q:
2194 x: int
2195 y: int = field(default=0, init=False)
2196 @dataclass
2197 class R:
2198 x: int
2199 y: List[int] = field(default_factory=list)
2200 q = Q(1)
2201 q.y = 2
2202 samples = [P(1), P(1, 2), Q(1), q, R(1), R(1, [2, 3, 4])]
2203 for sample in samples:
2204 for proto in range(pickle.HIGHEST_PROTOCOL + 1):
2205 with self.subTest(sample=sample, proto=proto):
2206 new_sample = pickle.loads(pickle.dumps(sample, proto))
2207 self.assertEqual(sample.x, new_sample.x)
2208 self.assertEqual(sample.y, new_sample.y)
2209 self.assertIsNot(sample, new_sample)
2210 new_sample.x = 42
2211 another_new_sample = pickle.loads(pickle.dumps(new_sample, proto))
2212 self.assertEqual(new_sample.x, another_new_sample.x)
2213 self.assertEqual(sample.y, another_new_sample.y)
2214
2215 def test_dataclasses_qualnames(self):
2216 @dataclass(order=True, unsafe_hash=True, frozen=True)

Callers

nothing calls this directly

Calls 8

subTestMethod · 0.95
assertEqualMethod · 0.95
assertIsNotMethod · 0.95
QClass · 0.70
PClass · 0.70
RClass · 0.70
loadsMethod · 0.45
dumpsMethod · 0.45

Tested by

no test coverage detected