summaryrefslogtreecommitdiffstats
path: root/Lib/test/pickletester.py
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2003-02-03 16:20:13 (GMT)
committerTim Peters <tim.peters@gmail.com>2003-02-03 16:20:13 (GMT)
commit31f119ebdb0c82a6d06fc94a2d6ad9eedd0a2bec (patch)
treeb3e2214ebbb674f0dd42faee8fd9d993dbba1034 /Lib/test/pickletester.py
parent621f055233f77779dc3b2b53edcf39da9a69e82d (diff)
downloadcpython-31f119ebdb0c82a6d06fc94a2d6ad9eedd0a2bec.zip
cpython-31f119ebdb0c82a6d06fc94a2d6ad9eedd0a2bec.tar.gz
cpython-31f119ebdb0c82a6d06fc94a2d6ad9eedd0a2bec.tar.bz2
Proper testing of proto 2 in part requires checking that the new opcodes
are actually getting generated. Add helpered method ensure_opcode_in_pickle to do a correct job checking for that. Changed test_long1(), test_long4(), and test_short_tuples() to use it.
Diffstat (limited to 'Lib/test/pickletester.py')
-rw-r--r--Lib/test/pickletester.py21
1 files changed, 10 insertions, 11 deletions
diff --git a/Lib/test/pickletester.py b/Lib/test/pickletester.py
index 249cc54..dbecddc 100644
--- a/Lib/test/pickletester.py
+++ b/Lib/test/pickletester.py
@@ -1,5 +1,6 @@
import unittest
import pickle
+import pickletools
from test.test_support import TestFailed, have_unicode, TESTFN
@@ -253,6 +254,12 @@ class AbstractPickleTests(unittest.TestCase):
def setUp(self):
pass
+ def ensure_opcode_in_pickle(self, code, pickle):
+ for op, dummy, dummy in pickletools.genops(pickle):
+ if op.code == code:
+ return
+ self.fail("didn't find opcode %r in pickle %r" % (code, pickle))
+
def test_misc(self):
# test various datatypes not tested by testdata
for proto in protocols:
@@ -476,12 +483,14 @@ class AbstractPickleTests(unittest.TestCase):
s = self.dumps(x, 2)
y = self.loads(s)
self.assertEqual(x, y)
+ self.ensure_opcode_in_pickle(pickle.LONG1, s)
def test_long4(self):
x = 12345678910111213141516178920L << (256*8)
s = self.dumps(x, 2)
y = self.loads(s)
self.assertEqual(x, y)
+ self.ensure_opcode_in_pickle(pickle.LONG4, s)
def test_short_tuples(self):
# Map (proto, len(tuple)) to expected opcode.
@@ -503,8 +512,6 @@ class AbstractPickleTests(unittest.TestCase):
(2, 3): pickle.TUPLE3,
(2, 4): pickle.TUPLE,
}
- all_tuple_opcodes = (pickle.TUPLE, pickle.EMPTY_TUPLE,
- pickle.TUPLE1, pickle.TUPLE2, pickle.TUPLE3)
a = ()
b = (1,)
c = (1, 2)
@@ -515,16 +522,8 @@ class AbstractPickleTests(unittest.TestCase):
s = self.dumps(x, proto)
y = self.loads(s)
self.assertEqual(x, y, (proto, x, s, y))
-
- # Verify that the protocol-correct tuple-building opcode
- # was generated.
expected = expected_opcode[proto, len(x)]
- for opcode in s:
- if opcode in all_tuple_opcodes:
- self.assertEqual(expected, opcode)
- break
- else:
- self.fail("didn't find a tuple-building opcode in pickle")
+ self.ensure_opcode_in_pickle(expected, s)
def test_singletons(self):
for proto in protocols: