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

Method test_copy_setstate

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

Source from the content-addressed store, hash-verified

3864 self.assertEqual(y, (x, "foo"))
3865
3866 def test_copy_setstate(self):
3867 # Testing that copy.*copy() correctly uses __setstate__...
3868 import copy
3869 class C(object):
3870 def __init__(self, foo=None):
3871 self.foo = foo
3872 self.__foo = foo
3873 def setfoo(self, foo=None):
3874 self.foo = foo
3875 def getfoo(self):
3876 return self.__foo
3877 def __getstate__(self):
3878 return [self.foo]
3879 def __setstate__(self_, lst):
3880 self.assertEqual(len(lst), 1)
3881 self_.__foo = self_.foo = lst[0]
3882 a = C(42)
3883 a.setfoo(24)
3884 self.assertEqual(a.foo, 24)
3885 self.assertEqual(a.getfoo(), 42)
3886 b = copy.copy(a)
3887 self.assertEqual(b.foo, 24)
3888 self.assertEqual(b.getfoo(), 24)
3889 b = copy.deepcopy(a)
3890 self.assertEqual(b.foo, 24)
3891 self.assertEqual(b.getfoo(), 24)
3892
3893 def test_slices(self):
3894 # 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