[Python-checkins] CVS: python/dist/src/Lib/test pickletester.py,1.4,1.5
Tim Peters
tim_one@users.sourceforge.net
Mon, 09 Apr 2001 20:41:43 -0700
Update of /cvsroot/python/python/dist/src/Lib/test
In directory usw-pr-cvs1:/tmp/cvs-serv21796/python/dist/src/Lib/test
Modified Files:
pickletester.py
Log Message:
Test full range of native ints. This exposes two more binary pickle
bugs on sizeof(long)==8 machines. pickle.py has no idea what it's
doing with very large ints, and variously gets things right by accident,
computes nonsense, or generates corrupt pickles. cPickle fails on
cases 2**31 <= i < 2**32: since it *thinks* those are 4-byte ints
(the "high 4 bytes" are all zeroes), it stores them in the (signed!) BININT
format, so they get unpickled as negative values.
Index: pickletester.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/pickletester.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** pickletester.py 2001/04/09 20:07:05 1.4
--- pickletester.py 2001/04/10 03:41:41 1.5
***************
*** 1,4 ****
--- 1,7 ----
# test_pickle and test_cpickle both use this.
+ from test_support import TestFailed
+ import sys
+
# break into multiple strings to please font-lock-mode
DATA = """(lp1
***************
*** 198,199 ****
--- 201,218 ----
if u2 != u:
print "Endcase failure: %s => %s" % (`u`, `u2`)
+
+ # Test the full range of Python ints.
+ n = sys.maxint
+ while n:
+ for expected in (-n, n):
+ for binary_mode in (0, 1):
+ s = pickle.dumps(expected, binary_mode)
+ got = pickle.loads(s)
+ if expected != got:
+ raise TestFailed("for %s-mode pickle of %d, pickle "
+ "string is %s, loaded back as %s" % (
+ binary_mode and "binary" or "text",
+ expected,
+ repr(s),
+ got))
+ n = n >> 1