GeezerVison is showing github.com — TST: Use `meson` for testing ``f2py`` (#25111) · charris/numpy@774e0a8
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: numpy/distutils/tests/test_build_ext.py +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -18,7 +18,7 @@ def test_multi_fortran_libs_link(tmp_path): | 18 | 18 | # We need to make sure we actually have an f77 compiler. | 19 | 19 | # This is nontrivial, so we'll borrow the utilities | 20 | 20 | # from f2py tests: | 21 | | - from numpy.f2py.tests.util import has_f77_compiler | | 21 | + from numpy.distutils.tests.utilities import has_f77_compiler | 22 | 22 | if not has_f77_compiler(): | 23 | 23 | pytest.skip('No F77 compiler found') | 24 | 24 |
| |
Collapse file Copy file name to clipboard +90Lines changed: 90 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +# Kanged out of numpy.f2py.tests.util for test_build_ext | | 2 | +from numpy.testing import IS_WASM | | 3 | +import textwrap | | 4 | +import shutil | | 5 | +import tempfile | | 6 | +import os | | 7 | +import re | | 8 | +import subprocess | | 9 | +import sys | | 10 | + | | 11 | +# | | 12 | +# Check if compilers are available at all... | | 13 | +# | | 14 | + | | 15 | +_compiler_status = None | | 16 | + | | 17 | + | | 18 | +def _get_compiler_status(): | | 19 | + global _compiler_status | | 20 | + if _compiler_status is not None: | | 21 | + return _compiler_status | | 22 | + | | 23 | + _compiler_status = (False, False, False) | | 24 | + if IS_WASM: | | 25 | + # Can't run compiler from inside WASM. | | 26 | + return _compiler_status | | 27 | + | | 28 | + # XXX: this is really ugly. But I don't know how to invoke Distutils | | 29 | + # in a safer way... | | 30 | + code = textwrap.dedent( | | 31 | + f"""\ | | 32 | + import os | | 33 | + import sys | | 34 | + sys.path = {repr(sys.path)} | | 35 | +
| | 36 | + def configuration(parent_name='',top_path=None): | | 37 | + global config | | 38 | + from numpy.distutils.misc_util import Configuration | | 39 | + config = Configuration('', parent_name, top_path) | | 40 | + return config | | 41 | +
| | 42 | + from numpy.distutils.core import setup | | 43 | + setup(configuration=configuration) | | 44 | +
| | 45 | + config_cmd = config.get_config_cmd() | | 46 | + have_c = config_cmd.try_compile('void foo() {{}}') | | 47 | + print('COMPILERS:%%d,%%d,%%d' %% (have_c, | | 48 | + config.have_f77c(), | | 49 | + config.have_f90c())) | | 50 | + sys.exit(99) | | 51 | + """ | | 52 | + ) | | 53 | + code = code % dict(syspath=repr(sys.path)) | | 54 | + | | 55 | + tmpdir = tempfile.mkdtemp() | | 56 | + try: | | 57 | + script = os.path.join(tmpdir, "setup.py") | | 58 | + | | 59 | + with open(script, "w") as f: | | 60 | + f.write(code) | | 61 | + | | 62 | + cmd = [sys.executable, "setup.py", "config"] | | 63 | + p = subprocess.Popen( | | 64 | + cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, cwd=tmpdir | | 65 | + ) | | 66 | + out, err = p.communicate() | | 67 | + finally: | | 68 | + shutil.rmtree(tmpdir) | | 69 | + | | 70 | + m = re.search(rb"COMPILERS:(\d+),(\d+),(\d+)", out) | | 71 | + if m: | | 72 | + _compiler_status = ( | | 73 | + bool(int(m.group(1))), | | 74 | + bool(int(m.group(2))), | | 75 | + bool(int(m.group(3))), | | 76 | + ) | | 77 | + # Finished | | 78 | + return _compiler_status | | 79 | + | | 80 | + | | 81 | +def has_c_compiler(): | | 82 | + return _get_compiler_status()[0] | | 83 | + | | 84 | + | | 85 | +def has_f77_compiler(): | | 86 | + return _get_compiler_status()[1] | | 87 | + | | 88 | + | | 89 | +def has_f90_compiler(): | | 90 | + return _get_compiler_status()[2] |
Collapse file Copy file name to clipboardExpand all lines: numpy/f2py/_backends/_meson.py +7-19Lines changed: 7 additions & 19 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -91,13 +91,6 @@ def _move_exec_to_root(self, build_dir: Path): | 91 | 91 | for path_object in path_objects: | 92 | 92 | shutil.move(path_object, Path.cwd()) | 93 | 93 |
| 94 | | - def _get_build_command(self): | 95 | | - return [ | 96 | | - "meson", | 97 | | - "setup", | 98 | | - self.meson_build_dir, | 99 | | - ] | 100 | | - | 101 | 94 | def write_meson_build(self, build_dir: Path) -> None: | 102 | 95 | """Writes the meson build file at specified location""" | 103 | 96 | meson_template = MesonTemplate( | @@ -115,19 +108,14 @@ def write_meson_build(self, build_dir: Path) -> None: | 115 | 108 | meson_build_file.write_text(src) | 116 | 109 | return meson_build_file | 117 | 110 |
| | 111 | + def _run_subprocess_command(self, command, cwd): | | 112 | + subprocess.run(command, cwd=cwd, check=True) | | 113 | + | 118 | 114 | def run_meson(self, build_dir: Path): | 119 | | - completed_process = subprocess.run(self._get_build_command(), cwd=build_dir) | 120 | | - if completed_process.returncode != 0: | 121 | | - raise subprocess.CalledProcessError( | 122 | | - completed_process.returncode, completed_process.args | 123 | | - ) | 124 | | - completed_process = subprocess.run( | 125 | | - ["meson", "compile", "-C", self.meson_build_dir], cwd=build_dir | 126 | | - ) | 127 | | - if completed_process.returncode != 0: | 128 | | - raise subprocess.CalledProcessError( | 129 | | - completed_process.returncode, completed_process.args | 130 | | - ) | | 115 | + setup_command = ["meson", "setup", self.meson_build_dir] | | 116 | + self._run_subprocess_command(setup_command, build_dir) | | 117 | + compile_command = ["meson", "compile", "-C", self.meson_build_dir] | | 118 | + self._run_subprocess_command(compile_command, build_dir) | 131 | 119 |
| 132 | 120 | def compile(self) -> None: | 133 | 121 | self.sources = _prepare_sources(self.modulename, self.sources, self.build_dir) | |
Collapse file Copy file name to clipboardExpand all lines: numpy/f2py/tests/test_abstract_interface.py +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 7 | 7 |
| 8 | 8 |
| 9 | 9 | @pytest.mark.skipif(IS_WASM, reason="Cannot start subprocess") | | 10 | +@pytest.mark.slow | 10 | 11 | class TestAbstractInterface(util.F2PyTest): | 11 | 12 | sources = [util.getpath("tests", "src", "abstract_interface", "foo.f90")] | 12 | 13 |
| |
Collapse file Copy file name to clipboardExpand all lines: numpy/f2py/tests/test_array_from_pyobj.py +7-15Lines changed: 7 additions & 15 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 3 | 3 | import copy | 4 | 4 | import platform | 5 | 5 | import pytest | | 6 | +from pathlib import Path | 6 | 7 |
| 7 | 8 | import numpy as np | 8 | 9 |
| | 19 | 20 | **_typeinfo) | 20 | 21 |
| 21 | 22 |
| | 23 | +def get_testdir(): | | 24 | + testroot = Path(__file__).resolve().parent / "src" | | 25 | + return testroot / "array_from_pyobj" | | 26 | + | 22 | 27 | def setup_module(): | 23 | 28 | """ | 24 | 29 | Build the required testing extension module | 25 | 30 |
| 26 | 31 | """ | 27 | 32 | global wrap | 28 | 33 |
| 29 | | - # Check compiler availability first | 30 | | - if not util.has_c_compiler(): | 31 | | - pytest.skip("No C compiler available") | 32 | | - | 33 | 34 | if wrap is None: | 34 | | - config_code = """ | 35 | | - config.add_extension('test_array_from_pyobj_ext', | 36 | | - sources=['wrapmodule.c', 'fortranobject.c'], | 37 | | - define_macros=[]) | 38 | | - """ | 39 | | - d = os.path.dirname(__file__) | 40 | 35 | src = [ | 41 | | - util.getpath("tests", "src", "array_from_pyobj", "wrapmodule.c"), | 42 | | - util.getpath("src", "fortranobject.c"), | 43 | | - util.getpath("src", "fortranobject.h"), | | 36 | + get_testdir() / "wrapmodule.c", | 44 | 37 | ] | 45 | | - wrap = util.build_module_distutils(src, config_code, | 46 | | - "test_array_from_pyobj_ext") | | 38 | + wrap = util.build_meson(src, module_name = "test_array_from_pyobj_ext") | 47 | 39 |
| 48 | 40 |
| 49 | 41 | def flags_info(arr): | |
Collapse file Copy file name to clipboardExpand all lines: numpy/f2py/tests/test_block_docstring.py +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 5 | 5 | from numpy.testing import IS_PYPY | 6 | 6 |
| 7 | 7 |
| | 8 | +@pytest.mark.slow | 8 | 9 | class TestBlockDocString(util.F2PyTest): | 9 | 10 | sources = [util.getpath("tests", "src", "block_docstring", "foo.f")] | 10 | 11 |
| |
Collapse file Copy file name to clipboardExpand all lines: numpy/f2py/tests/test_callback.py +4-1Lines changed: 4 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -15,6 +15,7 @@ class TestF77Callback(util.F2PyTest): | 15 | 15 | sources = [util.getpath("tests", "src", "callback", "foo.f")] | 16 | 16 |
| 17 | 17 | @pytest.mark.parametrize("name", "t,t2".split(",")) | | 18 | + @pytest.mark.slow | 18 | 19 | def test_all(self, name): | 19 | 20 | self.check_function(name) | 20 | 21 |
| @@ -205,6 +206,7 @@ class TestF77CallbackPythonTLS(TestF77Callback): | 205 | 206 | class TestF90Callback(util.F2PyTest): | 206 | 207 | sources = [util.getpath("tests", "src", "callback", "gh17797.f90")] | 207 | 208 |
| | 209 | + @pytest.mark.slow | 208 | 210 | def test_gh17797(self): | 209 | 211 | def incr(x): | 210 | 212 | return x + 123 | @@ -222,6 +224,7 @@ class TestGH18335(util.F2PyTest): | 222 | 224 | """ | 223 | 225 | sources = [util.getpath("tests", "src", "callback", "gh18335.f90")] | 224 | 226 |
| | 227 | + @pytest.mark.slow | 225 | 228 | def test_gh18335(self): | 226 | 229 | def foo(x): | 227 | 230 | x[0] += 1 | @@ -235,7 +238,7 @@ class TestGH25211(util.F2PyTest): | 235 | 238 | util.getpath("tests", "src", "callback", "gh25211.pyf")] | 236 | 239 | module_name = "callback2" | 237 | 240 |
| 238 | | - def test_gh18335(self): | | 241 | + def test_gh25211(self): | 239 | 242 | def bar(x): | 240 | 243 | return x*x | 241 | 244 |
| |
Collapse file Copy file name to clipboardExpand all lines: numpy/f2py/tests/test_character.py +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 5 | 5 | from numpy.f2py.tests import util | 6 | 6 |
| 7 | 7 |
| | 8 | +@pytest.mark.slow | 8 | 9 | class TestCharacterString(util.F2PyTest): | 9 | 10 | # options = ['--debug-capi', '--build-dir', '/tmp/test-build-f2py'] | 10 | 11 | suffix = '.f90' | @@ -512,6 +513,7 @@ class TestMiscCharacter(util.F2PyTest): | 512 | 513 | end subroutine {fprefix}_character_bc_old | 513 | 514 | """) | 514 | 515 |
| | 516 | + @pytest.mark.slow | 515 | 517 | def test_gh18684(self): | 516 | 518 | # Test character(len=5) and character*5 usages | 517 | 519 | f = getattr(self.module, self.fprefix + '_gh18684') | @@ -596,6 +598,7 @@ class TestStringAssumedLength(util.F2PyTest): | 596 | 598 | def test_gh24008(self): | 597 | 599 | self.module.greet("joe", "bob") | 598 | 600 |
| | 601 | +@pytest.mark.slow | 599 | 602 | class TestStringOptionalInOut(util.F2PyTest): | 600 | 603 | sources = [util.getpath("tests", "src", "string", "gh24662.f90")] | 601 | 604 |
| |
Collapse file Copy file name to clipboard +1-8Lines changed: 1 addition & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -import os | 2 | | -import sys | 3 | 1 | import pytest | 4 | | - | 5 | 2 | import numpy as np | 6 | 3 | from . import util | 7 | 4 |
| 8 | | - | | 5 | +@pytest.mark.slow | 9 | 6 | class TestCommonBlock(util.F2PyTest): | 10 | 7 | sources = [util.getpath("tests", "src", "common", "block.f")] | 11 | 8 |
| 12 | | - @pytest.mark.skipif(sys.platform == "win32", | 13 | | - reason="Fails with MinGW64 Gfortran (Issue #9673)") | 14 | 9 | def test_common_block(self): | 15 | 10 | self.module.initcb() | 16 | 11 | assert self.module.block.long_bn == np.array(1.0, dtype=np.float64) | @@ -21,7 +16,5 @@ def test_common_block(self): | 21 | 16 | class TestCommonWithUse(util.F2PyTest): | 22 | 17 | sources = [util.getpath("tests", "src", "common", "gh19161.f90")] | 23 | 18 |
| 24 | | - @pytest.mark.skipif(sys.platform == "win32", | 25 | | - reason="Fails with MinGW64 Gfortran (Issue #9673)") | 26 | 19 | def test_common_gh19161(self): | 27 | 20 | assert self.module.data.x == 0 |
Collapse file Copy file name to clipboardExpand all lines: numpy/f2py/tests/test_crackfortran.py +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -210,6 +210,7 @@ class TestDimSpec(util.F2PyTest): | 210 | 210 | ) | 211 | 211 |
| 212 | 212 | @pytest.mark.parametrize("dimspec", all_dimspecs) | | 213 | + @pytest.mark.slow | 213 | 214 | def test_array_size(self, dimspec): | 214 | 215 |
| 215 | 216 | count = self.all_dimspecs.index(dimspec) | @@ -276,6 +277,7 @@ def test_input_encoding(self, tmp_path, encoding): | 276 | 277 | assert mod[0]['name'] == 'foo' | 277 | 278 |
| 278 | 279 |
| | 280 | +@pytest.mark.slow | 279 | 281 | class TestUnicodeComment(util.F2PyTest): | 280 | 282 | sources = [util.getpath("tests", "src", "crackfortran", "unicode_comment.f90")] | 281 | 283 |
| @@ -327,6 +329,7 @@ def test_nameargspattern_backtracking(self, adversary): | 327 | 329 | class TestFunctionReturn(util.F2PyTest): | 328 | 330 | sources = [util.getpath("tests", "src", "crackfortran", "gh23598.f90")] | 329 | 331 |
| | 332 | + @pytest.mark.slow | 330 | 333 | def test_function_rettype(self): | 331 | 334 | # gh-23598 | 332 | 335 | assert self.module.intproduct(3, 4) == 12 | |
|