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 |
Tim Peters | c0c9370 | 2003-02-13 19:30:57 +0000 | [diff] [blame] | 8 | |
| 9 | from test import test_support |
| 10 | from test.pickletester import AbstractPickleTests |
| 11 | |
| 12 | class DumpCPickle_LoadPickle(AbstractPickleTests): |
| 13 | |
| 14 | error = KeyError |
| 15 | |
| 16 | def dumps(self, arg, proto=0, fast=0): |
| 17 | # Ignore fast |
| 18 | return cPickle.dumps(arg, proto) |
| 19 | |
| 20 | def loads(self, buf): |
| 21 | # Ignore fast |
| 22 | return pickle.loads(buf) |
| 23 | |
| 24 | class DumpPickle_LoadCPickle(AbstractPickleTests): |
| 25 | |
| 26 | error = cPickle.BadPickleGet |
| 27 | |
| 28 | def dumps(self, arg, proto=0, fast=0): |
| 29 | # Ignore fast |
| 30 | return pickle.dumps(arg, proto) |
| 31 | |
| 32 | def loads(self, buf): |
| 33 | # Ignore fast |
| 34 | return cPickle.loads(buf) |
| 35 | |
| 36 | def test_main(): |
Walter Dörwald | 21d3a32 | 2003-05-01 17:45:56 +0000 | [diff] [blame] | 37 | test_support.run_unittest( |
| 38 | DumpCPickle_LoadPickle, |
| 39 | DumpPickle_LoadCPickle |
| 40 | ) |
Tim Peters | c0c9370 | 2003-02-13 19:30:57 +0000 | [diff] [blame] | 41 | |
| 42 | if __name__ == "__main__": |
| 43 | test_main() |