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