Utility method to verify if two objects are copies of each others.
(self, obj, objcopy, msg=None)
| 836 | _testdata = create_data() |
| 837 | |
| 838 | def assert_is_copy(self, obj, objcopy, msg=None): |
| 839 | """Utility method to verify if two objects are copies of each others. |
| 840 | """ |
| 841 | if msg is None: |
| 842 | msg = "{!r} is not a copy of {!r}".format(obj, objcopy) |
| 843 | self.assertEqual(obj, objcopy, msg=msg) |
| 844 | self.assertIs(type(obj), type(objcopy), msg=msg) |
| 845 | if hasattr(obj, '__dict__'): |
| 846 | self.assertDictEqual(obj.__dict__, objcopy.__dict__, msg=msg) |
| 847 | self.assertIsNot(obj.__dict__, objcopy.__dict__, msg=msg) |
| 848 | if hasattr(obj, '__slots__'): |
| 849 | self.assertListEqual(obj.__slots__, objcopy.__slots__, msg=msg) |
| 850 | for slot in obj.__slots__: |
| 851 | self.assertEqual( |
| 852 | hasattr(obj, slot), hasattr(objcopy, slot), msg=msg) |
| 853 | self.assertEqual(getattr(obj, slot, None), |
| 854 | getattr(objcopy, slot, None), msg=msg) |
| 855 | |
| 856 | def check_unpickling_error(self, errors, data): |
| 857 | with self.subTest(data=data), \ |
no test coverage detected