summaryrefslogtreecommitdiff
path: root/numpy/f2py
diff options
context:
space:
mode:
authorRohit Goswami <rog32@hi.is>2021-11-28 06:06:28 +0000
committerRohit Goswami <rog32@hi.is>2021-12-03 03:15:36 +0000
commit3c92ba281502393283caffe995c1a0662f2c9f84 (patch)
tree9e39a877980e00cafd995459d47383edaf78b13d /numpy/f2py
parent0e10696f55576441fd820279d9ec10cd9f2a4c5d (diff)
downloadnumpy-3c92ba281502393283caffe995c1a0662f2c9f84.tar.gz
TST,STY: Clean up F2PY tests for pathlib.Path
Diffstat (limited to 'numpy/f2py')
-rw-r--r--numpy/f2py/tests/test_abstract_interface.py20
-rw-r--r--numpy/f2py/tests/test_array_from_pyobj.py7
-rw-r--r--numpy/f2py/tests/test_assumed_shape.py14
-rw-r--r--numpy/f2py/tests/test_common.py5
-rw-r--r--numpy/f2py/tests/test_kind.py7
-rw-r--r--numpy/f2py/tests/test_mixed.py9
-rw-r--r--numpy/f2py/tests/test_module_doc.py6
-rw-r--r--numpy/f2py/tests/test_parameter.py15
-rw-r--r--numpy/f2py/tests/test_regression.py8
-rw-r--r--numpy/f2py/tests/test_size.py6
-rw-r--r--numpy/f2py/tests/test_string.py6
-rw-r--r--numpy/f2py/tests/util.py15
12 files changed, 46 insertions, 72 deletions
diff --git a/numpy/f2py/tests/test_abstract_interface.py b/numpy/f2py/tests/test_abstract_interface.py
index 936c1f7bc..41b7d21c4 100644
--- a/numpy/f2py/tests/test_abstract_interface.py
+++ b/numpy/f2py/tests/test_abstract_interface.py
@@ -1,3 +1,4 @@
+from pathlib import Path
import textwrap
from . import util
from numpy.f2py import crackfortran
@@ -50,16 +51,15 @@ class TestAbstractInterface(util.F2PyTest):
def test_parse_abstract_interface(self, tmp_path):
# Test gh18403
- f_path = tmp_path / "gh18403_mod.f90"
- with f_path.open('w') as ff:
- ff.write(textwrap.dedent("""\
- module test
- abstract interface
- subroutine foo()
- end subroutine
- end interface
- end module test
- """))
+ f_path = Path(tmp_path / "gh18403_mod.f90")
+ f_path.write_text(textwrap.dedent("""\
+ module test
+ abstract interface
+ subroutine foo()
+ end subroutine
+ end interface
+ end module test
+ """))
mod = crackfortran.crackfortran([str(f_path)])
assert len(mod) == 1
assert len(mod[0]['body']) == 1
diff --git a/numpy/f2py/tests/test_array_from_pyobj.py b/numpy/f2py/tests/test_array_from_pyobj.py
index 649fd1c48..0407ff515 100644
--- a/numpy/f2py/tests/test_array_from_pyobj.py
+++ b/numpy/f2py/tests/test_array_from_pyobj.py
@@ -12,7 +12,6 @@ from . import util
wrap = None
-
def setup_module():
"""
Build the required testing extension module
@@ -31,9 +30,9 @@ def setup_module():
define_macros=[])
"""
d = os.path.dirname(__file__)
- src = [os.path.join(d, 'src', 'array_from_pyobj', 'wrapmodule.c'),
- os.path.join(d, '..', 'src', 'fortranobject.c'),
- os.path.join(d, '..', 'src', 'fortranobject.h')]
+ src = [util.getpath('tests', 'src', 'array_from_pyobj', 'wrapmodule.c'),
+ util.getpath('src', 'fortranobject.c'),
+ util.getpath('src', 'fortranobject.h')]
wrap = util.build_module_distutils(src, config_code,
'test_array_from_pyobj_ext')
diff --git a/numpy/f2py/tests/test_assumed_shape.py b/numpy/f2py/tests/test_assumed_shape.py
index 79e3ad138..8c86edfc8 100644
--- a/numpy/f2py/tests/test_assumed_shape.py
+++ b/numpy/f2py/tests/test_assumed_shape.py
@@ -6,16 +6,12 @@ from numpy.testing import assert_
from . import util
-def _path(*a):
- return os.path.join(*((os.path.dirname(__file__),) + a))
-
-
class TestAssumedShapeSumExample(util.F2PyTest):
- sources = [_path('src', 'assumed_shape', 'foo_free.f90'),
- _path('src', 'assumed_shape', 'foo_use.f90'),
- _path('src', 'assumed_shape', 'precision.f90'),
- _path('src', 'assumed_shape', 'foo_mod.f90'),
- _path('src', 'assumed_shape', '.f2py_f2cmap'),
+ sources = [util.getpath('tests', 'src', 'assumed_shape', 'foo_free.f90'),
+ util.getpath('tests', 'src', 'assumed_shape', 'foo_use.f90'),
+ util.getpath('tests', 'src', 'assumed_shape', 'precision.f90'),
+ util.getpath('tests', 'src', 'assumed_shape', 'foo_mod.f90'),
+ util.getpath('tests', 'src', 'assumed_shape', '.f2py_f2cmap'),
]
@pytest.mark.slow
diff --git a/numpy/f2py/tests/test_common.py b/numpy/f2py/tests/test_common.py
index e4bf35504..62587e7a9 100644
--- a/numpy/f2py/tests/test_common.py
+++ b/numpy/f2py/tests/test_common.py
@@ -7,11 +7,8 @@ from . import util
from numpy.testing import assert_array_equal
-def _path(*a):
- return os.path.join(*((os.path.dirname(__file__),) + a))
-
class TestCommonBlock(util.F2PyTest):
- sources = [_path('src', 'common', 'block.f')]
+ sources = [util.getpath('tests', 'src', 'common', 'block.f')]
@pytest.mark.skipif(sys.platform=='win32',
reason='Fails with MinGW64 Gfortran (Issue #9673)')
diff --git a/numpy/f2py/tests/test_kind.py b/numpy/f2py/tests/test_kind.py
index a7e2b28ed..2ac519ca7 100644
--- a/numpy/f2py/tests/test_kind.py
+++ b/numpy/f2py/tests/test_kind.py
@@ -8,13 +8,8 @@ from numpy.f2py.crackfortran import (
)
from . import util
-
-def _path(*a):
- return os.path.join(*((os.path.dirname(__file__),) + a))
-
-
class TestKind(util.F2PyTest):
- sources = [_path('src', 'kind', 'foo.f90')]
+ sources = [util.getpath('tests', 'src', 'kind', 'foo.f90')]
@pytest.mark.slow
def test_all(self):
diff --git a/numpy/f2py/tests/test_mixed.py b/numpy/f2py/tests/test_mixed.py
index 04266ca5b..266e9c0d9 100644
--- a/numpy/f2py/tests/test_mixed.py
+++ b/numpy/f2py/tests/test_mixed.py
@@ -6,14 +6,11 @@ from numpy.testing import assert_, assert_equal, IS_PYPY
from . import util
-def _path(*a):
- return os.path.join(*((os.path.dirname(__file__),) + a))
-
class TestMixed(util.F2PyTest):
- sources = [_path('src', 'mixed', 'foo.f'),
- _path('src', 'mixed', 'foo_fixed.f90'),
- _path('src', 'mixed', 'foo_free.f90')]
+ sources = [util.getpath('tests', 'src', 'mixed', 'foo.f'),
+ util.getpath('tests', 'src', 'mixed', 'foo_fixed.f90'),
+ util.getpath('tests', 'src', 'mixed', 'foo_free.f90')]
def test_all(self):
assert_(self.module.bar11() == 11)
diff --git a/numpy/f2py/tests/test_module_doc.py b/numpy/f2py/tests/test_module_doc.py
index 4b9555cee..92c03c003 100644
--- a/numpy/f2py/tests/test_module_doc.py
+++ b/numpy/f2py/tests/test_module_doc.py
@@ -7,12 +7,8 @@ from . import util
from numpy.testing import assert_equal, IS_PYPY
-def _path(*a):
- return os.path.join(*((os.path.dirname(__file__),) + a))
-
-
class TestModuleDocString(util.F2PyTest):
- sources = [_path('src', 'module_data', 'module_data_docstring.f90')]
+ sources = [util.getpath('tests', 'src', 'module_data', 'module_data_docstring.f90')]
@pytest.mark.skipif(sys.platform=='win32',
reason='Fails with MinGW64 Gfortran (Issue #9673)')
diff --git a/numpy/f2py/tests/test_parameter.py b/numpy/f2py/tests/test_parameter.py
index b61827169..22e1b52d3 100644
--- a/numpy/f2py/tests/test_parameter.py
+++ b/numpy/f2py/tests/test_parameter.py
@@ -6,18 +6,13 @@ from numpy.testing import assert_raises, assert_equal
from . import util
-
-def _path(*a):
- return os.path.join(*((os.path.dirname(__file__),) + a))
-
-
class TestParameters(util.F2PyTest):
# Check that intent(in out) translates as intent(inout)
- sources = [_path('src', 'parameter', 'constant_real.f90'),
- _path('src', 'parameter', 'constant_integer.f90'),
- _path('src', 'parameter', 'constant_both.f90'),
- _path('src', 'parameter', 'constant_compound.f90'),
- _path('src', 'parameter', 'constant_non_compound.f90'),
+ sources = [util.getpath('tests', 'src', 'parameter', 'constant_real.f90'),
+ util.getpath('tests', 'src', 'parameter', 'constant_integer.f90'),
+ util.getpath('tests', 'src', 'parameter', 'constant_both.f90'),
+ util.getpath('tests', 'src', 'parameter', 'constant_compound.f90'),
+ util.getpath('tests', 'src', 'parameter', 'constant_non_compound.f90'),
]
@pytest.mark.slow
diff --git a/numpy/f2py/tests/test_regression.py b/numpy/f2py/tests/test_regression.py
index b91499e4a..da279d772 100644
--- a/numpy/f2py/tests/test_regression.py
+++ b/numpy/f2py/tests/test_regression.py
@@ -7,13 +7,9 @@ from numpy.testing import assert_, assert_raises, assert_equal, assert_string_eq
from . import util
-def _path(*a):
- return os.path.join(*((os.path.dirname(__file__),) + a))
-
-
class TestIntentInOut(util.F2PyTest):
# Check that intent(in out) translates as intent(inout)
- sources = [_path('src', 'regression', 'inout.f90')]
+ sources = [util.getpath('tests', 'src', 'regression', 'inout.f90')]
@pytest.mark.slow
def test_inout(self):
@@ -30,7 +26,7 @@ class TestIntentInOut(util.F2PyTest):
class TestNumpyVersionAttribute(util.F2PyTest):
# Check that th attribute __f2py_numpy_version__ is present
# in the compiled module and that has the value np.__version__.
- sources = [_path('src', 'regression', 'inout.f90')]
+ sources = [util.getpath('tests', 'src', 'regression', 'inout.f90')]
@pytest.mark.slow
def test_numpy_version_attribute(self):
diff --git a/numpy/f2py/tests/test_size.py b/numpy/f2py/tests/test_size.py
index b609fa77f..cabc340ce 100644
--- a/numpy/f2py/tests/test_size.py
+++ b/numpy/f2py/tests/test_size.py
@@ -5,12 +5,8 @@ from numpy.testing import assert_equal
from . import util
-def _path(*a):
- return os.path.join(*((os.path.dirname(__file__),) + a))
-
-
class TestSizeSumExample(util.F2PyTest):
- sources = [_path('src', 'size', 'foo.f90')]
+ sources = [util.getpath('tests', 'src', 'size', 'foo.f90')]
@pytest.mark.slow
def test_all(self):
diff --git a/numpy/f2py/tests/test_string.py b/numpy/f2py/tests/test_string.py
index 3a945ff8b..b5d18ce4b 100644
--- a/numpy/f2py/tests/test_string.py
+++ b/numpy/f2py/tests/test_string.py
@@ -6,12 +6,8 @@ import numpy as np
from . import util
-def _path(*a):
- return os.path.join(*((os.path.dirname(__file__),) + a))
-
-
class TestString(util.F2PyTest):
- sources = [_path('src', 'string', 'char.f90')]
+ sources = [util.getpath('tests', 'src', 'string', 'char.f90')]
@pytest.mark.slow
def test_char(self):
diff --git a/numpy/f2py/tests/util.py b/numpy/f2py/tests/util.py
index 1a6805e75..c1dc4a536 100644
--- a/numpy/f2py/tests/util.py
+++ b/numpy/f2py/tests/util.py
@@ -3,6 +3,7 @@ Utility functions for
- building and importing modules on test time, using a temporary location
- detecting if compilers are present
+- determining paths to tests
"""
import os
@@ -15,6 +16,7 @@ import textwrap
import re
import pytest
+from pathlib import Path
from numpy.compat import asbytes, asstr
from numpy.testing import temppath
from importlib import import_module
@@ -334,9 +336,9 @@ class F2PyTest:
needs_f77 = False
needs_f90 = False
for fn in codes:
- if fn.endswith('.f'):
+ if str( fn ).endswith('.f'):
needs_f77 = True
- elif fn.endswith('.f90'):
+ elif str( fn ).endswith('.f90'):
needs_f90 = True
if needs_f77 and not has_f77_compiler():
pytest.skip("No Fortran 77 compiler available")
@@ -354,3 +356,12 @@ class F2PyTest:
self.module = build_module(self.sources, options=self.options,
skip=self.skip, only=self.only,
module_name=self.module_name)
+
+#
+# Helper functions
+#
+
+def getpath(*a):
+ # Package root
+ d = Path(__file__).parent.parent.resolve()
+ return d.joinpath(*a)