diff options
author | Benjamin Peterson <benjamin@python.org> | 2008-06-12 03:10:02 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2008-06-12 03:10:02 (GMT) |
commit | 75f25f2c9a4646746efbc056b4d2a07b40f93964 (patch) | |
tree | dc99b42d2c9e31672d27a37659ccf68951526916 /Lib/test | |
parent | f501942c764d25f29a2e06ba5c9917b149c7189b (diff) | |
download | cpython-75f25f2c9a4646746efbc056b4d2a07b40f93964.zip cpython-75f25f2c9a4646746efbc056b4d2a07b40f93964.tar.gz cpython-75f25f2c9a4646746efbc056b4d2a07b40f93964.tar.bz2 |
revert the addition of _pickle because it was causing havok with 64-bit
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/pickletester.py | 25 | ||||
-rw-r--r-- | Lib/test/test_pickle.py | 53 | ||||
-rw-r--r-- | Lib/test/test_pickletools.py | 2 |
3 files changed, 33 insertions, 47 deletions
diff --git a/Lib/test/pickletester.py b/Lib/test/pickletester.py index c9ebdb8..783d361 100644 --- a/Lib/test/pickletester.py +++ b/Lib/test/pickletester.py @@ -362,7 +362,7 @@ def create_data(): return x class AbstractPickleTests(unittest.TestCase): - # Subclass must define self.dumps, self.loads. + # Subclass must define self.dumps, self.loads, self.error. _testdata = create_data() @@ -463,9 +463,8 @@ class AbstractPickleTests(unittest.TestCase): self.assertEqual(list(x[0].attr.keys()), [1]) self.assert_(x[0].attr[1] is x) - def test_get(self): - self.assertRaises(KeyError, self.loads, b'g0\np0') - self.assertEquals(self.loads(b'((Kdtp0\nh\x00l.))'), [(100,), (100,)]) + def test_garyp(self): + self.assertRaises(self.error, self.loads, b'garyp') def test_insecure_strings(self): # XXX Some of these tests are temporarily disabled @@ -956,7 +955,7 @@ class AbstractPickleModuleTests(unittest.TestCase): f = open(TESTFN, "wb") try: f.close() - self.assertRaises(ValueError, pickle.dump, 123, f) + self.assertRaises(ValueError, self.module.dump, 123, f) finally: os.remove(TESTFN) @@ -965,24 +964,24 @@ class AbstractPickleModuleTests(unittest.TestCase): f = open(TESTFN, "wb") try: f.close() - self.assertRaises(ValueError, pickle.dump, 123, f) + self.assertRaises(ValueError, self.module.dump, 123, f) finally: os.remove(TESTFN) def test_highest_protocol(self): # Of course this needs to be changed when HIGHEST_PROTOCOL changes. - self.assertEqual(pickle.HIGHEST_PROTOCOL, 3) + self.assertEqual(self.module.HIGHEST_PROTOCOL, 3) def test_callapi(self): from io import BytesIO f = BytesIO() # With and without keyword arguments - pickle.dump(123, f, -1) - pickle.dump(123, file=f, protocol=-1) - pickle.dumps(123, -1) - pickle.dumps(123, protocol=-1) - pickle.Pickler(f, -1) - pickle.Pickler(f, protocol=-1) + self.module.dump(123, f, -1) + self.module.dump(123, file=f, protocol=-1) + self.module.dumps(123, -1) + self.module.dumps(123, protocol=-1) + self.module.Pickler(f, -1) + self.module.Pickler(f, protocol=-1) class AbstractPersistentPicklerTests(unittest.TestCase): diff --git a/Lib/test/test_pickle.py b/Lib/test/test_pickle.py index 65a7adc..42fb33e 100644 --- a/Lib/test/test_pickle.py +++ b/Lib/test/test_pickle.py @@ -7,42 +7,37 @@ from test.pickletester import AbstractPickleTests from test.pickletester import AbstractPickleModuleTests from test.pickletester import AbstractPersistentPicklerTests -try: - import _pickle - has_c_implementation = True -except ImportError: - has_c_implementation = False +class PickleTests(AbstractPickleTests, AbstractPickleModuleTests): + module = pickle + error = KeyError -class PickleTests(AbstractPickleModuleTests): - pass + def dumps(self, arg, proto=None): + return pickle.dumps(arg, proto) + def loads(self, buf): + return pickle.loads(buf) -class PyPicklerTests(AbstractPickleTests): +class PicklerTests(AbstractPickleTests): - pickler = pickle._Pickler - unpickler = pickle._Unpickler + error = KeyError def dumps(self, arg, proto=None): f = io.BytesIO() - p = self.pickler(f, proto) + p = pickle.Pickler(f, proto) p.dump(arg) f.seek(0) return bytes(f.read()) def loads(self, buf): f = io.BytesIO(buf) - u = self.unpickler(f) + u = pickle.Unpickler(f) return u.load() - -class PyPersPicklerTests(AbstractPersistentPicklerTests): - - pickler = pickle._Pickler - unpickler = pickle._Unpickler +class PersPicklerTests(AbstractPersistentPicklerTests): def dumps(self, arg, proto=None): - class PersPickler(self.pickler): + class PersPickler(pickle.Pickler): def persistent_id(subself, obj): return self.persistent_id(obj) f = io.BytesIO() @@ -52,29 +47,19 @@ class PyPersPicklerTests(AbstractPersistentPicklerTests): return f.read() def loads(self, buf): - class PersUnpickler(self.unpickler): + class PersUnpickler(pickle.Unpickler): def persistent_load(subself, obj): return self.persistent_load(obj) f = io.BytesIO(buf) u = PersUnpickler(f) return u.load() - -if has_c_implementation: - class CPicklerTests(PyPicklerTests): - pickler = _pickle.Pickler - unpickler = _pickle.Unpickler - - class CPersPicklerTests(PyPersPicklerTests): - pickler = _pickle.Pickler - unpickler = _pickle.Unpickler - - def test_main(): - tests = [PickleTests, PyPicklerTests, PyPersPicklerTests] - if has_c_implementation: - tests.extend([CPicklerTests, CPersPicklerTests]) - support.run_unittest(*tests) + support.run_unittest( + PickleTests, + PicklerTests, + PersPicklerTests + ) support.run_doctest(pickle) if __name__ == "__main__": diff --git a/Lib/test/test_pickletools.py b/Lib/test/test_pickletools.py index 3e701b0..ccb6c9c 100644 --- a/Lib/test/test_pickletools.py +++ b/Lib/test/test_pickletools.py @@ -12,6 +12,8 @@ class OptimizedPickleTests(AbstractPickleTests, AbstractPickleModuleTests): def loads(self, buf): return pickle.loads(buf) + module = pickle + error = KeyError def test_main(): support.run_unittest(OptimizedPickleTests) |