(self)
| 254 | @unittest.skipUnless(os.name == "posix", "requires Posix") |
| 255 | @unittest.skipUnless(hasattr(mmap.mmap, "resize"), "requires mmap.resize") |
| 256 | def test_flush(self): |
| 257 | mmap_filename = "test_mmap_file" |
| 258 | resize_to = 1024 |
| 259 | |
| 260 | def resize_and_flush(mm_obj): |
| 261 | mm_obj.resize(resize_to) |
| 262 | mm_obj.flush() |
| 263 | |
| 264 | with tempfile.TemporaryDirectory() as tmpdirname: |
| 265 | file_path = f"{tmpdirname}/{mmap_filename}" |
| 266 | with open(file_path, "wb+") as file: |
| 267 | file.write(b"CPython") |
| 268 | file.flush() |
| 269 | with mmap.mmap(file.fileno(), 1) as mm_obj: |
| 270 | run_concurrently( |
| 271 | worker_func=resize_and_flush, |
| 272 | args=(mm_obj,), |
| 273 | nthreads=NTHREADS, |
| 274 | ) |
| 275 | |
| 276 | self.assertEqual(os.path.getsize(file_path), resize_to) |
| 277 | |
| 278 | def test_mmap_export_as_memoryview(self): |
| 279 | """ |
nothing calls this directly
no test coverage detected