blob: cc458ad585e2c0d88d910caeffd562a62ce0b336 [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
Tim Petersc0c93702003-02-13 19:30:57 +00009
10from test import test_support
11from test.pickletester import AbstractPickleTests
12
13class DumpCPickle_LoadPickle(AbstractPickleTests):
14
15 error = KeyError
16
17 def dumps(self, arg, proto=0, fast=0):
18 # Ignore fast
19 return cPickle.dumps(arg, proto)
20
21 def loads(self, buf):
22 # Ignore fast
23 return pickle.loads(buf)
24
25class DumpPickle_LoadCPickle(AbstractPickleTests):
26
27 error = cPickle.BadPickleGet
28
29 def dumps(self, arg, proto=0, fast=0):
30 # Ignore fast
31 return pickle.dumps(arg, proto)
32
33 def loads(self, buf):
34 # Ignore fast
35 return cPickle.loads(buf)
36
37def test_main():
38 suite = unittest.TestSuite()
39 for test in (DumpCPickle_LoadPickle,
40 DumpPickle_LoadCPickle,
41 ):
Tim Petersf2715e02003-02-19 02:35:07 +000042 suite.addTest(unittest.makeSuite(test))
Tim Petersc0c93702003-02-13 19:30:57 +000043 test_support.run_suite(suite)
44
45if __name__ == "__main__":
46 test_main()