summaryrefslogtreecommitdiffstats
path: root/Lib/test/pickletester.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-07-17 08:24:17 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2016-07-17 08:24:17 (GMT)
commitdec25afab1c325c28621dda3ba2b32dbc200c8b3 (patch)
treee1b19ba17d8dab7f94aa6f0053264030b954dc32 /Lib/test/pickletester.py
parent6fd76bceda3fefc5e5814108c5fe819050613d33 (diff)
downloadcpython-dec25afab1c325c28621dda3ba2b32dbc200c8b3.zip
cpython-dec25afab1c325c28621dda3ba2b32dbc200c8b3.tar.gz
cpython-dec25afab1c325c28621dda3ba2b32dbc200c8b3.tar.bz2
Issue #17711: Fixed unpickling by the persistent ID with protocol 0.
Original patch by Alexandre Vassalotti.
Diffstat (limited to 'Lib/test/pickletester.py')
-rw-r--r--Lib/test/pickletester.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/Lib/test/pickletester.py b/Lib/test/pickletester.py
index f252a0a..7922b54 100644
--- a/Lib/test/pickletester.py
+++ b/Lib/test/pickletester.py
@@ -2629,6 +2629,35 @@ class AbstractPersistentPicklerTests(unittest.TestCase):
self.assertEqual(self.load_false_count, 1)
+class AbstractIdentityPersistentPicklerTests(unittest.TestCase):
+
+ def persistent_id(self, obj):
+ return obj
+
+ def persistent_load(self, pid):
+ return pid
+
+ def _check_return_correct_type(self, obj, proto):
+ unpickled = self.loads(self.dumps(obj, proto))
+ self.assertIsInstance(unpickled, type(obj))
+ self.assertEqual(unpickled, obj)
+
+ def test_return_correct_type(self):
+ for proto in protocols:
+ # Protocol 0 supports only ASCII strings.
+ if proto == 0:
+ self._check_return_correct_type("abc", 0)
+ else:
+ for obj in [b"abc\n", "abc\n", -1, -1.1 * 0.1, str]:
+ self._check_return_correct_type(obj, proto)
+
+ def test_protocol0_is_ascii_only(self):
+ non_ascii_str = "\N{EMPTY SET}"
+ self.assertRaises(pickle.PicklingError, self.dumps, non_ascii_str, 0)
+ pickled = pickle.PERSID + non_ascii_str.encode('utf-8') + b'\n.'
+ self.assertRaises(pickle.UnpicklingError, self.loads, pickled)
+
+
class AbstractPicklerUnpicklerObjectTests(unittest.TestCase):
pickler_class = None