MCPcopy Create free account
hub / github.com/numpy/numpy / test_memmap_roundtrip

Function test_memmap_roundtrip

numpy/lib/tests/test_format.py:464–491  ·  view source on GitHub ↗
(tmpdir)

Source from the content-addressed store, hash-verified

462@pytest.mark.skipif(IS_WASM, reason="memmap doesn't work correctly")
463@pytest.mark.slow
464def 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
494def test_compressed_roundtrip(tmpdir):

Callers

nothing calls this directly

Calls 5

openFunction · 0.85
assert_equal_Function · 0.85
joinMethod · 0.45
flushMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected