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

Method test_dataclass

Lib/test/test_copy.py:994–1008  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

992 copy.replace(p, x=1, error=2)
993
994 def test_dataclass(self):
995 from dataclasses import dataclass
996 @dataclass
997 class C:
998 x: int
999 y: int = 0
1000
1001 attrs = attrgetter('x', 'y')
1002 c = C(11, 22)
1003 self.assertEqual(attrs(copy.replace(c)), (11, 22))
1004 self.assertEqual(attrs(copy.replace(c, x=1)), (1, 22))
1005 self.assertEqual(attrs(copy.replace(c, y=2)), (11, 2))
1006 self.assertEqual(attrs(copy.replace(c, x=1, y=2)), (1, 2))
1007 with self.assertRaisesRegex(TypeError, 'unexpected keyword argument'):
1008 copy.replace(c, x=1, error=2)
1009
1010
1011class MiscTestCase(unittest.TestCase):

Callers

nothing calls this directly

Calls 5

attrgetterClass · 0.90
assertRaisesRegexMethod · 0.80
CClass · 0.70
assertEqualMethod · 0.45
replaceMethod · 0.45

Tested by

no test coverage detected