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

Method test_filelike_read_fails

numpy/lib/tests/test_loadtxt.py:846–861  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

844 object(), dtype=np.dtype("i"), filelike=True)
845
846 def test_filelike_read_fails(self):
847 # Can only be reached if loadtxt opens the file, so it is hard to do
848 # via the public interface (although maybe not impossible considering
849 # the current "DataClass" backing).
850 class BadFileLike:
851 counter = 0
852
853 def read(self, size):
854 self.counter += 1
855 if self.counter > 20:
856 raise RuntimeError("Bad bad bad!")
857 return "1,2,3\n"
858
859 with pytest.raises(RuntimeError, match="Bad bad bad!"):
860 np.core._multiarray_umath._load_from_filelike(
861 BadFileLike(), dtype=np.dtype("i"), filelike=True)
862
863 def test_filelike_bad_read(self):
864 # Can only be reached if loadtxt opens the file, so it is hard to do

Callers

nothing calls this directly

Calls 2

BadFileLikeClass · 0.85
dtypeMethod · 0.45

Tested by

no test coverage detected