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

Method test_replace_method

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

Source from the content-addressed store, hash-verified

918 self.assertRaises(TypeError, copy.replace, A())
919
920 def test_replace_method(self):
921 class A:
922 def __new__(cls, x, y=0):
923 self = object.__new__(cls)
924 self.x = x
925 self.y = y
926 return self
927
928 def __init__(self, *args, **kwargs):
929 self.z = self.x + self.y
930
931 def __replace__(self, **changes):
932 x = changes.get('x', self.x)
933 y = changes.get('y', self.y)
934 return type(self)(x, y)
935
936 attrs = attrgetter('x', 'y', 'z')
937 a = A(11, 22)
938 self.assertEqual(attrs(copy.replace(a)), (11, 22, 33))
939 self.assertEqual(attrs(copy.replace(a, x=1)), (1, 22, 23))
940 self.assertEqual(attrs(copy.replace(a, y=2)), (11, 2, 13))
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

Callers

nothing calls this directly

Calls 4

attrgetterClass · 0.90
AClass · 0.70
assertEqualMethod · 0.45
replaceMethod · 0.45

Tested by

no test coverage detected