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

Method test_class_var_frozen

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

Source from the content-addressed store, hash-verified

1229 self.assertEqual(C.x, 10)
1230
1231 def test_class_var_frozen(self):
1232 # Make sure ClassVars work even if we're frozen.
1233 @dataclass(frozen=True)
1234 class C:
1235 x: int
1236 y: int = 10
1237 z: ClassVar[int] = 1000
1238 w: ClassVar[int] = 2000
1239 t: ClassVar[int] = 3000
1240
1241 c = C(5)
1242 self.assertEqual(repr(C(5)), 'TestCase.test_class_var_frozen.<locals>.C(x=5, y=10)')
1243 self.assertEqual(len(fields(C)), 2) # We have 2 fields
1244 self.assertEqual(len(C.__annotations__), 5) # And 3 ClassVars
1245 self.assertEqual(c.z, 1000)
1246 self.assertEqual(c.w, 2000)
1247 self.assertEqual(c.t, 3000)
1248 # We can still modify the ClassVar, it's only instances that are
1249 # frozen.
1250 C.z += 1
1251 self.assertEqual(c.z, 1001)
1252 c = C(20)
1253 self.assertEqual((c.x, c.y), (20, 10))
1254 self.assertEqual(c.z, 1001)
1255 self.assertEqual(c.w, 2000)
1256 self.assertEqual(c.t, 3000)
1257
1258 def test_init_var_no_default(self):
1259 # If an InitVar has no default value, it should not be set on the class.

Callers

nothing calls this directly

Calls 3

assertEqualMethod · 0.95
fieldsFunction · 0.85
CClass · 0.70

Tested by

no test coverage detected