Utility method to verify if two objects are copies of each others.
(self, obj, objcopy, msg=None)
| 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(): |
no test coverage detected