diff options
author | Guido van Rossum <guido@python.org> | 2007-07-20 00:22:32 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2007-07-20 00:22:32 (GMT) |
commit | 99603b0c1edb4b8ca2a30fa90470170b959321ee (patch) | |
tree | f0fef33a9c03529354c01f5fd374fd36ebc024d7 /Lib/test | |
parent | be6fe5476cc3233ac20e02c0063355a5884663f7 (diff) | |
download | cpython-99603b0c1edb4b8ca2a30fa90470170b959321ee.zip cpython-99603b0c1edb4b8ca2a30fa90470170b959321ee.tar.gz cpython-99603b0c1edb4b8ca2a30fa90470170b959321ee.tar.bz2 |
Getting rid of cPickle. Mmm, feels good!
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/pickletester.py | 6 | ||||
-rw-r--r-- | Lib/test/test_bool.py | 41 | ||||
-rw-r--r-- | Lib/test/test_bytes.py | 12 | ||||
-rw-r--r-- | Lib/test/test_cpickle.py | 103 | ||||
-rw-r--r-- | Lib/test/test_descr.py | 31 | ||||
-rw-r--r-- | Lib/test/test_exceptions.py | 8 | ||||
-rw-r--r-- | Lib/test/test_re.py | 6 | ||||
-rw-r--r-- | Lib/test/test_slice.py | 2 | ||||
-rw-r--r-- | Lib/test/test_xpickle.py | 44 |
9 files changed, 9 insertions, 244 deletions
diff --git a/Lib/test/pickletester.py b/Lib/test/pickletester.py index 927939e..7bff76f 100644 --- a/Lib/test/pickletester.py +++ b/Lib/test/pickletester.py @@ -1,9 +1,5 @@ import unittest import pickle -try: - import cPickle -except ImportError: - cPickle = None import pickletools import copy_reg @@ -12,8 +8,6 @@ from test.test_support import TestFailed, TESTFN, run_with_locale # Tests that try a number of pickle protocols should have a # for proto in protocols: # kind of outer loop. -if cPickle is not None: - assert pickle.HIGHEST_PROTOCOL == cPickle.HIGHEST_PROTOCOL == 2 protocols = range(pickle.HIGHEST_PROTOCOL + 1) diff --git a/Lib/test/test_bool.py b/Lib/test/test_bool.py index 8006370..7a9022e 100644 --- a/Lib/test/test_bool.py +++ b/Lib/test/test_bool.py @@ -268,34 +268,6 @@ class BoolTest(unittest.TestCase): self.assertIs(pickle.loads(pickle.dumps(True, True)), True) self.assertIs(pickle.loads(pickle.dumps(False, True)), False) - def test_cpickle(self): - try: - import cPickle - except ImportError: - return # Just ignore this if cPickle doesn't exist - - self.assertIs(cPickle.loads(cPickle.dumps(True)), True) - self.assertIs(cPickle.loads(cPickle.dumps(False)), False) - self.assertIs(cPickle.loads(cPickle.dumps(True, True)), True) - self.assertIs(cPickle.loads(cPickle.dumps(False, True)), False) - - def test_mixedpickle(self): - import pickle - try: - import cPickle - except ImportError: - return # Just ignore this if cPickle doesn't exist - - self.assertIs(pickle.loads(cPickle.dumps(True)), True) - self.assertIs(pickle.loads(cPickle.dumps(False)), False) - self.assertIs(pickle.loads(cPickle.dumps(True, True)), True) - self.assertIs(pickle.loads(cPickle.dumps(False, True)), False) - - self.assertIs(cPickle.loads(pickle.dumps(True)), True) - self.assertIs(cPickle.loads(pickle.dumps(False)), False) - self.assertIs(cPickle.loads(pickle.dumps(True, True)), True) - self.assertIs(cPickle.loads(pickle.dumps(False, True)), False) - def test_picklevalues(self): # Test for specific backwards-compatible pickle values import pickle @@ -306,19 +278,6 @@ class BoolTest(unittest.TestCase): self.assertEqual(pickle.dumps(True, protocol=2), b'\x80\x02\x88.') self.assertEqual(pickle.dumps(False, protocol=2), b'\x80\x02\x89.') - def test_cpicklevalues(self): - # Test for specific backwards-compatible pickle values - try: - import cPickle - except ImportError: - return # Just ignore the rest if cPickle doesn't exist - self.assertEqual(cPickle.dumps(True, protocol=0), b"I01\n.") - self.assertEqual(cPickle.dumps(False, protocol=0), b"I00\n.") - self.assertEqual(cPickle.dumps(True, protocol=1), b"I01\n.") - self.assertEqual(cPickle.dumps(False, protocol=1), b"I00\n.") - self.assertEqual(cPickle.dumps(True, protocol=2), b'\x80\x02\x88.') - self.assertEqual(cPickle.dumps(False, protocol=2), b'\x80\x02\x89.') - def test_convert_to_bool(self): # Verify that TypeError occurs when bad things are returned # from __bool__(). This isn't really a bool test, but diff --git a/Lib/test/test_bytes.py b/Lib/test/test_bytes.py index ca22ef1..094c56c 100644 --- a/Lib/test/test_bytes.py +++ b/Lib/test/test_bytes.py @@ -4,7 +4,6 @@ import os import re import sys import pickle -import cPickle import tempfile import unittest import test.test_support @@ -641,12 +640,11 @@ class BytesTest(unittest.TestCase): self.assertEqual(b.rpartition(b'i'), (b'mississipp', b'i', b'')) def test_pickling(self): - for pm in pickle, cPickle: - for proto in range(pm.HIGHEST_PROTOCOL): - for b in b"", b"a", b"abc", b"\xffab\x80", b"\0\0\377\0\0": - ps = pm.dumps(b, proto) - q = pm.loads(ps) - self.assertEqual(b, q) + for proto in range(pickle.HIGHEST_PROTOCOL): + for b in b"", b"a", b"abc", b"\xffab\x80", b"\0\0\377\0\0": + ps = pickle.dumps(b, proto) + q = pickle.loads(ps) + self.assertEqual(b, q) def test_strip(self): b = b'mississippi' diff --git a/Lib/test/test_cpickle.py b/Lib/test/test_cpickle.py deleted file mode 100644 index 78beda7..0000000 --- a/Lib/test/test_cpickle.py +++ /dev/null @@ -1,103 +0,0 @@ -import cPickle -import unittest -from cStringIO import StringIO -from test.pickletester import AbstractPickleTests, AbstractPickleModuleTests -from test import test_support - -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, proto=0): - f = StringIO() - p = cPickle.Pickler(f, proto) - 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, proto=0): - p = cPickle.Pickler(proto) - 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, proto=0): - f = StringIO() - p = cPickle.Pickler(f, proto) - 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) - - def test_nonrecursive_deep(self): - # If it's not cyclic, it should pickle OK even if the nesting - # depth exceeds PY_CPICKLE_FAST_LIMIT. That happens to be - # 50 today. Jack Jansen reported stack overflow on Mac OS 9 - # at 64. - a = [] - for i in range(60): - a = [a] - b = self.loads(self.dumps(a)) - self.assertEqual(a, b) - -def test_main(): - test_support.run_unittest( - cPickleTests, - cPicklePicklerTests, - cPickleListPicklerTests, - cPickleFastPicklerTests - ) - -if __name__ == "__main__": - test_main() diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py index 110e3a8..8e57b90 100644 --- a/Lib/test/test_descr.py +++ b/Lib/test/test_descr.py @@ -2807,10 +2807,6 @@ def pickles(): if verbose: print("Testing pickling and copying new-style classes and objects...") import pickle - try: - import cPickle - except ImportError: - cPickle = None def sorteditems(d): return sorted(d.items()) @@ -2863,9 +2859,7 @@ def pickles(): class C4(C4classic, object): # mixed inheritance pass - for p in pickle, cPickle: - if p is None: - continue # cPickle not found -- skip it + for p in [pickle]: for bin in 0, 1: if verbose: print(p.__name__, ["text", "binary"][bin]) @@ -2925,7 +2919,7 @@ def pickles(): def pickleslots(): if verbose: print("Testing pickling of classes with __slots__ ...") - import pickle, pickle as cPickle + import pickle # Pickling of classes with __slots__ but without __getstate__ should fail # (when using protocols 0 or 1) global B, C, D, E @@ -2943,23 +2937,11 @@ def pickleslots(): else: raise TestFailed, "should fail: pickle C instance - %s" % base try: - cPickle.dumps(C(), 0) - except TypeError: - pass - else: - raise TestFailed, "should fail: cPickle C instance - %s" % base - try: pickle.dumps(C(), 0) except TypeError: pass else: raise TestFailed, "should fail: pickle D instance - %s" % base - try: - cPickle.dumps(D(), 0) - except TypeError: - pass - else: - raise TestFailed, "should fail: cPickle D instance - %s" % base # Give C a nice generic __getstate__ and __setstate__ class C(base): __slots__ = ['a'] @@ -2984,20 +2966,14 @@ def pickleslots(): x = C() y = pickle.loads(pickle.dumps(x)) vereq(hasattr(y, 'a'), 0) - y = cPickle.loads(cPickle.dumps(x)) - vereq(hasattr(y, 'a'), 0) x.a = 42 y = pickle.loads(pickle.dumps(x)) vereq(y.a, 42) - y = cPickle.loads(cPickle.dumps(x)) - vereq(y.a, 42) x = D() x.a = 42 x.b = 100 y = pickle.loads(pickle.dumps(x)) vereq(y.a + y.b, 142) - y = cPickle.loads(cPickle.dumps(x)) - vereq(y.a + y.b, 142) # A subclass that adds a slot should also work class E(C): __slots__ = ['b'] @@ -3007,9 +2983,6 @@ def pickleslots(): y = pickle.loads(pickle.dumps(x)) vereq(y.a, x.a) vereq(y.b, x.b) - y = cPickle.loads(cPickle.dumps(x)) - vereq(y.a, x.a) - vereq(y.b, x.b) def copies(): if verbose: print("Testing copy.copy() and copy.deepcopy()...") diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py index 56a990d..0988098 100644 --- a/Lib/test/test_exceptions.py +++ b/Lib/test/test_exceptions.py @@ -4,10 +4,6 @@ import os import sys import unittest import pickle -try: - import cPickle -except ImportError: - cPickle = None from test.test_support import (TESTFN, unlink, run_unittest, guard_warnings_filter) @@ -299,9 +295,7 @@ class ExceptionTests(unittest.TestCase): value, expected[checkArgName])) # test for pickling support - for p in pickle, cPickle: - if p is None: - continue # cPickle not found -- skip it + for p in [pickle]: for protocol in range(p.HIGHEST_PROTOCOL + 1): s = p.dumps(e, protocol) new = p.loads(s) diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py index f69dde5..f14ff49 100644 --- a/Lib/test/test_re.py +++ b/Lib/test/test_re.py @@ -412,12 +412,6 @@ class ReTests(unittest.TestCase): def test_pickling(self): import pickle self.pickle_test(pickle) - try: - import cPickle - except ImportError: - pass # cPickle not found -- skip it - else: - self.pickle_test(cPickle) # old pickles expect the _compile() reconstructor in sre module import warnings with guard_warnings_filter(): diff --git a/Lib/test/test_slice.py b/Lib/test/test_slice.py index 77a2931..4d89aa6 100644 --- a/Lib/test/test_slice.py +++ b/Lib/test/test_slice.py @@ -2,7 +2,7 @@ import unittest from test import test_support -from cPickle import loads, dumps +from pickle import loads, dumps import sys diff --git a/Lib/test/test_xpickle.py b/Lib/test/test_xpickle.py deleted file mode 100644 index 42cd0f4..0000000 --- a/Lib/test/test_xpickle.py +++ /dev/null @@ -1,44 +0,0 @@ -# test_pickle dumps and loads pickles via pickle.py. -# test_cpickle does the same, but via the cPickle module. -# This test covers the other two cases, making pickles with one module and -# loading them via the other. - -import pickle -import cPickle -import unittest - -from test import test_support -from test.pickletester import AbstractPickleTests - -class DumpCPickle_LoadPickle(AbstractPickleTests): - - error = KeyError - - def dumps(self, arg, proto=0, fast=0): - # Ignore fast - return cPickle.dumps(arg, proto) - - def loads(self, buf): - # Ignore fast - return pickle.loads(buf) - -class DumpPickle_LoadCPickle(AbstractPickleTests): - - error = cPickle.BadPickleGet - - def dumps(self, arg, proto=0, fast=0): - # Ignore fast - return pickle.dumps(arg, proto) - - def loads(self, buf): - # Ignore fast - return cPickle.loads(buf) - -def test_main(): - test_support.run_unittest( - DumpCPickle_LoadPickle, - DumpPickle_LoadCPickle - ) - -if __name__ == "__main__": - test_main() |