summaryrefslogtreecommitdiff
path: root/Lib/test/pickletester.py
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2003-02-02 16:09:05 +0000
committerTim Peters <tim.peters@gmail.com>2003-02-02 16:09:05 +0000
commit9ba788d4697f8c50aab76ee27d0f8d8040181abb (patch)
tree3e3da0037015ca5491d0caa9c125cd823e1cea4e /Lib/test/pickletester.py
parent9bf592894cf2e5738da07c1760c27d64b3246881 (diff)
downloadcpython-9ba788d4697f8c50aab76ee27d0f8d8040181abb.tar.gz
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.py25
1 files changed, 23 insertions, 2 deletions
diff --git a/Lib/test/pickletester.py b/Lib/test/pickletester.py
index 2a1ca179c1..5ef0cf2e24 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)