summaryrefslogtreecommitdiff
path: root/numpy/lib/tests/test_io.py
diff options
context:
space:
mode:
authorSebastian Berg <sebastian@sipsolutions.net>2022-01-13 20:30:33 -0600
committerSebastian Berg <sebastian@sipsolutions.net>2022-01-14 20:07:07 -0600
commitd2473c052eb70849575246f99fde1a055087fb61 (patch)
tree19578be49a3ddd196d8302a7f9a8864c4596487c /numpy/lib/tests/test_io.py
parent73940d6b08a5b3690799bfdd68bb514ee1445b16 (diff)
downloadnumpy-d2473c052eb70849575246f99fde1a055087fb61.tar.gz
TST,BUG: Additional bad-file-like test, add missing error path free
And remove one silly leftover struct member that was unused
Diffstat (limited to 'numpy/lib/tests/test_io.py')
-rw-r--r--numpy/lib/tests/test_io.py14
1 files changed, 14 insertions, 0 deletions
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"):