summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_marshal.py
diff options
context:
space:
mode:
authorVinay Sajip <vinay_sajip@yahoo.co.uk>2011-07-02 16:16:02 (GMT)
committerVinay Sajip <vinay_sajip@yahoo.co.uk>2011-07-02 16:16:02 (GMT)
commit65897a386e7980a736e3492eecc9bdbb706bf4f9 (patch)
tree4a2c1ed7749041d553164fbcd9e8349d9e57af06 /Lib/test/test_marshal.py
parent2ee61884fe350bc1efbd20bffb305d6eac5a1937 (diff)
parent5bdae3bb7c7ab9e85453698972fa5fa926f012f3 (diff)
downloadcpython-65897a386e7980a736e3492eecc9bdbb706bf4f9.zip
cpython-65897a386e7980a736e3492eecc9bdbb706bf4f9.tar.gz
cpython-65897a386e7980a736e3492eecc9bdbb706bf4f9.tar.bz2
Closes #12291 for 3.3 - merged fix from 3.2.
Diffstat (limited to 'Lib/test/test_marshal.py')
-rw-r--r--Lib/test/test_marshal.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/Lib/test/test_marshal.py b/Lib/test/test_marshal.py
index 8a5590a..dec8129 100644
--- a/Lib/test/test_marshal.py
+++ b/Lib/test/test_marshal.py
@@ -228,6 +228,30 @@ class BugsTestCase(unittest.TestCase):
invalid_string = b'l\x02\x00\x00\x00\x00\x00\x00\x00'
self.assertRaises(ValueError, marshal.loads, invalid_string)
+ def test_multiple_dumps_and_loads(self):
+ # Issue 12291: marshal.load() should be callable multiple times
+ # with interleaved data written by non-marshal code
+ # Adapted from a patch by Engelbert Gruber.
+ data = (1, 'abc', b'def', 1.0, (2, 'a', ['b', b'c']))
+ for interleaved in (b'', b'0123'):
+ ilen = len(interleaved)
+ positions = []
+ try:
+ with open(support.TESTFN, 'wb') as f:
+ for d in data:
+ marshal.dump(d, f)
+ if ilen:
+ f.write(interleaved)
+ positions.append(f.tell())
+ with open(support.TESTFN, 'rb') as f:
+ for i, d in enumerate(data):
+ self.assertEqual(d, marshal.load(f))
+ if ilen:
+ f.read(ilen)
+ self.assertEqual(positions[i], f.tell())
+ finally:
+ support.unlink(support.TESTFN)
+
def test_main():
support.run_unittest(IntTestCase,