summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorVinay Sajip <vinay_sajip@yahoo.co.uk>2011-07-02 15:42:47 (GMT)
committerVinay Sajip <vinay_sajip@yahoo.co.uk>2011-07-02 15:42:47 (GMT)
commit5bdae3bb7c7ab9e85453698972fa5fa926f012f3 (patch)
treeed140d49cc67ee21d563cccb2b2f47fdebd8763e /Lib
parenta4a04069fd93395369b6061ed07f471e53f1c7a1 (diff)
downloadcpython-5bdae3bb7c7ab9e85453698972fa5fa926f012f3.zip
cpython-5bdae3bb7c7ab9e85453698972fa5fa926f012f3.tar.gz
cpython-5bdae3bb7c7ab9e85453698972fa5fa926f012f3.tar.bz2
Closes #12291: Fixed bug which was found when doing multiple loads from one stream.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/importlib/test/source/test_file_loader.py2
-rw-r--r--Lib/test/test_marshal.py24
2 files changed, 25 insertions, 1 deletions
diff --git a/Lib/importlib/test/source/test_file_loader.py b/Lib/importlib/test/source/test_file_loader.py
index 0ffe78d..2028092 100644
--- a/Lib/importlib/test/source/test_file_loader.py
+++ b/Lib/importlib/test/source/test_file_loader.py
@@ -214,7 +214,7 @@ class BadBytecodeTest(unittest.TestCase):
lambda bc: bc[:8] + b'<test>',
del_source=del_source)
file_path = mapping['_temp'] if not del_source else bytecode_path
- with self.assertRaises(ValueError):
+ with self.assertRaises(EOFError):
self.import_(file_path, '_temp')
def _test_bad_magic(self, test, *, del_source=False):
diff --git a/Lib/test/test_marshal.py b/Lib/test/test_marshal.py
index 81cf598..cd100f9 100644
--- a/Lib/test/test_marshal.py
+++ b/Lib/test/test_marshal.py
@@ -211,6 +211,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,