Skip to content

Commit e15a7ff

Browse files
HaoZekebilderbuchi
andcommitted
TST: Callbacks with callstatement
Co-authored-by: bilderbuchi <[email protected]>
1 parent 770811c commit e15a7ff

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module utils
2+
implicit none
3+
contains
4+
subroutine my_abort(message)
5+
implicit none
6+
character(len=*), intent(in) :: message
7+
!f2py callstatement PyErr_SetString(PyExc_ValueError, message);f2py_success = 0;
8+
!f2py callprotoargument char*
9+
write(0,*) "THIS SHOULD NOT APPEAR"
10+
stop 1
11+
end subroutine my_abort
12+
13+
subroutine do_something(message)
14+
!f2py intent(callback, hide) mypy_abort
15+
character(len=*), intent(in) :: message
16+
call mypy_abort(message)
17+
end subroutine do_something
18+
end module utils

numpy/f2py/tests/test_callback.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,3 +244,14 @@ def bar(x):
244244

245245
res = self.module.foo(bar)
246246
assert res == 110
247+
248+
249+
@pytest.mark.slow
250+
class TestCBFortranCallstatement(util.F2PyTest):
251+
sources = [util.getpath("tests", "src", "callback", "gh26681.f90")]
252+
options = ['--lower']
253+
254+
def test_callstatement_fortran(self):
255+
with pytest.raises(ValueError, match='helpme') as exc:
256+
self.module.mypy_abort = self.module.utils.my_abort
257+
self.module.utils.do_something('helpme')

0 commit comments

Comments
 (0)