blob: 4db894b8cacc88a0aa391d8fe9b38e189660f3e9 [file] [log] [blame]
Tim Petersc0c93702003-02-13 19:30:57 +00001# 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
6import pickle
7import cPickle
8import unittest
9from cStringIO import StringIO
10
11from test import test_support
12from test.pickletester import AbstractPickleTests
13
14class 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
26class 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
38def 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
46if __name__ == "__main__":
47 test_main()