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

Method test_unpickle_from_2x

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

Source from the content-addressed store, hash-verified

857 self.check_unpickling_error(ValueError, data)
858
859 def test_unpickle_from_2x(self):
860 # Unpickle non-trivial data from Python 2.x.
861 loaded = self.loads(DATA_SET)
862 self.assertEqual(loaded, set([1, 2]))
863 loaded = self.loads(DATA_XRANGE)
864 self.assertEqual(type(loaded), type(range(0)))
865 self.assertEqual(list(loaded), list(range(5)))
866 loaded = self.loads(DATA_COOKIE)
867 self.assertEqual(type(loaded), SimpleCookie)
868 self.assertEqual(list(loaded.keys()), ["key"])
869 self.assertEqual(loaded["key"].value, "value")
870
871 # Exception objects without arguments pickled from 2.x with protocol 2
872 for exc in python2_exceptions_without_args:
873 data = exception_pickle.replace(b'?', exc.__name__.encode("ascii"))
874 loaded = self.loads(data)
875 self.assertIs(type(loaded), exc)
876
877 # StandardError is mapped to Exception, test that separately
878 loaded = self.loads(exception_pickle.replace(b'?', b'StandardError'))
879 self.assertIs(type(loaded), Exception)
880
881 loaded = self.loads(DATA_UEERR)
882 self.assertIs(type(loaded), UnicodeEncodeError)
883 self.assertEqual(loaded.object, "foo")
884 self.assertEqual(loaded.encoding, "ascii")
885 self.assertEqual(loaded.start, 0)
886 self.assertEqual(loaded.end, 1)
887 self.assertEqual(loaded.reason, "bad")
888
889 def test_load_python2_str_as_bytes(self):
890 # From Python 2: pickle.dumps('a\x00\xa0', protocol=0)

Callers

nothing calls this directly

Calls 8

loadsMethod · 0.95
setFunction · 0.85
listClass · 0.85
assertEqualMethod · 0.45
keysMethod · 0.45
replaceMethod · 0.45
encodeMethod · 0.45
assertIsMethod · 0.45

Tested by

no test coverage detected