Skip to content

Commit 1d36a44

Browse files
committed
Fix tests with platform without mmap.resize
1 parent b1241ab commit 1d36a44

1 file changed

Lines changed: 18 additions & 27 deletions

File tree

Lib/test/test_mmap.py

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,7 @@ def test_madvise(self):
885885
self.assertEqual(m.madvise(mmap.MADV_NORMAL, 0, 2), None)
886886
self.assertEqual(m.madvise(mmap.MADV_NORMAL, 0, size), None)
887887

888+
@unittest.skipUnless(hasattr(mmap.mmap, 'resize'), 'requires mmap.resize')
888889
def test_resize_up_anonymous_mapping(self):
889890
"""If the mmap is backed by the pagefile ensure a resize up can happen
890891
and that the original data is still in place
@@ -901,32 +902,26 @@ def test_resize_up_anonymous_mapping(self):
901902
with self.assertRaises(ValueError):
902903
m.resize(new_size)
903904
else:
904-
try:
905-
m.resize(new_size)
906-
except SystemError:
907-
pass
908-
else:
909-
self.assertEqual(len(m), new_size)
910-
self.assertEqual(m[:start_size], data)
911-
self.assertEqual(m[start_size:], b'\0' * (new_size - start_size))
905+
m.resize(new_size)
906+
self.assertEqual(len(m), new_size)
907+
self.assertEqual(m[:start_size], data)
908+
self.assertEqual(m[start_size:], b'\0' * (new_size - start_size))
912909

913910
@unittest.skipUnless(os.name == 'posix', 'requires Posix')
911+
@unittest.skipUnless(hasattr(mmap.mmap, 'resize'), 'requires mmap.resize')
914912
def test_resize_up_private_anonymous_mapping(self):
915913
start_size = PAGESIZE
916914
new_size = 2 * start_size
917915
data = random.randbytes(start_size)
918916

919917
with mmap.mmap(-1, start_size, flags=mmap.MAP_PRIVATE) as m:
920918
m[:] = data
921-
try:
922-
m.resize(new_size)
923-
except SystemError:
924-
pass
925-
else:
926-
self.assertEqual(len(m), new_size)
927-
self.assertEqual(m[:start_size], data)
928-
self.assertEqual(m[start_size:], b'\0' * (new_size - start_size))
919+
m.resize(new_size)
920+
self.assertEqual(len(m), new_size)
921+
self.assertEqual(m[:start_size], data)
922+
self.assertEqual(m[start_size:], b'\0' * (new_size - start_size))
929923

924+
@unittest.skipUnless(hasattr(mmap.mmap, 'resize'), 'requires mmap.resize')
930925
def test_resize_down_anonymous_mapping(self):
931926
"""If the mmap is backed by the pagefile ensure a resize down up can happen
932927
and that a truncated form of the original data is still in place
@@ -937,17 +932,13 @@ def test_resize_down_anonymous_mapping(self):
937932

938933
with mmap.mmap(-1, start_size) as m:
939934
m[:] = data
940-
try:
941-
m.resize(new_size)
942-
except SystemError:
943-
pass
944-
else:
945-
self.assertEqual(len(m), new_size)
946-
self.assertEqual(m[:], data[:new_size])
947-
if sys.platform.startswith(('linux', 'android')):
948-
# Can't expand to its original size.
949-
with self.assertRaises(ValueError):
950-
m.resize(start_size)
935+
m.resize(new_size)
936+
self.assertEqual(len(m), new_size)
937+
self.assertEqual(m[:], data[:new_size])
938+
if sys.platform.startswith(('linux', 'android')):
939+
# Can't expand to its original size.
940+
with self.assertRaises(ValueError):
941+
m.resize(start_size)
951942

952943
@unittest.skipUnless(os.name == 'nt', 'requires Windows')
953944
def test_resize_fails_if_mapping_held_elsewhere(self):

0 commit comments

Comments
 (0)