(tmpdir)
| 462 | @pytest.mark.skipif(IS_WASM, reason="memmap doesn't work correctly") |
| 463 | @pytest.mark.slow |
| 464 | def test_memmap_roundtrip(tmpdir): |
| 465 | for i, arr in enumerate(basic_arrays + record_arrays): |
| 466 | if arr.dtype.hasobject: |
| 467 | # Skip these since they can't be mmap'ed. |
| 468 | continue |
| 469 | # Write it out normally and through mmap. |
| 470 | nfn = os.path.join(tmpdir, f'normal{i}.npy') |
| 471 | mfn = os.path.join(tmpdir, f'memmap{i}.npy') |
| 472 | with open(nfn, 'wb') as fp: |
| 473 | format.write_array(fp, arr) |
| 474 | |
| 475 | fortran_order = ( |
| 476 | arr.flags.f_contiguous and not arr.flags.c_contiguous) |
| 477 | ma = format.open_memmap(mfn, mode='w+', dtype=arr.dtype, |
| 478 | shape=arr.shape, fortran_order=fortran_order) |
| 479 | ma[...] = arr |
| 480 | ma.flush() |
| 481 | |
| 482 | # Check that both of these files' contents are the same. |
| 483 | with open(nfn, 'rb') as fp: |
| 484 | normal_bytes = fp.read() |
| 485 | with open(mfn, 'rb') as fp: |
| 486 | memmap_bytes = fp.read() |
| 487 | assert_equal_(normal_bytes, memmap_bytes) |
| 488 | |
| 489 | # Check that reading the file using memmap works. |
| 490 | ma = format.open_memmap(nfn, mode='r') |
| 491 | ma.flush() |
| 492 | |
| 493 | |
| 494 | def test_compressed_roundtrip(tmpdir): |
nothing calls this directly
no test coverage detected