diff options
author | Tim Peters <tim.peters@gmail.com> | 2003-02-13 19:30:57 (GMT) |
---|---|---|
committer | Tim Peters <tim.peters@gmail.com> | 2003-02-13 19:30:57 (GMT) |
commit | c0c9370985f393436013eb70d724d7ff1e69c74d (patch) | |
tree | d0d6859350696cacc6b7db87bf10e782663ba0ee /Lib/test/test_xpickle.py | |
parent | 729765079e342536a094fd447e81812755760cd3 (diff) | |
download | cpython-c0c9370985f393436013eb70d724d7ff1e69c74d.zip cpython-c0c9370985f393436013eb70d724d7ff1e69c74d.tar.gz cpython-c0c9370985f393436013eb70d724d7ff1e69c74d.tar.bz2 |
We didn't have any tests making pickles with one of {pickle, cPickle},
and loading them via the other, except for the special cases of this
Guido added to test_datetime.py for datetime module objects. The new
test_xpickle.py tries all of pickletester's AbstractPickleTests in
both x-module ways.
Diffstat (limited to 'Lib/test/test_xpickle.py')
-rw-r--r-- | Lib/test/test_xpickle.py | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/Lib/test/test_xpickle.py b/Lib/test/test_xpickle.py new file mode 100644 index 0000000..4db894b --- /dev/null +++ b/Lib/test/test_xpickle.py @@ -0,0 +1,47 @@ +# test_pickle dumps and loads pickles via pickle.py. +# test_cpickle does the same, but via the cPickle module. +# This test covers the other two cases, making pickles with one module and +# loading them via the other. + +import pickle +import cPickle +import unittest +from cStringIO import StringIO + +from test import test_support +from test.pickletester import AbstractPickleTests + +class DumpCPickle_LoadPickle(AbstractPickleTests): + + error = KeyError + + def dumps(self, arg, proto=0, fast=0): + # Ignore fast + return cPickle.dumps(arg, proto) + + def loads(self, buf): + # Ignore fast + return pickle.loads(buf) + +class DumpPickle_LoadCPickle(AbstractPickleTests): + + error = cPickle.BadPickleGet + + def dumps(self, arg, proto=0, fast=0): + # Ignore fast + return pickle.dumps(arg, proto) + + def loads(self, buf): + # Ignore fast + return cPickle.loads(buf) + +def test_main(): + suite = unittest.TestSuite() + for test in (DumpCPickle_LoadPickle, + DumpPickle_LoadCPickle, + ): + suite.addTest(unittest.makeSuite(test)) + test_support.run_suite(suite) + +if __name__ == "__main__": + test_main() |