test_pyf_src.py 1.1 KB

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