summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_cpickle.py
diff options
context:
space:
mode:
authorJeremy Hylton <jeremy@alum.mit.edu>2001-10-15 21:38:56 (GMT)
committerJeremy Hylton <jeremy@alum.mit.edu>2001-10-15 21:38:56 (GMT)
commit6642653875ff1b2f4bbe9c351c58cfa1c1abbede (patch)
treec5e2e1ea02b0d19199af36ca018c88a92fffe3a5 /Lib/test/test_cpickle.py
parent499ab6a65381256e24bf99ef897e8058c19d54ec (diff)
downloadcpython-6642653875ff1b2f4bbe9c351c58cfa1c1abbede.zip
cpython-6642653875ff1b2f4bbe9c351c58cfa1c1abbede.tar.gz
cpython-6642653875ff1b2f4bbe9c351c58cfa1c1abbede.tar.bz2
Covert pickle tests to use unittest.
Extend tests to cover a few more cases. For cPickle, test several of the undocumented features.
Diffstat (limited to 'Lib/test/test_cpickle.py')
-rw-r--r--Lib/test/test_cpickle.py87
1 files changed, 85 insertions, 2 deletions
diff --git a/Lib/test/test_cpickle.py b/Lib/test/test_cpickle.py
index c03df38..3aebcc0 100644
--- a/Lib/test/test_cpickle.py
+++ b/Lib/test/test_cpickle.py
@@ -1,3 +1,86 @@
import cPickle
-import pickletester
-pickletester.dotest(cPickle)
+from cStringIO import StringIO
+from pickletester import AbstractPickleTests, AbstractPickleModuleTests
+from test_support import run_unittest
+
+class cPickleTests(AbstractPickleTests, AbstractPickleModuleTests):
+
+ def setUp(self):
+ self.dumps = cPickle.dumps
+ self.loads = cPickle.loads
+
+ error = cPickle.BadPickleGet
+ module = cPickle
+
+class cPicklePicklerTests(AbstractPickleTests):
+
+ def dumps(self, arg, bin=0):
+ f = StringIO()
+ p = cPickle.Pickler(f, bin)
+ p.dump(arg)
+ f.seek(0)
+ return f.read()
+
+ def loads(self, buf):
+ f = StringIO(buf)
+ p = cPickle.Unpickler(f)
+ return p.load()
+
+ error = cPickle.BadPickleGet
+
+class cPickleListPicklerTests(AbstractPickleTests):
+
+ def dumps(self, arg, bin=0):
+ p = cPickle.Pickler(bin)
+ p.dump(arg)
+ return p.getvalue()
+
+ def loads(self, *args):
+ f = StringIO(args[0])
+ p = cPickle.Unpickler(f)
+ return p.load()
+
+ error = cPickle.BadPickleGet
+
+class cPickleFastPicklerTests(AbstractPickleTests):
+
+ def dumps(self, arg, bin=0):
+ f = StringIO()
+ p = cPickle.Pickler(f, bin)
+ p.fast = 1
+ p.dump(arg)
+ f.seek(0)
+ return f.read()
+
+ def loads(self, *args):
+ f = StringIO(args[0])
+ p = cPickle.Unpickler(f)
+ return p.load()
+
+ error = cPickle.BadPickleGet
+
+ def test_recursive_list(self):
+ self.assertRaises(ValueError,
+ AbstractPickleTests.test_recursive_list,
+ self)
+
+ def test_recursive_inst(self):
+ self.assertRaises(ValueError,
+ AbstractPickleTests.test_recursive_inst,
+ self)
+
+ def test_recursive_dict(self):
+ self.assertRaises(ValueError,
+ AbstractPickleTests.test_recursive_dict,
+ self)
+
+ def test_recursive_multi(self):
+ self.assertRaises(ValueError,
+ AbstractPickleTests.test_recursive_multi,
+ self)
+
+if __name__ == "__main__":
+ run_unittest(cPickleTests)
+ run_unittest(cPicklePicklerTests)
+ run_unittest(cPickleListPicklerTests)
+ run_unittest(cPickleFastPicklerTests)