MCPcopy Index your code
hub / github.com/python/cpython / test_resize_down_anonymous_mapping

Method test_resize_down_anonymous_mapping

Lib/test/test_mmap.py:934–950  ·  view source on GitHub ↗

If the mmap is backed by the pagefile ensure a resize down up can happen and that a truncated form of the original data is still in place

(self)

Source from the content-addressed store, hash-verified

932
933 @unittest.skipUnless(hasattr(mmap.mmap, 'resize'), 'requires mmap.resize')
934 def test_resize_down_anonymous_mapping(self):
935 """If the mmap is backed by the pagefile ensure a resize down up can happen
936 and that a truncated form of the original data is still in place
937 """
938 start_size = 2 * PAGESIZE
939 new_size = start_size // 2
940 data = random.randbytes(start_size)
941
942 with mmap.mmap(-1, start_size) as m:
943 m[:] = data
944 m.resize(new_size)
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)
951
952 @unittest.skipUnless(os.name == 'nt', 'requires Windows')
953 def test_resize_fails_if_mapping_held_elsewhere(self):

Callers

nothing calls this directly

Calls 5

randbytesMethod · 0.45
resizeMethod · 0.45
assertEqualMethod · 0.45
startswithMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected