diff options
author | Nadeem Vawda <nadeem.vawda@gmail.com> | 2011-05-07 12:14:53 (GMT) |
---|---|---|
committer | Nadeem Vawda <nadeem.vawda@gmail.com> | 2011-05-07 12:14:53 (GMT) |
commit | 909f6d2fbaefe6d191c87f5439545a85d74f6c54 (patch) | |
tree | 21244a4a1285300b7d8404041b0c529009612b4c /Lib/test/test_mmap.py | |
parent | ced1056925420a67a5cce86287122429700ad52e (diff) | |
download | cpython-909f6d2fbaefe6d191c87f5439545a85d74f6c54.zip cpython-909f6d2fbaefe6d191c87f5439545a85d74f6c54.tar.gz cpython-909f6d2fbaefe6d191c87f5439545a85d74f6c54.tar.bz2 |
Issue #11277: Fix tests - crash will not trigger if the file is closed and reopened.
Diffstat (limited to 'Lib/test/test_mmap.py')
-rw-r--r-- | Lib/test/test_mmap.py | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/Lib/test/test_mmap.py b/Lib/test/test_mmap.py index fbc34ed..0a177c6 100644 --- a/Lib/test/test_mmap.py +++ b/Lib/test/test_mmap.py @@ -654,21 +654,21 @@ class LargeMmapTests(unittest.TestCase): def tearDown(self): unlink(TESTFN) - def _create_test_file(self, num_zeroes, tail): + def _make_test_file(self, num_zeroes, tail): if sys.platform[:3] == 'win' or sys.platform == 'darwin': requires('largefile', 'test requires %s bytes and a long time to run' % str(0x180000000)) - with open(TESTFN, 'wb') as f: - try: - f.seek(num_zeroes) - f.write(tail) - f.flush() - except (IOError, OverflowError): - raise unittest.SkipTest("filesystem does not have largefile support") + f = open(TESTFN, 'w+b') + try: + f.seek(num_zeroes) + f.write(tail) + f.flush() + except (IOError, OverflowError): + raise unittest.SkipTest("filesystem does not have largefile support") + return f def test_large_offset(self): - self._create_test_file(0x14FFFFFFF, b" ") - with open(TESTFN, 'rb') as f: + with self._make_test_file(0x14FFFFFFF, b" ") as f: m = mmap.mmap(f.fileno(), 0, offset=0x140000000, access=mmap.ACCESS_READ) try: self.assertEqual(m[0xFFFFFFF], 32) @@ -676,8 +676,7 @@ class LargeMmapTests(unittest.TestCase): m.close() def test_large_filesize(self): - self._create_test_file(0x17FFFFFFF, b" ") - with open(TESTFN, 'rb') as f: + with self._make_test_file(0x17FFFFFFF, b" ") as f: m = mmap.mmap(f.fileno(), 0x10000, access=mmap.ACCESS_READ) try: self.assertEqual(m.size(), 0x180000000) @@ -690,8 +689,7 @@ class LargeMmapTests(unittest.TestCase): tail = b' DEARdear ' start = boundary - len(tail) // 2 end = start + len(tail) - self._create_test_file(start, tail) - with open(TESTFN, 'rb') as f: + with self._make_test_file(start, tail) as f: m = mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ) try: self.assertEqual(m[start:end], tail) |