mirror of
https://github.com/python/cpython.git
synced 2025-11-02 03:01:58 +00:00
This is my patch:
[ 1180995 ] binary formats for marshalling floats Adds 2 new type codes for marshal (binary floats and binary complexes), a new marshal version (2), updates MAGIC and fiddles the de-serializing of code objects to be less likely to clobber the real reason for failing if it fails.
This commit is contained in:
parent
268e61cf74
commit
df88846ebc
5 changed files with 195 additions and 67 deletions
|
|
@ -73,20 +73,34 @@ class FloatTestCase(unittest.TestCase):
|
|||
n /= 123.4567
|
||||
|
||||
f = 0.0
|
||||
s = marshal.dumps(f)
|
||||
s = marshal.dumps(f, 2)
|
||||
got = marshal.loads(s)
|
||||
self.assertEqual(f, got)
|
||||
# and with version <= 1 (floats marshalled differently then)
|
||||
s = marshal.dumps(f, 1)
|
||||
got = marshal.loads(s)
|
||||
self.assertEqual(f, got)
|
||||
|
||||
n = sys.maxint * 3.7e-250
|
||||
while n < small:
|
||||
for expected in (-n, n):
|
||||
f = float(expected)
|
||||
|
||||
s = marshal.dumps(f)
|
||||
got = marshal.loads(s)
|
||||
self.assertEqual(f, got)
|
||||
|
||||
s = marshal.dumps(f, 1)
|
||||
got = marshal.loads(s)
|
||||
self.assertEqual(f, got)
|
||||
|
||||
marshal.dump(f, file(test_support.TESTFN, "wb"))
|
||||
got = marshal.load(file(test_support.TESTFN, "rb"))
|
||||
self.assertEqual(f, got)
|
||||
|
||||
marshal.dump(f, file(test_support.TESTFN, "wb"), 1)
|
||||
got = marshal.load(file(test_support.TESTFN, "rb"))
|
||||
self.assertEqual(f, got)
|
||||
n *= 123.4567
|
||||
os.unlink(test_support.TESTFN)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue