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

Method test_resize_up_anonymous_mapping

Lib/test/test_mmap.py:898–917  ·  view source on GitHub ↗

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

(self)

Source from the content-addressed store, hash-verified

896
897 @unittest.skipUnless(hasattr(mmap.mmap, 'resize'), 'requires mmap.resize')
898 def test_resize_up_anonymous_mapping(self):
899 """If the mmap is backed by the pagefile ensure a resize up can happen
900 and that the original data is still in place
901 """
902 start_size = PAGESIZE
903 new_size = 2 * start_size
904 data = random.randbytes(start_size)
905
906 with mmap.mmap(-1, start_size) as m:
907 m[:] = data
908 if sys.platform.startswith(('linux', 'android')):
909 # Can't expand a shared anonymous mapping on Linux.
910 # See https://bugzilla.kernel.org/show_bug.cgi?id=8691
911 with self.assertRaises(ValueError):
912 m.resize(new_size)
913 else:
914 m.resize(new_size)
915 self.assertEqual(len(m), new_size)
916 self.assertEqual(m[:start_size], data)
917 self.assertEqual(m[start_size:], b'\0' * (new_size - start_size))
918
919 @unittest.skipUnless(os.name == 'posix', 'requires Posix')
920 @unittest.skipUnless(hasattr(mmap.mmap, 'resize'), 'requires mmap.resize')

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected