MCPcopy Index your code
hub / github.com/python/cpython / AbstractUnpickleTests

Class AbstractUnpickleTests

Lib/test/pickletester.py:740–1755  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

738
739
740class AbstractUnpickleTests:
741 # Subclass must define self.loads.
742
743 _testdata = create_data()
744
745 def assert_is_copy(self, obj, objcopy, msg=None):
746 """Utility method to verify if two objects are copies of each others.
747 """
748 if msg is None:
749 msg = "{!r} is not a copy of {!r}".format(obj, objcopy)
750 self.assertEqual(obj, objcopy, msg=msg)
751 self.assertIs(type(obj), type(objcopy), msg=msg)
752 if hasattr(obj, '__dict__'):
753 self.assertDictEqual(obj.__dict__, objcopy.__dict__, msg=msg)
754 self.assertIsNot(obj.__dict__, objcopy.__dict__, msg=msg)
755 if hasattr(obj, '__slots__'):
756 self.assertListEqual(obj.__slots__, objcopy.__slots__, msg=msg)
757 for slot in obj.__slots__:
758 self.assertEqual(
759 hasattr(obj, slot), hasattr(objcopy, slot), msg=msg)
760 self.assertEqual(getattr(obj, slot, None),
761 getattr(objcopy, slot, None), msg=msg)
762
763 def check_unpickling_error_strict(self, errors, data):
764 with self.assertRaises(errors):
765 try:
766 self.loads(data)
767 except BaseException as exc:
768 if support.verbose > 1:
769 print('%-32r - %s: %s' %
770 (data, exc.__class__.__name__, exc))
771 raise
772
773 def check_unpickling_error(self, errors, data):
774 with self.subTest(data=data):
775 self.check_unpickling_error_strict(errors, data)
776
777 def test_load_from_data0(self):
778 self.assert_is_copy(self._testdata, self.loads(DATA0))
779
780 def test_load_from_data1(self):
781 self.assert_is_copy(self._testdata, self.loads(DATA1))
782
783 def test_load_from_data2(self):
784 self.assert_is_copy(self._testdata, self.loads(DATA2))
785
786 def test_load_from_data3(self):
787 self.assert_is_copy(self._testdata, self.loads(DATA3))
788
789 def test_load_from_data4(self):
790 self.assert_is_copy(self._testdata, self.loads(DATA4))
791
792 def test_load_classic_instance(self):
793 # See issue5180. Test loading 2.x pickles that
794 # contain an instance of old style class.
795 for X, args in [(C, ()), (D, ('x',)), (E, ())]:
796 xname = X.__name__.encode('ascii')
797 # Protocol 0 (text mode pickle):

Callers

nothing calls this directly

Calls 1

create_dataFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…