If the mmap is backed by the pagefile ensure a resize up can happen and that the original data is still in place
(self)
| 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') |
nothing calls this directly
no test coverage detected