Issue #11277: Fix tests - crash will not trigger if the file is closed and reopened.
This commit is contained in:
parent
0d837ef2a5
commit
d0a8f16031
|
@ -645,21 +645,21 @@ class LargeMmapTests(unittest.TestCase):
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
unlink(TESTFN)
|
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':
|
if sys.platform[:3] == 'win' or sys.platform == 'darwin':
|
||||||
requires('largefile',
|
requires('largefile',
|
||||||
'test requires %s bytes and a long time to run' % str(0x180000000))
|
'test requires %s bytes and a long time to run' % str(0x180000000))
|
||||||
with open(TESTFN, 'wb') as f:
|
f = open(TESTFN, 'w+b')
|
||||||
try:
|
try:
|
||||||
f.seek(num_zeroes)
|
f.seek(num_zeroes)
|
||||||
f.write(tail)
|
f.write(tail)
|
||||||
f.flush()
|
f.flush()
|
||||||
except (IOError, OverflowError):
|
except (IOError, OverflowError):
|
||||||
raise unittest.SkipTest("filesystem does not have largefile support")
|
raise unittest.SkipTest("filesystem does not have largefile support")
|
||||||
|
return f
|
||||||
|
|
||||||
def test_large_offset(self):
|
def test_large_offset(self):
|
||||||
self._create_test_file(0x14FFFFFFF, b" ")
|
with self._make_test_file(0x14FFFFFFF, b" ") as f:
|
||||||
with open(TESTFN, 'rb') as f:
|
|
||||||
m = mmap.mmap(f.fileno(), 0, offset=0x140000000, access=mmap.ACCESS_READ)
|
m = mmap.mmap(f.fileno(), 0, offset=0x140000000, access=mmap.ACCESS_READ)
|
||||||
try:
|
try:
|
||||||
self.assertEqual(m[0xFFFFFFF], b" ")
|
self.assertEqual(m[0xFFFFFFF], b" ")
|
||||||
|
@ -667,8 +667,7 @@ class LargeMmapTests(unittest.TestCase):
|
||||||
m.close()
|
m.close()
|
||||||
|
|
||||||
def test_large_filesize(self):
|
def test_large_filesize(self):
|
||||||
self._create_test_file(0x17FFFFFFF, b" ")
|
with self._make_test_file(0x17FFFFFFF, b" ") as f:
|
||||||
with open(TESTFN, 'rb') as f:
|
|
||||||
m = mmap.mmap(f.fileno(), 0x10000, access=mmap.ACCESS_READ)
|
m = mmap.mmap(f.fileno(), 0x10000, access=mmap.ACCESS_READ)
|
||||||
try:
|
try:
|
||||||
self.assertEqual(m.size(), 0x180000000)
|
self.assertEqual(m.size(), 0x180000000)
|
||||||
|
@ -681,8 +680,7 @@ class LargeMmapTests(unittest.TestCase):
|
||||||
tail = b' DEARdear '
|
tail = b' DEARdear '
|
||||||
start = boundary - len(tail) // 2
|
start = boundary - len(tail) // 2
|
||||||
end = start + len(tail)
|
end = start + len(tail)
|
||||||
self._create_test_file(start, tail)
|
with self._make_test_file(start, tail) as f:
|
||||||
with open(TESTFN, 'rb') as f:
|
|
||||||
m = mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ)
|
m = mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ)
|
||||||
try:
|
try:
|
||||||
self.assertEqual(m[start:end], tail)
|
self.assertEqual(m[start:end], tail)
|
||||||
|
|
Loading…
Reference in New Issue