Skip to content

Commit 92e56da

Browse files
authored
TST: Add tests for numpygh-30809 intent(inplace) deprecation
Tests verify VisibleDeprecationWarning is raised only when casting is needed for intent(inplace) arrays.
1 parent 2166708 commit 92e56da

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

‎numpy/f2py/tests/test_regression.py‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,3 +185,39 @@ def test_gh27167(self):
185185
assert (self.module.f_globals.n_max == 16)
186186
assert (self.module.f_globals.i_max == 18)
187187
assert (self.module.f_globals.j_max == 72)
188+
189+
class TestGH30809(util.F2PyTest):
190+
"""Tests for gh-30809: intent(inplace) deprecation warning"""
191+
sources = [util.getpath("tests", "src", "regression", "gh30809.f90")]
192+
193+
@pytest.mark.slow
194+
def test_intent_inplace_warns_on_cast(self):
195+
"""Warn when dtype mismatch requires casting"""
196+
arr = np.array([1, 2, 3, 4], dtype=np.int32)
197+
198+
with pytest.warns(np.VisibleDeprecationWarning,
199+
match="intent\\(inplace\\).*casting"):
200+
self.module.inplace_sum(arr)
201+
202+
@pytest.mark.slow
203+
def test_intent_inplace_no_warn_correct_dtype(self):
204+
"""No warning when dtype is correct"""
205+
arr = np.array([1.0, 2.0, 3.0, 4.0], dtype=np.float64)
206+
207+
with pytest.warns(None) as record:
208+
self.module.inplace_sum(arr)
209+
assert len(record) == 0
210+
211+
@pytest.mark.slow
212+
def test_intent_inplace_warning_as_error(self):
213+
"""Test warning can be converted to error"""
214+
import warnings
215+
216+
arr = np.array([1, 2, 3, 4], dtype=np.int32)
217+
218+
with warnings.catch_warnings():
219+
warnings.filterwarnings('error', category=np.VisibleDeprecationWarning)
220+
221+
with pytest.raises(np.VisibleDeprecationWarning,
222+
match="intent\\(inplace\\).*casting"):
223+
self.module.inplace_sum(arr)

0 commit comments

Comments
 (0)