From d2473c052eb70849575246f99fde1a055087fb61 Mon Sep 17 00:00:00 2001 From: Sebastian Berg Date: Thu, 13 Jan 2022 20:30:33 -0600 Subject: TST,BUG: Additional bad-file-like test, add missing error path free And remove one silly leftover struct member that was unused --- numpy/lib/tests/test_io.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'numpy/lib/tests/test_io.py') diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py index 7ec44045f..cf55c97bf 100644 --- a/numpy/lib/tests/test_io.py +++ b/numpy/lib/tests/test_io.py @@ -3387,6 +3387,20 @@ class TestCReaderUnitTests: np.core._multiarray_umath._load_from_filelike( BadFileLike(), dtype=np.dtype("i"), filelike=True) + def test_filelike_bad_read(self): + # Can only be reached if loadtxt opens the file, so it is hard to do + # via the public interface (although maybe not impossible considering + # the current "DataClass" backing). + class BadFileLike: + counter = 0 + def read(self, size): + return 1234 # not a string! + + with pytest.raises(TypeError, + match="non-string returned while reading data"): + np.core._multiarray_umath._load_from_filelike( + BadFileLike(), dtype=np.dtype("i"), filelike=True) + def test_not_an_iter(self): with pytest.raises(TypeError, match="error reading from object, expected an iterable"): -- cgit v1.2.1