MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_unpickle_from_2x

Method test_unpickle_from_2x

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

Source from the content-addressed store, hash-verified

947 self.check_unpickling_error(ValueError, data)
948
949 def test_unpickle_from_2x(self):
950 # Unpickle non-trivial data from Python 2.x.
951 loaded = self.loads(DATA_SET)
952 self.assertEqual(loaded, set([1, 2]))
953 loaded = self.loads(DATA_XRANGE)
954 self.assertEqual(type(loaded), type(range(0)))
955 self.assertEqual(list(loaded), list(range(5)))
956 loaded = self.loads(DATA_COOKIE)
957 self.assertEqual(type(loaded), SimpleCookie)
958 self.assertEqual(list(loaded.keys()), ["key"])
959 self.assertEqual(loaded["key"].value, "value")
960
961 # Exception objects without arguments pickled from 2.x with protocol 2
962 for exc in python2_exceptions_without_args:
963 data = exception_pickle.replace(b'?', exc.__name__.encode("ascii"))
964 loaded = self.loads(data)
965 self.assertIs(type(loaded), exc)
966
967 # StandardError is mapped to Exception, test that separately
968 loaded = self.loads(exception_pickle.replace(b'?', b'StandardError'))
969 self.assertIs(type(loaded), Exception)
970
971 loaded = self.loads(DATA_UEERR)
972 self.assertIs(type(loaded), UnicodeEncodeError)
973 self.assertEqual(loaded.object, "foo")
974 self.assertEqual(loaded.encoding, "ascii")
975 self.assertEqual(loaded.start, 0)
976 self.assertEqual(loaded.end, 1)
977 self.assertEqual(loaded.reason, "bad")
978
979 def test_load_python2_str_as_bytes(self):
980 # 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