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

Method _assert_is_copy

Lib/test/test_descr.py:5479–5503  ·  view source on GitHub ↗

Utility method to verify if two objects are copies of each others.

(self, obj, objcopy, msg=None)

Source from the content-addressed store, hash-verified

5477 self._check_reduce(protocol, Picky(), state=state)
5478
5479 def _assert_is_copy(self, obj, objcopy, msg=None):
5480 """Utility method to verify if two objects are copies of each others.
5481 """
5482 if msg is None:
5483 msg = "{!r} is not a copy of {!r}".format(obj, objcopy)
5484 if type(obj).__repr__ is object.__repr__:
5485 # We have this limitation for now because we use the object's repr
5486 # to help us verify that the two objects are copies. This allows
5487 # us to delegate the non-generic verification logic to the objects
5488 # themselves.
5489 raise ValueError("object passed to _assert_is_copy must " +
5490 "override the __repr__ method.")
5491 self.assertIsNot(obj, objcopy, msg=msg)
5492 self.assertIs(type(obj), type(objcopy), msg=msg)
5493 if hasattr(obj, '__dict__'):
5494 self.assertDictEqual(obj.__dict__, objcopy.__dict__, msg=msg)
5495 self.assertIsNot(obj.__dict__, objcopy.__dict__, msg=msg)
5496 if hasattr(obj, '__slots__'):
5497 self.assertListEqual(obj.__slots__, objcopy.__slots__, msg=msg)
5498 for slot in obj.__slots__:
5499 self.assertEqual(
5500 hasattr(obj, slot), hasattr(objcopy, slot), msg=msg)
5501 self.assertEqual(getattr(obj, slot, None),
5502 getattr(objcopy, slot, None), msg=msg)
5503 self.assertEqual(repr(obj), repr(objcopy), msg=msg)
5504
5505 @staticmethod
5506 def _generate_pickle_copiers():

Callers 2

test_pickle_slotsMethod · 0.95
test_reduce_copyingMethod · 0.95

Calls 9

hasattrFunction · 0.85
getattrFunction · 0.85
reprFunction · 0.85
assertIsNotMethod · 0.80
assertDictEqualMethod · 0.80
assertListEqualMethod · 0.80
formatMethod · 0.45
assertIsMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected