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

Method test_copy_setstate

Lib/test/test_descr.py:3953–3978  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

3951 self.assertEqual(y, (x, "foo"))
3952
3953 def test_copy_setstate(self):
3954 # Testing that copy.*copy() correctly uses __setstate__...
3955 import copy
3956 class C(object):
3957 def __init__(self, foo=None):
3958 self.foo = foo
3959 self.__foo = foo
3960 def setfoo(self, foo=None):
3961 self.foo = foo
3962 def getfoo(self):
3963 return self.__foo
3964 def __getstate__(self):
3965 return [self.foo]
3966 def __setstate__(self_, lst):
3967 self.assertEqual(len(lst), 1)
3968 self_.__foo = self_.foo = lst[0]
3969 a = C(42)
3970 a.setfoo(24)
3971 self.assertEqual(a.foo, 24)
3972 self.assertEqual(a.getfoo(), 42)
3973 b = copy.copy(a)
3974 self.assertEqual(b.foo, 24)
3975 self.assertEqual(b.getfoo(), 24)
3976 b = copy.deepcopy(a)
3977 self.assertEqual(b.foo, 24)
3978 self.assertEqual(b.getfoo(), 24)
3979
3980 def test_slices(self):
3981 # Testing cases with slices and overridden __getitem__ ...

Callers

nothing calls this directly

Calls 5

setfooMethod · 0.95
getfooMethod · 0.95
CClass · 0.70
assertEqualMethod · 0.45
copyMethod · 0.45

Tested by

no test coverage detected