diff options
author | ganesh-k13 <ganesh3597@gmail.com> | 2022-07-01 18:46:10 +0530 |
---|---|---|
committer | ganesh-k13 <ganesh3597@gmail.com> | 2022-07-01 18:46:13 +0530 |
commit | aaa4c911259bfaad8efcbac2051c5586bde5fe28 (patch) | |
tree | 70bf66bb3e199aed8fc2b32c5661d9c2192dc447 /numpy | |
parent | be3f69125bff394f06312941200e132342b1abb2 (diff) | |
download | numpy-aaa4c911259bfaad8efcbac2051c5586bde5fe28.tar.gz |
TST: Changed `raise` to `warns`
* Changed `raise` to `warns` and test for `RuntimeWarning`
* Added results check back
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/core/tests/test_umath.py | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/numpy/core/tests/test_umath.py b/numpy/core/tests/test_umath.py index 5b2a8f0f9..ad0673b7b 100644 --- a/numpy/core/tests/test_umath.py +++ b/numpy/core/tests/test_umath.py @@ -774,7 +774,7 @@ class TestDivisionOverflows: @pytest.mark.parametrize("operation", [np.remainder, np.fmod, np.divmod, np.floor_divide, operator.mod, operator.floordiv]) - @np.errstate(divide='raise', over='raise') + @np.errstate(divide='warn', over='warn') def test_overflows(self, dividend_dtype, divisor_dtype, operation): # SIMD tries to perform the operation on as many elements as possible # that is a multiple of the register's size. We resort to the @@ -790,36 +790,45 @@ class TestDivisionOverflows: divisor_dtype).itemsize and operation in ( np.divmod, np.floor_divide, TestDivisionOverflows.operator.floordiv): - with pytest.raises( - FloatingPointError, + with pytest.warns( + RuntimeWarning, match="overflow encountered in"): result = operation( dividend_dtype(np.iinfo(dividend_dtype).min), divisor_dtype(-1) ) + assert result == self.overflow_results[operation].nocast( + dividend_dtype) # Arrays for a in arrays: # In case of divmod, we need to flatten the result # column first as we get a column vector of quotient and # remainder and a normal flatten of the expected result. - with pytest.raises(FloatingPointError): + with pytest.warns( + RuntimeWarning, + match="overflow encountered in"): result = np.array(operation(a, divisor)).flatten('f') + expected_array = np.array( + [self.overflow_results[operation].nocast( + dividend_dtype)]*len(a)).flatten() + assert_array_equal(result, expected_array) else: # Scalars result = operation( dividend_dtype(np.iinfo(dividend_dtype).min), divisor_dtype(-1) ) - assert result == self.overflow_results[operation].casted(dividend_dtype) + assert result == self.overflow_results[operation].casted( + dividend_dtype) # Arrays for a in arrays: # See above comment on flatten result = np.array(operation(a, divisor)).flatten('f') expected_array = np.array( - [self.overflow_results[operation].casted(dividend_dtype)]*len(a) - ).flatten() + [self.overflow_results[operation].casted( + dividend_dtype)]*len(a)).flatten() assert_array_equal(result, expected_array) |