MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_namedtuple

Method test_namedtuple

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

Source from the content-addressed store, hash-verified

941 self.assertEqual(attrs(copy.replace(a, x=1, y=2)), (1, 2, 3))
942
943 def test_namedtuple(self):
944 from collections import namedtuple
945 from typing import NamedTuple
946 PointFromCall = namedtuple('Point', 'x y', defaults=(0,))
947 class PointFromInheritance(PointFromCall):
948 pass
949 class PointFromClass(NamedTuple):
950 x: int
951 y: int = 0
952 for Point in (PointFromCall, PointFromInheritance, PointFromClass):
953 with self.subTest(Point=Point):
954 p = Point(11, 22)
955 self.assertIsInstance(p, Point)
956 self.assertEqual(copy.replace(p), (11, 22))
957 self.assertIsInstance(copy.replace(p), Point)
958 self.assertEqual(copy.replace(p, x=1), (1, 22))
959 self.assertEqual(copy.replace(p, y=2), (11, 2))
960 self.assertEqual(copy.replace(p, x=1, y=2), (1, 2))
961 with self.assertRaisesRegex(TypeError, 'unexpected field name'):
962 copy.replace(p, x=1, error=2)
963
964 def test_dataclass(self):
965 from dataclasses import dataclass

Callers

nothing calls this directly

Calls 7

namedtupleFunction · 0.90
subTestMethod · 0.80
assertIsInstanceMethod · 0.80
assertRaisesRegexMethod · 0.80
PointClass · 0.70
assertEqualMethod · 0.45
replaceMethod · 0.45

Tested by

no test coverage detected