(tmpdir)
| 489 | @pytest.mark.skipif(IS_WASM, reason="memmap doesn't work correctly") |
| 490 | @pytest.mark.slow |
| 491 | def test_memmap_roundtrip(tmpdir): |
| 492 | for i, arr in enumerate(basic_arrays + record_arrays): |
| 493 | if arr.dtype.hasobject: |
| 494 | # Skip these since they can't be mmap'ed. |
| 495 | continue |
| 496 | # Write it out normally and through mmap. |
| 497 | nfn = os.path.join(tmpdir, f'normal{i}.npy') |
| 498 | mfn = os.path.join(tmpdir, f'memmap{i}.npy') |
| 499 | with open(nfn, 'wb') as fp: |
| 500 | format.write_array(fp, arr) |
| 501 | |
| 502 | fortran_order = ( |
| 503 | arr.flags.f_contiguous and not arr.flags.c_contiguous) |
| 504 | ma = format.open_memmap(mfn, mode='w+', dtype=arr.dtype, |
| 505 | shape=arr.shape, fortran_order=fortran_order) |
| 506 | ma[...] = arr |
| 507 | ma.flush() |
| 508 | |
| 509 | # Check that both of these files' contents are the same. |
| 510 | with open(nfn, 'rb') as fp: |
| 511 | normal_bytes = fp.read() |
| 512 | with open(mfn, 'rb') as fp: |
| 513 | memmap_bytes = fp.read() |
| 514 | assert_equal_(normal_bytes, memmap_bytes) |
| 515 | |
| 516 | # Check that reading the file using memmap works. |
| 517 | ma = format.open_memmap(nfn, mode='r') |
| 518 | ma.flush() |
| 519 | |
| 520 | |
| 521 | def test_compressed_roundtrip(tmpdir): |
nothing calls this directly
no test coverage detected
searching dependent graphs…