m2m模型翻译
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.8 KiB

6 months ago
  1. import textwrap
  2. from . import util
  3. from numpy.f2py import crackfortran
  4. class TestAbstractInterface(util.F2PyTest):
  5. suffix = '.f90'
  6. skip = ['add1', 'add2']
  7. code = textwrap.dedent("""
  8. module ops_module
  9. abstract interface
  10. subroutine op(x, y, z)
  11. integer, intent(in) :: x, y
  12. integer, intent(out) :: z
  13. end subroutine
  14. end interface
  15. contains
  16. subroutine foo(x, y, r1, r2)
  17. integer, intent(in) :: x, y
  18. integer, intent(out) :: r1, r2
  19. procedure (op) add1, add2
  20. procedure (op), pointer::p
  21. p=>add1
  22. call p(x, y, r1)
  23. p=>add2
  24. call p(x, y, r2)
  25. end subroutine
  26. end module
  27. subroutine add1(x, y, z)
  28. integer, intent(in) :: x, y
  29. integer, intent(out) :: z
  30. z = x + y
  31. end subroutine
  32. subroutine add2(x, y, z)
  33. integer, intent(in) :: x, y
  34. integer, intent(out) :: z
  35. z = x + 2 * y
  36. end subroutine
  37. """)
  38. def test_abstract_interface(self):
  39. assert self.module.ops_module.foo(3, 5) == (8, 13)
  40. def test_parse_abstract_interface(self, tmp_path):
  41. # Test gh18403
  42. f_path = tmp_path / "gh18403_mod.f90"
  43. with f_path.open('w') as ff:
  44. ff.write(textwrap.dedent("""\
  45. module test
  46. abstract interface
  47. subroutine foo()
  48. end subroutine
  49. end interface
  50. end module test
  51. """))
  52. mod = crackfortran.crackfortran([str(f_path)])
  53. assert len(mod) == 1
  54. assert len(mod[0]['body']) == 1
  55. assert mod[0]['body'][0]['block'] == 'abstract interface'