diff options
| author | Sebastian Berg <sebastian@sipsolutions.net> | 2022-05-27 09:08:44 -0700 |
|---|---|---|
| committer | Sebastian Berg <sebastian@sipsolutions.net> | 2022-05-27 09:21:24 -0700 |
| commit | 1f79961352fe352195fd9e1e26ba807d399556b6 (patch) | |
| tree | 2559a4a5d4a9eda2ad85cb29b4eaf91de0658480 /numpy | |
| parent | 8fced79a8c60d86aaaaf997aa861589336f7899c (diff) | |
| download | numpy-1f79961352fe352195fd9e1e26ba807d399556b6.tar.gz | |
TST,MAINT: Simplify warning testing in masked arrays
There is no point in catching the warnigns when raising will do
(because we want 0 warnings). That is more informative in any case.
Diffstat (limited to 'numpy')
| -rw-r--r-- | numpy/ma/tests/test_core.py | 54 |
1 files changed, 18 insertions, 36 deletions
diff --git a/numpy/ma/tests/test_core.py b/numpy/ma/tests/test_core.py index c8f7f4269..0dada104d 100644 --- a/numpy/ma/tests/test_core.py +++ b/numpy/ma/tests/test_core.py @@ -2763,8 +2763,8 @@ class TestMaskedArrayInPlaceArithmetic: def test_inplace_addition_scalar_type(self): # Test of inplace additions for t in self.othertypes: - with warnings.catch_warnings(record=True) as w: - warnings.filterwarnings("always") + with warnings.catch_warnings(): + warnings.filterwarnings("error") (x, y, xm) = (_.astype(t) for _ in self.uint8data) xm[2] = masked x += t(1) @@ -2772,13 +2772,11 @@ class TestMaskedArrayInPlaceArithmetic: xm += t(1) assert_equal(xm, y + t(1)) - assert_equal(len(w), 0, f'Failed on type={t}.') - def test_inplace_addition_array_type(self): # Test of inplace additions for t in self.othertypes: - with warnings.catch_warnings(record=True) as w: - warnings.filterwarnings("always") + with warnings.catch_warnings(): + warnings.filterwarnings("error") (x, y, xm) = (_.astype(t) for _ in self.uint8data) m = xm.mask a = arange(10, dtype=t) @@ -2789,26 +2787,22 @@ class TestMaskedArrayInPlaceArithmetic: assert_equal(xm, y + a) assert_equal(xm.mask, mask_or(m, a.mask)) - assert_equal(len(w), 0, f'Failed on type={t}.') - def test_inplace_subtraction_scalar_type(self): # Test of inplace subtractions for t in self.othertypes: - with warnings.catch_warnings(record=True) as w: - warnings.filterwarnings("always") + with warnings.catch_warnings(): + warnings.filterwarnings("error") (x, y, xm) = (_.astype(t) for _ in self.uint8data) x -= t(1) assert_equal(x, y - t(1)) xm -= t(1) assert_equal(xm, y - t(1)) - assert_equal(len(w), 0, f'Failed on type={t}.') - def test_inplace_subtraction_array_type(self): # Test of inplace subtractions for t in self.othertypes: - with warnings.catch_warnings(record=True) as w: - warnings.filterwarnings("always") + with warnings.catch_warnings(): + warnings.filterwarnings("error") (x, y, xm) = (_.astype(t) for _ in self.uint8data) m = xm.mask a = arange(10, dtype=t) @@ -2819,26 +2813,22 @@ class TestMaskedArrayInPlaceArithmetic: assert_equal(xm, y - a) assert_equal(xm.mask, mask_or(m, a.mask)) - assert_equal(len(w), 0, f'Failed on type={t}.') - def test_inplace_multiplication_scalar_type(self): # Test of inplace multiplication for t in self.othertypes: - with warnings.catch_warnings(record=True) as w: - warnings.filterwarnings("always") + with warnings.catch_warnings(): + warnings.filterwarnings("error") (x, y, xm) = (_.astype(t) for _ in self.uint8data) x *= t(2) assert_equal(x, y * t(2)) xm *= t(2) assert_equal(xm, y * t(2)) - assert_equal(len(w), 0, f'Failed on type={t}.') - def test_inplace_multiplication_array_type(self): # Test of inplace multiplication for t in self.othertypes: - with warnings.catch_warnings(record=True) as w: - warnings.filterwarnings("always") + with warnings.catch_warnings(): + warnings.filterwarnings("error") (x, y, xm) = (_.astype(t) for _ in self.uint8data) m = xm.mask a = arange(10, dtype=t) @@ -2849,15 +2839,13 @@ class TestMaskedArrayInPlaceArithmetic: assert_equal(xm, y * a) assert_equal(xm.mask, mask_or(m, a.mask)) - assert_equal(len(w), 0, f'Failed on type={t}.') - def test_inplace_floor_division_scalar_type(self): # Test of inplace division # Check for TypeError in case of unsupported types unsupported = {np.dtype(t).type for t in np.typecodes["Complex"]} for t in self.othertypes: - with warnings.catch_warnings(record=True) as w: - warnings.filterwarnings("always") + with warnings.catch_warnings(): + warnings.filterwarnings("error") (x, y, xm) = (_.astype(t) for _ in self.uint8data) x = arange(10, dtype=t) * t(2) xm = arange(10, dtype=t) * t(2) @@ -2867,8 +2855,6 @@ class TestMaskedArrayInPlaceArithmetic: xm //= t(2) assert_equal(x, y) assert_equal(xm, y) - - assert_equal(len(w), 0, "Failed on type=%s." % t) except TypeError: msg = f"Supported type {t} throwing TypeError" assert t in unsupported, msg @@ -2878,8 +2864,8 @@ class TestMaskedArrayInPlaceArithmetic: # Check for TypeError in case of unsupported types unsupported = {np.dtype(t).type for t in np.typecodes["Complex"]} for t in self.othertypes: - with warnings.catch_warnings(record=True) as w: - warnings.filterwarnings("always") + with warnings.catch_warnings(): + warnings.filterwarnings("error") (x, y, xm) = (_.astype(t) for _ in self.uint8data) m = xm.mask a = arange(10, dtype=t) @@ -2893,8 +2879,6 @@ class TestMaskedArrayInPlaceArithmetic: xm.mask, mask_or(mask_or(m, a.mask), (a == t(0))) ) - - assert_equal(len(w), 0, f'Failed on type={t}.') except TypeError: msg = f"Supported type {t} throwing TypeError" assert t in unsupported, msg @@ -2977,8 +2961,8 @@ class TestMaskedArrayInPlaceArithmetic: def test_inplace_pow_type(self): # Test keeping data w/ (inplace) power for t in self.othertypes: - with warnings.catch_warnings(record=True) as w: - warnings.filterwarnings("always") + with warnings.catch_warnings(): + warnings.filterwarnings("error") # Test pow on scalar x = array([1, 2, 3], mask=[0, 0, 1], dtype=t) xx = x ** t(2) @@ -2990,8 +2974,6 @@ class TestMaskedArrayInPlaceArithmetic: assert_equal(x.data, xx_r.data) assert_equal(x.mask, xx_r.mask) - assert_equal(len(w), 0, f'Failed on type={t}.') - class TestMaskedArrayMethods: # Test class for miscellaneous MaskedArrays methods. |
