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

Method test_helper_astuple_factory

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

Source from the content-addressed store, hash-verified

1906 self.assertEqual(astuple(Parent(Child({1: 2}))), (({1: 2},),))
1907
1908 def test_helper_astuple_factory(self):
1909 @dataclass
1910 class C:
1911 x: int
1912 y: int
1913 NT = namedtuple('NT', 'x y')
1914 def nt(lst):
1915 return NT(*lst)
1916 c = C(1, 2)
1917 t = astuple(c, tuple_factory=nt)
1918 self.assertEqual(t, NT(1, 2))
1919 self.assertIsNot(t, astuple(c, tuple_factory=nt))
1920 c.x = 42
1921 t = astuple(c, tuple_factory=nt)
1922 self.assertEqual(t, NT(42, 2))
1923 self.assertIs(type(t), NT)
1924
1925 def test_helper_astuple_namedtuple(self):
1926 T = namedtuple('T', 'a b c')

Callers

nothing calls this directly

Calls 7

assertEqualMethod · 0.95
assertIsNotMethod · 0.95
assertIsMethod · 0.95
namedtupleFunction · 0.90
astupleFunction · 0.85
NTClass · 0.85
CClass · 0.70

Tested by

no test coverage detected