Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 909f6d2

Browse files
committed
Issue #11277: Fix tests - crash will not trigger if the file is closed and reopened.
1 parent ced1056 commit 909f6d2

1 file changed

Lines changed: 12 additions & 14 deletions

File tree

Lib/test/test_mmap.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -654,30 +654,29 @@ def setUp(self):
654654
def tearDown(self):
655655
unlink(TESTFN)
656656

657-
def _create_test_file(self, num_zeroes, tail):
657+
def _make_test_file(self, num_zeroes, tail):
658658
if sys.platform[:3] == 'win' or sys.platform == 'darwin':
659659
requires('largefile',
660660
'test requires %s bytes and a long time to run' % str(0x180000000))
661-
with open(TESTFN, 'wb') as f:
662-
try:
663-
f.seek(num_zeroes)
664-
f.write(tail)
665-
f.flush()
666-
except (IOError, OverflowError):
667-
raise unittest.SkipTest("filesystem does not have largefile support")
661+
f = open(TESTFN, 'w+b')
662+
try:
663+
f.seek(num_zeroes)
664+
f.write(tail)
665+
f.flush()
666+
except (IOError, OverflowError):
667+
raise unittest.SkipTest("filesystem does not have largefile support")
668+
return f
668669

669670
def test_large_offset(self):
670-
self._create_test_file(0x14FFFFFFF, b" ")
671-
with open(TESTFN, 'rb') as f:
671+
with self._make_test_file(0x14FFFFFFF, b" ") as f:
672672
m = mmap.mmap(f.fileno(), 0, offset=0x140000000, access=mmap.ACCESS_READ)
673673
try:
674674
self.assertEqual(m[0xFFFFFFF], 32)
675675
finally:
676676
m.close()
677677

678678
def test_large_filesize(self):
679-
self._create_test_file(0x17FFFFFFF, b" ")
680-
with open(TESTFN, 'rb') as f:
679+
with self._make_test_file(0x17FFFFFFF, b" ") as f:
681680
m = mmap.mmap(f.fileno(), 0x10000, access=mmap.ACCESS_READ)
682681
try:
683682
self.assertEqual(m.size(), 0x180000000)
@@ -690,8 +689,7 @@ def _test_around_boundary(self, boundary):
690689
tail = b' DEARdear '
691690
start = boundary - len(tail) // 2
692691
end = start + len(tail)
693-
self._create_test_file(start, tail)
694-
with open(TESTFN, 'rb') as f:
692+
with self._make_test_file(start, tail) as f:
695693
m = mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ)
696694
try:
697695
self.assertEqual(m[start:end], tail)

0 commit comments

Comments
 (0)