diff -r f9b4cfc19264 Lib/test/test_marshal.py --- a/Lib/test/test_marshal.py Sat Jun 18 19:34:12 2011 -0400 +++ b/Lib/test/test_marshal.py Sun Jun 26 10:19:55 2011 +0200 @@ -211,6 +211,42 @@ invalid_string = b'l\x02\x00\x00\x00\x00\x00\x00\x00' self.assertRaises(ValueError, marshal.loads, invalid_string) +class MultipleTestCase(unittest.TestCase): + """ + http://bugs.python.org/issue12291 file written using marshal in 3.2 can be read by 2.7, but not 3.2 or 3.3 + + actually files written 3.x can not be read on 3.x. + """ + + def test_multiple_dump_reload(self): + data = ( 1, 'abc', 1.0 ) + pos = [] + try: + with open(support.TESTFN, "wb") as f: + for d in data: + marshal.dump(d, f) + pos.append(f.tell()) + with open(support.TESTFN, "rb") as f: + for i in range(len(data)): + self.assertEqual(data[i], marshal.load(f)) + self.assertEqual(pos[i], f.tell()) + finally: + support.unlink(support.TESTFN) + + def test_multiple_dump_reload_interleaved(self): + data = ( 1, 'abc', 1.0 ) + pos = [] + with open(support.TESTFN, "wb") as f: + for d in data: + marshal.dump(d, f) + f.write(bytes("0123", "ascii")) + pos.append(f.tell()) + with open(support.TESTFN, "rb") as f: + for i in range(len(data)): + self.assertEqual(data[i], marshal.load(f)) + f.read(4) + self.assertEqual(pos[i], f.tell()) + os.unlink(support.TESTFN) def test_main(): support.run_unittest(IntTestCase, @@ -219,7 +255,8 @@ CodeTestCase, ContainerTestCase, ExceptionTestCase, - BugsTestCase) + BugsTestCase, + MultipleTestCase) if __name__ == "__main__": test_main()