diff options
author | Jeremy Hylton <jeremy@alum.mit.edu> | 2002-11-13 22:01:27 (GMT) |
---|---|---|
committer | Jeremy Hylton <jeremy@alum.mit.edu> | 2002-11-13 22:01:27 (GMT) |
commit | 5e0f4e73a963a69b0ecd16e2477d6cd2cacef6c9 (patch) | |
tree | 44ef072c63525fcb6ff5055907de583bc9f459a2 /Lib/test/test_pickle.py | |
parent | 0e1183ddffd1363ffce6b4792f5b82a8d3a9e5a8 (diff) | |
download | cpython-5e0f4e73a963a69b0ecd16e2477d6cd2cacef6c9.zip cpython-5e0f4e73a963a69b0ecd16e2477d6cd2cacef6c9.tar.gz cpython-5e0f4e73a963a69b0ecd16e2477d6cd2cacef6c9.tar.bz2 |
Remove inst_persistent_id() WANNI (we ain't never needed it).
Add some simple tests of the persistence hooks.
Diffstat (limited to 'Lib/test/test_pickle.py')
-rw-r--r-- | Lib/test/test_pickle.py | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/Lib/test/test_pickle.py b/Lib/test/test_pickle.py index 87c73c2..d61f29b 100644 --- a/Lib/test/test_pickle.py +++ b/Lib/test/test_pickle.py @@ -1,7 +1,8 @@ import pickle import unittest from cStringIO import StringIO -from test.pickletester import AbstractPickleTests, AbstractPickleModuleTests +from test.pickletester import AbstractPickleTests, AbstractPickleModuleTests, \ + AbstractPersistentPicklerTests from test import test_support class PickleTests(AbstractPickleTests, AbstractPickleModuleTests): @@ -29,11 +30,32 @@ class PicklerTests(AbstractPickleTests): u = pickle.Unpickler(f) return u.load() +class PersPicklerTests(AbstractPersistentPicklerTests): + + def dumps(self, arg, bin=0): + class PersPickler(pickle.Pickler): + def persistent_id(subself, obj): + return self.persistent_id(obj) + f = StringIO() + p = PersPickler(f, bin) + p.dump(arg) + f.seek(0) + return f.read() + + def loads(self, buf): + class PersUnpickler(pickle.Unpickler): + def persistent_load(subself, obj): + return self.persistent_load(obj) + f = StringIO(buf) + u = PersUnpickler(f) + return u.load() + def test_main(): loader = unittest.TestLoader() suite = unittest.TestSuite() suite.addTest(loader.loadTestsFromTestCase(PickleTests)) suite.addTest(loader.loadTestsFromTestCase(PicklerTests)) + suite.addTest(loader.loadTestsFromTestCase(PersPicklerTests)) test_support.run_suite(suite) if __name__ == "__main__": |