Update version number and release date.
[python/dscho.git] / Lib / test / test_marshal.py
blob9237af0b63883e5efa4e17cd9a9438e62e3437b9
1 from test.test_support import TestFailed
2 import marshal
3 import sys
5 # XXX Much more needed here.
7 # Test the full range of Python ints.
8 n = sys.maxint
9 while n:
10 for expected in (-n, n):
11 s = marshal.dumps(expected)
12 got = marshal.loads(s)
13 if expected != got:
14 raise TestFailed("for int %d, marshal string is %r, loaded "
15 "back as %d" % (expected, s, got))
16 n = n >> 1
18 # Simulate int marshaling on a 64-bit box. This is most interesting if
19 # we're running the test on a 32-bit box, of course.
21 def to_little_endian_string(value, nbytes):
22 bytes = []
23 for i in range(nbytes):
24 bytes.append(chr(value & 0xff))
25 value >>= 8
26 return ''.join(bytes)
28 maxint64 = (1L << 63) - 1
29 minint64 = -maxint64-1
31 for base in maxint64, minint64, -maxint64, -(minint64 >> 1):
32 while base:
33 s = 'I' + to_little_endian_string(base, 8)
34 got = marshal.loads(s)
35 if base != got:
36 raise TestFailed("for int %d, simulated marshal string is %r, "
37 "loaded back as %d" % (base, s, got))
38 if base == -1: # a fixed-point for shifting right 1
39 base = 0
40 else:
41 base >>= 1
43 # Simple-minded check for SF 588452: Debug build crashes
44 marshal.dumps([128] * 1000)