Utility method to verify if two objects are copies of each others.
(self, obj, objcopy, msg=None)
| 5714 | self._check_reduce(protocol, Picky(), state=state) |
| 5715 | |
| 5716 | def _assert_is_copy(self, obj, objcopy, msg=None): |
| 5717 | """Utility method to verify if two objects are copies of each others. |
| 5718 | """ |
| 5719 | if msg is None: |
| 5720 | msg = "{!r} is not a copy of {!r}".format(obj, objcopy) |
| 5721 | if type(obj).__repr__ is object.__repr__: |
| 5722 | # We have this limitation for now because we use the object's repr |
| 5723 | # to help us verify that the two objects are copies. This allows |
| 5724 | # us to delegate the non-generic verification logic to the objects |
| 5725 | # themselves. |
| 5726 | raise ValueError("object passed to _assert_is_copy must " + |
| 5727 | "override the __repr__ method.") |
| 5728 | self.assertIsNot(obj, objcopy, msg=msg) |
| 5729 | self.assertIs(type(obj), type(objcopy), msg=msg) |
| 5730 | if hasattr(obj, '__dict__'): |
| 5731 | self.assertDictEqual(obj.__dict__, objcopy.__dict__, msg=msg) |
| 5732 | self.assertIsNot(obj.__dict__, objcopy.__dict__, msg=msg) |
| 5733 | if hasattr(obj, '__slots__'): |
| 5734 | self.assertListEqual(obj.__slots__, objcopy.__slots__, msg=msg) |
| 5735 | for slot in obj.__slots__: |
| 5736 | self.assertEqual( |
| 5737 | hasattr(obj, slot), hasattr(objcopy, slot), msg=msg) |
| 5738 | self.assertEqual(getattr(obj, slot, None), |
| 5739 | getattr(objcopy, slot, None), msg=msg) |
| 5740 | self.assertEqual(repr(obj), repr(objcopy), msg=msg) |
| 5741 | |
| 5742 | @staticmethod |
| 5743 | def _generate_pickle_copiers(): |
no test coverage detected