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)
| 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): |
nothing calls this directly
no test coverage detected