MCPcopy Index your code
hub / github.com/numpy/numpy / test_memmap_roundtrip

Function test_memmap_roundtrip

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

Source from the content-addressed store, hash-verified

489@pytest.mark.skipif(IS_WASM, reason="memmap doesn't work correctly")
490@pytest.mark.slow
491def 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
521def test_compressed_roundtrip(tmpdir):

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…