test_modules.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import pytest
  2. import textwrap
  3. from . import util
  4. from numpy.testing import IS_PYPY
  5. @pytest.mark.slow
  6. class TestModuleFilterPublicEntities(util.F2PyTest):
  7. sources = [
  8. util.getpath(
  9. "tests", "src", "modules", "gh26920",
  10. "two_mods_with_one_public_routine.f90"
  11. )
  12. ]
  13. # we filter the only public function mod2
  14. only = ["mod1_func1", ]
  15. def test_gh26920(self):
  16. # if it compiles and can be loaded, things are fine
  17. pass
  18. @pytest.mark.slow
  19. class TestModuleWithoutPublicEntities(util.F2PyTest):
  20. sources = [
  21. util.getpath(
  22. "tests", "src", "modules", "gh26920",
  23. "two_mods_with_no_public_entities.f90"
  24. )
  25. ]
  26. only = ["mod1_func1", ]
  27. def test_gh26920(self):
  28. # if it compiles and can be loaded, things are fine
  29. pass
  30. @pytest.mark.slow
  31. class TestModuleDocString(util.F2PyTest):
  32. sources = [util.getpath("tests", "src", "modules", "module_data_docstring.f90")]
  33. @pytest.mark.xfail(IS_PYPY, reason="PyPy cannot modify tp_doc after PyType_Ready")
  34. def test_module_docstring(self):
  35. assert self.module.mod.__doc__ == textwrap.dedent(
  36. """\
  37. i : 'i'-scalar
  38. x : 'i'-array(4)
  39. a : 'f'-array(2,3)
  40. b : 'f'-array(-1,-1), not allocated\x00
  41. foo()\n
  42. Wrapper for ``foo``.\n\n"""
  43. )
  44. @pytest.mark.slow
  45. class TestModuleAndSubroutine(util.F2PyTest):
  46. module_name = "example"
  47. sources = [
  48. util.getpath("tests", "src", "modules", "gh25337", "data.f90"),
  49. util.getpath("tests", "src", "modules", "gh25337", "use_data.f90"),
  50. ]
  51. def test_gh25337(self):
  52. self.module.data.set_shift(3)
  53. assert "data" in dir(self.module)
  54. @pytest.mark.slow
  55. class TestUsedModule(util.F2PyTest):
  56. module_name = "fmath"
  57. sources = [
  58. util.getpath("tests", "src", "modules", "use_modules.f90"),
  59. ]
  60. def test_gh25867(self):
  61. compiled_mods = [x for x in dir(self.module) if "__" not in x]
  62. assert "useops" in compiled_mods
  63. assert self.module.useops.sum_and_double(3, 7) == 20
  64. assert "mathops" in compiled_mods
  65. assert self.module.mathops.add(3, 7) == 10