diff options
author | Tim Peters <tim.peters@gmail.com> | 2003-02-02 16:09:05 (GMT) |
---|---|---|
committer | Tim Peters <tim.peters@gmail.com> | 2003-02-02 16:09:05 (GMT) |
commit | 4190fb84293b4c54127e1b7be2d9bdf06edf2910 (patch) | |
tree | 7a307603c38ceececee2b17ffd9f7aa69ec8e69c /Lib/test/pickletester.py | |
parent | 1ecfb73c269f1475d4b2738ef76c20eaecbaa7e9 (diff) | |
download | cpython-4190fb84293b4c54127e1b7be2d9bdf06edf2910.zip cpython-4190fb84293b4c54127e1b7be2d9bdf06edf2910.tar.gz cpython-4190fb84293b4c54127e1b7be2d9bdf06edf2910.tar.bz2 |
Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
the hitherto unknown (to me) noload() cPickle function, which is (a)
something we don't test at all, and (b) pickle.py doesn't have.
Diffstat (limited to 'Lib/test/pickletester.py')
-rw-r--r-- | Lib/test/pickletester.py | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/Lib/test/pickletester.py b/Lib/test/pickletester.py index 2a1ca17..5ef0cf2 100644 --- a/Lib/test/pickletester.py +++ b/Lib/test/pickletester.py @@ -1,4 +1,6 @@ import unittest +import pickle + from test.test_support import TestFailed, have_unicode, TESTFN # Tests that try a number of pickle protocols should have a @@ -296,6 +298,25 @@ class AbstractPickleTests(unittest.TestCase): # Tests for protocol 2 + def test_proto(self): + build_none = pickle.NONE + pickle.STOP + for proto in protocols: + expected = build_none + if proto >= 2: + expected = pickle.PROTO + chr(proto) + expected + p = self.dumps(None, proto) + self.assertEqual(p, expected) + + oob = protocols[-1] + 1 # a future protocol + badpickle = pickle.PROTO + chr(oob) + build_none + try: + self.loads(badpickle) + except ValueError, detail: + self.failUnless(str(detail).startswith( + "unsupported pickle protocol")) + else: + self.fail("expected bad protocol number to raise ValueError") + def test_long1(self): x = 12345678910111213141516178920L s = self.dumps(x, 2) @@ -314,14 +335,14 @@ class AbstractPickleTests(unittest.TestCase): c = (1, 2) d = (1, 2, 3) e = (1, 2, 3, 4) - for proto in 0, 1, 2: + for proto in protocols: for x in a, b, c, d, e: s = self.dumps(x, proto) y = self.loads(s) self.assertEqual(x, y, (proto, x, s, y)) def test_singletons(self): - for proto in 0, 1, 2: + for proto in protocols: for x in None, False, True: s = self.dumps(x, proto) y = self.loads(s) |