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

Function test_version_2_0_memmap

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

Source from the content-addressed store, hash-verified

681
682@pytest.mark.skipif(IS_WASM, reason="memmap doesn't work correctly")
683def test_version_2_0_memmap(tmpdir):
684 # requires more than 2 byte for header
685 dt = [(("%d" % i) * 100, float) for i in range(500)]
686 d = np.ones(1000, dtype=dt)
687 tf1 = os.path.join(tmpdir, f'version2_01.npy')
688 tf2 = os.path.join(tmpdir, f'version2_02.npy')
689
690 # 1.0 requested but data cannot be saved this way
691 assert_raises(ValueError, format.open_memmap, tf1, mode='w+', dtype=d.dtype,
692 shape=d.shape, version=(1, 0))
693
694 ma = format.open_memmap(tf1, mode='w+', dtype=d.dtype,
695 shape=d.shape, version=(2, 0))
696 ma[...] = d
697 ma.flush()
698 ma = format.open_memmap(tf1, mode='r', max_header_size=200000)
699 assert_array_equal(ma, d)
700
701 with warnings.catch_warnings(record=True) as w:
702 warnings.filterwarnings('always', '', UserWarning)
703 ma = format.open_memmap(tf2, mode='w+', dtype=d.dtype,
704 shape=d.shape, version=None)
705 assert_(w[0].category is UserWarning)
706 ma[...] = d
707 ma.flush()
708
709 ma = format.open_memmap(tf2, mode='r', max_header_size=200000)
710
711 assert_array_equal(ma, d)
712
713@pytest.mark.parametrize("mmap_mode", ["r", None])
714def test_huge_header(tmpdir, mmap_mode):

Callers

nothing calls this directly

Calls 5

assert_raisesFunction · 0.90
assert_array_equalFunction · 0.90
assert_Function · 0.90
joinMethod · 0.45
flushMethod · 0.45

Tested by

no test coverage detected