[Python-checkins] python/dist/src/Lib/test pickletester.py,1.37,1.38
tim_one@users.sourceforge.net
tim_one@users.sourceforge.net
Mon, 03 Feb 2003 08:20:21 -0800
Update of /cvsroot/python/python/dist/src/Lib/test
In directory sc8-pr-cvs1:/tmp/cvs-serv14251/python/Lib/test
Modified Files:
pickletester.py
Log Message:
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.
Index: pickletester.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/pickletester.py,v
retrieving revision 1.37
retrieving revision 1.38
diff -C2 -d -r1.37 -r1.38
*** pickletester.py 2 Feb 2003 20:29:38 -0000 1.37
--- pickletester.py 3 Feb 2003 16:20:13 -0000 1.38
***************
*** 1,4 ****
--- 1,5 ----
import unittest
import pickle
+ import pickletools
from test.test_support import TestFailed, have_unicode, TESTFN
***************
*** 254,257 ****
--- 255,264 ----
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
***************
*** 477,480 ****
--- 484,488 ----
y = self.loads(s)
self.assertEqual(x, y)
+ self.ensure_opcode_in_pickle(pickle.LONG1, s)
def test_long4(self):
***************
*** 483,486 ****
--- 491,495 ----
y = self.loads(s)
self.assertEqual(x, y)
+ self.ensure_opcode_in_pickle(pickle.LONG4, s)
def test_short_tuples(self):
***************
*** 504,509 ****
(2, 4): pickle.TUPLE,
}
- all_tuple_opcodes = (pickle.TUPLE, pickle.EMPTY_TUPLE,
- pickle.TUPLE1, pickle.TUPLE2, pickle.TUPLE3)
a = ()
b = (1,)
--- 513,516 ----
***************
*** 516,529 ****
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")
def test_singletons(self):
--- 523,528 ----
y = self.loads(s)
self.assertEqual(x, y, (proto, x, s, y))
expected = expected_opcode[proto, len(x)]
! self.ensure_opcode_in_pickle(expected, s)
def test_singletons(self):