Skip to content

Commit 8825fac

Browse files
committed
TST: Test f2py passing string array to callback.
See numpy#10027.
1 parent 9a36ead commit 8825fac

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

numpy/f2py/tests/test_callback.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
from __future__ import division, absolute_import, print_function
22

33
import math
4+
import sys
45
import textwrap
56

6-
from numpy import array
7+
import numpy as np
78
from numpy.testing import run_module_suite, assert_, assert_equal, dec
89
import util
910

@@ -47,6 +48,16 @@ class TestF77Callback(util.F2PyTest):
4748
a = callback(r)
4849
end
4950
51+
subroutine string_callback_array(callback, cu, lencu, a)
52+
external callback
53+
integer callback
54+
integer lencu
55+
character*8 cu(lencu)
56+
integer a
57+
cf2py intent(out) a
58+
59+
a = callback(cu, lencu)
60+
end
5061
"""
5162

5263
@dec.slow
@@ -119,6 +130,8 @@ def mth(self):
119130
r = t(a.mth)
120131
assert_(r == 9, repr(r))
121132

133+
@dec.knownfailureif(sys.platform=='win32',
134+
msg='Fails with MinGW64 Gfortran (Issue #9673)')
122135
def test_string_callback(self):
123136

124137
def callback(code):
@@ -131,6 +144,25 @@ def callback(code):
131144
r = f(callback)
132145
assert_(r == 0, repr(r))
133146

147+
@dec.knownfailureif(sys.platform=='win32',
148+
msg='Fails with MinGW64 Gfortran (Issue #9673)')
149+
def test_string_callback_array(self):
150+
# See gh-10027
151+
cu = np.zeros((1, 8), 'S1')
152+
153+
def callback(cu, lencu):
154+
if cu.shape != (lencu, 8):
155+
return 1
156+
if cu.dtype != 'S1':
157+
return 2
158+
if not np.all(cu == b''):
159+
return 3
160+
return 0
161+
162+
f = getattr(self.module, 'string_callback_array')
163+
res = f(callback, cu, len(cu))
164+
assert_(res == 0, repr(res))
165+
134166

135167
if __name__ == "__main__":
136168
run_module_suite()

0 commit comments

Comments
 (0)