summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Berg <sebastian@sipsolutions.net>2022-02-03 16:58:36 -0600
committerSebastian Berg <sebastian@sipsolutions.net>2022-02-03 20:35:36 -0600
commit8e4dfdaffe8f6149c8768a2d91158184244d0b79 (patch)
tree531952d17c00a994be1a219035cd5dd3157a306c
parent7c7e41f1a9e06bfe1c852e1971077a3fa6446db7 (diff)
downloadnumpy-8e4dfdaffe8f6149c8768a2d91158184244d0b79.tar.gz
TST: Test object cleanup on error in fromiter
-rw-r--r--numpy/core/tests/test_numeric.py20
1 files changed, 8 insertions, 12 deletions
diff --git a/numpy/core/tests/test_numeric.py b/numpy/core/tests/test_numeric.py
index d6d051c28..1d1ebfdd0 100644
--- a/numpy/core/tests/test_numeric.py
+++ b/numpy/core/tests/test_numeric.py
@@ -1202,18 +1202,14 @@ class TestFromiter:
raise NIterError('error at index %s' % eindex)
yield e
- def test_2592(self):
- # Test iteration exceptions are correctly raised.
- count, eindex = 10, 5
- assert_raises(NIterError, np.fromiter,
- self.load_data(count, eindex), dtype=int, count=count)
-
- def test_2592_edge(self):
- # Test iter. exceptions, edge case (exception at end of iterator).
- count = 10
- eindex = count-1
- assert_raises(NIterError, np.fromiter,
- self.load_data(count, eindex), dtype=int, count=count)
+ @pytest.mark.parametrize("dtype", [int, object])
+ @pytest.mark.parametrize(["count", "error_index"], [(10, 5), (10, 9)])
+ def test_2592(self, count, error_index, dtype):
+ # Test iteration exceptions are correctly raised. The data/generator
+ # has `count` elements but errors at `error_index`
+ iterable = self.load_data(count, error_index)
+ with pytest.raises(NIterError):
+ np.fromiter(iterable, dtype=dtype, count=count)
@pytest.mark.parametrize("dtype", ["S", "S0", "V0", "U0"])
def test_empty_not_structured(self, dtype):