diff options
author | Tim Peters <tim.peters@gmail.com> | 2001-04-10 03:41:41 (GMT) |
---|---|---|
committer | Tim Peters <tim.peters@gmail.com> | 2001-04-10 03:41:41 (GMT) |
commit | e089c688717fbc7c208ad30ee885dcd93a4de678 (patch) | |
tree | 482d34aafc818b97fe753c9a369af32170b8fa6e /Lib/test/pickletester.py | |
parent | aa815df1e18b9b717e39e258f416b107476b4db2 (diff) | |
download | cpython-e089c688717fbc7c208ad30ee885dcd93a4de678.zip cpython-e089c688717fbc7c208ad30ee885dcd93a4de678.tar.gz cpython-e089c688717fbc7c208ad30ee885dcd93a4de678.tar.bz2 |
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.
Diffstat (limited to 'Lib/test/pickletester.py')
-rw-r--r-- | Lib/test/pickletester.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/Lib/test/pickletester.py b/Lib/test/pickletester.py index 54a43b2..8014efe 100644 --- a/Lib/test/pickletester.py +++ b/Lib/test/pickletester.py @@ -1,5 +1,8 @@ # 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 I0 @@ -197,3 +200,19 @@ def dotest(pickle): else: 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 |