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

Method test_mmap_close

numpy/core/tests/test_multiarray.py:5730–5742  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

5728 reason="PyPy's memoryview currently does not track exports. See: "
5729 "https://foss.heptapod.net/pypy/pypy/-/issues/3724")
5730 def test_mmap_close(self):
5731 # The old buffer protocol was not safe for some things that the new
5732 # one is. But `frombuffer` always used the old one for a long time.
5733 # Checks that it is safe with the new one (using memoryviews)
5734 with tempfile.TemporaryFile(mode='wb') as tmp:
5735 tmp.write(b"asdf")
5736 tmp.flush()
5737 mm = mmap.mmap(tmp.fileno(), 0)
5738 arr = np.frombuffer(mm, dtype=np.uint8)
5739 with pytest.raises(BufferError):
5740 mm.close() # cannot close while array uses the buffer
5741 del arr
5742 mm.close()
5743
5744class TestFlat:
5745 def setup_method(self):

Callers

nothing calls this directly

Calls 3

writeMethod · 0.45
flushMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected