summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorNadeem Vawda <nadeem.vawda@gmail.com>2011-05-07 12:17:27 (GMT)
committerNadeem Vawda <nadeem.vawda@gmail.com>2011-05-07 12:17:27 (GMT)
commitce792301738bc6a1e95d0310bacb664f8d31a747 (patch)
tree34a2e5e8103bb9b7090616586eadfa8e62276331 /Lib
parent02e656962854d15f9adc2f3cde03950ad440b094 (diff)
parent044dfadd1c94cd9e69f15346e6ba0c9d4ef7a60d (diff)
downloadcpython-ce792301738bc6a1e95d0310bacb664f8d31a747.zip
cpython-ce792301738bc6a1e95d0310bacb664f8d31a747.tar.gz
cpython-ce792301738bc6a1e95d0310bacb664f8d31a747.tar.bz2
Merge: #11277: Fix tests - crash will not trigger if the file is closed and reopened.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_mmap.py26
1 files changed, 12 insertions, 14 deletions
diff --git a/Lib/test/test_mmap.py b/Lib/test/test_mmap.py
index be588cf..850768f 100644
--- a/Lib/test/test_mmap.py
+++ b/Lib/test/test_mmap.py
@@ -663,27 +663,26 @@ 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:
with mmap.mmap(f.fileno(), 0, offset=0x140000000, access=mmap.ACCESS_READ) as m:
self.assertEqual(m[0xFFFFFFF], 32)
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:
with mmap.mmap(f.fileno(), 0x10000, access=mmap.ACCESS_READ) as m:
self.assertEqual(m.size(), 0x180000000)
@@ -693,8 +692,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:
with mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ) as m:
self.assertEqual(m[start:end], tail)