Tim Peters | c0c9370 | 2003-02-13 19:30:57 +0000 | [diff] [blame^] | 1 | # test_pickle dumps and loads pickles via pickle.py. |
| 2 | # test_cpickle does the same, but via the cPickle module. |
| 3 | # This test covers the other two cases, making pickles with one module and |
| 4 | # loading them via the other. |
| 5 | |
| 6 | import pickle |
| 7 | import cPickle |
| 8 | import unittest |
| 9 | from cStringIO import StringIO |
| 10 | |
| 11 | from test import test_support |
| 12 | from test.pickletester import AbstractPickleTests |
| 13 | |
| 14 | class DumpCPickle_LoadPickle(AbstractPickleTests): |
| 15 | |
| 16 | error = KeyError |
| 17 | |
| 18 | def dumps(self, arg, proto=0, fast=0): |
| 19 | # Ignore fast |
| 20 | return cPickle.dumps(arg, proto) |
| 21 | |
| 22 | def loads(self, buf): |
| 23 | # Ignore fast |
| 24 | return pickle.loads(buf) |
| 25 | |
| 26 | class DumpPickle_LoadCPickle(AbstractPickleTests): |
| 27 | |
| 28 | error = cPickle.BadPickleGet |
| 29 | |
| 30 | def dumps(self, arg, proto=0, fast=0): |
| 31 | # Ignore fast |
| 32 | return pickle.dumps(arg, proto) |
| 33 | |
| 34 | def loads(self, buf): |
| 35 | # Ignore fast |
| 36 | return cPickle.loads(buf) |
| 37 | |
| 38 | def test_main(): |
| 39 | suite = unittest.TestSuite() |
| 40 | for test in (DumpCPickle_LoadPickle, |
| 41 | DumpPickle_LoadCPickle, |
| 42 | ): |
| 43 | suite.addTest(unittest.makeSuite(test)) |
| 44 | test_support.run_suite(suite) |
| 45 | |
| 46 | if __name__ == "__main__": |
| 47 | test_main() |