diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2016-07-17 08:24:17 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2016-07-17 08:24:17 (GMT) |
commit | dec25afab1c325c28621dda3ba2b32dbc200c8b3 (patch) | |
tree | e1b19ba17d8dab7f94aa6f0053264030b954dc32 /Lib/test/test_pickle.py | |
parent | 6fd76bceda3fefc5e5814108c5fe819050613d33 (diff) | |
download | cpython-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/test_pickle.py')
-rw-r--r-- | Lib/test/test_pickle.py | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/Lib/test/test_pickle.py b/Lib/test/test_pickle.py index ee7a667..d467d52 100644 --- a/Lib/test/test_pickle.py +++ b/Lib/test/test_pickle.py @@ -14,6 +14,7 @@ from test.pickletester import AbstractUnpickleTests from test.pickletester import AbstractPickleTests from test.pickletester import AbstractPickleModuleTests from test.pickletester import AbstractPersistentPicklerTests +from test.pickletester import AbstractIdentityPersistentPicklerTests from test.pickletester import AbstractPicklerUnpicklerObjectTests from test.pickletester import AbstractDispatchTableTests from test.pickletester import BigmemPickleTests @@ -82,10 +83,7 @@ class InMemoryPickleTests(AbstractPickleTests, AbstractUnpickleTests, return pickle.loads(buf, **kwds) -class PyPersPicklerTests(AbstractPersistentPicklerTests): - - pickler = pickle._Pickler - unpickler = pickle._Unpickler +class PersistentPicklerUnpicklerMixin(object): def dumps(self, arg, proto=None): class PersPickler(self.pickler): @@ -94,8 +92,7 @@ class PyPersPicklerTests(AbstractPersistentPicklerTests): f = io.BytesIO() p = PersPickler(f, proto) p.dump(arg) - f.seek(0) - return f.read() + return f.getvalue() def loads(self, buf, **kwds): class PersUnpickler(self.unpickler): @@ -106,6 +103,20 @@ class PyPersPicklerTests(AbstractPersistentPicklerTests): return u.load() +class PyPersPicklerTests(AbstractPersistentPicklerTests, + PersistentPicklerUnpicklerMixin): + + pickler = pickle._Pickler + unpickler = pickle._Unpickler + + +class PyIdPersPicklerTests(AbstractIdentityPersistentPicklerTests, + PersistentPicklerUnpicklerMixin): + + pickler = pickle._Pickler + unpickler = pickle._Unpickler + + class PyPicklerUnpicklerObjectTests(AbstractPicklerUnpicklerObjectTests): pickler_class = pickle._Pickler @@ -144,6 +155,10 @@ if has_c_implementation: pickler = _pickle.Pickler unpickler = _pickle.Unpickler + class CIdPersPicklerTests(PyIdPersPicklerTests): + pickler = _pickle.Pickler + unpickler = _pickle.Unpickler + class CDumpPickle_LoadPickle(PyPicklerTests): pickler = _pickle.Pickler unpickler = pickle._Unpickler @@ -409,11 +424,13 @@ class CompatPickleTests(unittest.TestCase): def test_main(): - tests = [PickleTests, PyUnpicklerTests, PyPicklerTests, PyPersPicklerTests, + tests = [PickleTests, PyUnpicklerTests, PyPicklerTests, + PyPersPicklerTests, PyIdPersPicklerTests, PyDispatchTableTests, PyChainDispatchTableTests, CompatPickleTests] if has_c_implementation: - tests.extend([CUnpicklerTests, CPicklerTests, CPersPicklerTests, + tests.extend([CUnpicklerTests, CPicklerTests, + CPersPicklerTests, CIdPersPicklerTests, CDumpPickle_LoadPickle, DumpPickle_CLoadPickle, PyPicklerUnpicklerObjectTests, CPicklerUnpicklerObjectTests, |