codekingpro/portable-devtools
115k
1# This test is ported from numpy.distutils
2from numpy.f2py._src_pyf import process_str
3from numpy.testing import assert_equal
4
5pyf_src = """
6python module foo
7 <_rd=real,double precision>
8 interface
9 subroutine <s,d>foosub(tol)
10 <_rd>, intent(in,out) :: tol
11 end subroutine <s,d>foosub
12 end interface
13end python module foo
14"""
15
16expected_pyf = """
17python module foo
18 interface
19 subroutine sfoosub(tol)
20 real, intent(in,out) :: tol
21 end subroutine sfoosub
22 subroutine dfoosub(tol)
23 double precision, intent(in,out) :: tol
24 end subroutine dfoosub
25 end interface
26end python module foo
27"""
28
29
30def normalize_whitespace(s):
31 """
32 Remove leading and trailing whitespace, and convert internal
33 stretches of whitespace to a single space.
34 """
35 return ' '.join(s.split())
36
37
38def test_from_template():
39 """Regression test for gh-10712."""
40 pyf = process_str(pyf_src)
41 normalized_pyf = normalize_whitespace(pyf)
42 normalized_expected_pyf = normalize_whitespace(expected_pyf)
43 assert_equal(normalized_pyf, normalized_expected_pyf)
44 