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

Method test_load_classic_instance

Lib/test/pickletester.py:792–847  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

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):
798 """
799 0: ( MARK
800 1: i INST '__main__ X' (MARK at 0)
801 13: p PUT 0
802 16: ( MARK
803 17: d DICT (MARK at 16)
804 18: p PUT 1
805 21: b BUILD
806 22: . STOP
807 """
808 pickle0 = (b"(i__main__\n"
809 b"X\n"
810 b"p0\n"
811 b"(dp1\nb.").replace(b'X', xname)
812 self.assert_is_copy(X(*args), self.loads(pickle0))
813
814 # Protocol 1 (binary mode pickle)
815 """
816 0: ( MARK
817 1: c GLOBAL '__main__ X'
818 13: q BINPUT 0
819 15: o OBJ (MARK at 0)
820 16: q BINPUT 1
821 18: } EMPTY_DICT
822 19: q BINPUT 2
823 21: b BUILD
824 22: . STOP
825 """
826 pickle1 = (b'(c__main__\n'
827 b'X\n'
828 b'q\x00oq\x01}q\x02b.').replace(b'X', xname)
829 self.assert_is_copy(X(*args), self.loads(pickle1))
830
831 # Protocol 2 (pickle2 = b'\x80\x02' + pickle1)
832 """
833 0: \x80 PROTO 2
834 2: ( MARK
835 3: c GLOBAL '__main__ X'
836 15: q BINPUT 0
837 17: o OBJ (MARK at 2)
838 18: q BINPUT 1
839 20: } EMPTY_DICT
840 21: q BINPUT 2
841 23: b BUILD
842 24: . STOP
843 """
844 pickle2 = (b'\x80\x02(c__main__\n'
845 b'X\n'
846 b'q\x00oq\x01}q\x02b.').replace(b'X', xname)
847 self.assert_is_copy(X(*args), self.loads(pickle2))
848
849 def test_maxint64(self):

Callers

nothing calls this directly

Calls 5

assert_is_copyMethod · 0.95
loadsMethod · 0.95
XClass · 0.70
encodeMethod · 0.45
replaceMethod · 0.45

Tested by

no test coverage detected