diff --git a/doc/source/f2py/f2py-testing.rst b/doc/source/f2py/f2py-testing.rst index 687b414975ee..7b16a0f6ff7f 100644 --- a/doc/source/f2py/f2py-testing.rst +++ b/doc/source/f2py/f2py-testing.rst @@ -23,12 +23,12 @@ The directory of the test suite looks like the following:: ├── test_array_from_pyobj.py ├── // ... several test files ├── test_symbolic.py - └── util.py + testutils.py Files starting with ``test_`` contain tests for various aspects of f2py from parsing Fortran files to checking modules' documentation. ``src`` directory contains the -Fortran source files upon which we do the testing. ``util.py`` contains utility -functions for building and importing Fortran modules during test time using a +Fortran source files upon which we do the testing. ``testutils.py`` contains utility +functions for building and importing Fortran modules during test time using a temporary location. Adding a test @@ -36,14 +36,14 @@ Adding a test F2PY's current test suite predates ``pytest`` and therefore does not use fixtures. Instead, the test files contain test classes that inherit from ``F2PyTest`` -class present in ``util.py``. +class present in ``testutils.py``. -.. literalinclude:: ../../../numpy/f2py/tests/util.py +.. literalinclude:: ../../../numpy/f2py/testutils.py :language: python :lines: 327-336 :linenos: -This class many helper functions for parsing and compiling test source files. Its child +This class many helper functions for parsing and compiling test source files. Its child classes can override its ``sources`` data member to provide their own source files. This superclass will then compile the added source files upon object creation and their functions will be appended to ``self.module`` data member. Thus, the child classes will @@ -70,13 +70,13 @@ Consider the following subroutines, contained in a file named :file:`add-test.f` :language: fortran The first routine `addb` simply takes an array and increases its elements by 1. -The second subroutine `addc` assigns a new array `k` with elements greater that +The second subroutine `addc` assigns a new array `k` with elements greater that the elements of the input array `w` by 1. A test can be implemented as follows:: - class TestAdd(util.F2PyTest): - sources = [util.getpath("add-test.f")] + class TestAdd(testutils.F2PyTest): + sources = [testutils.getpath("add-test.f")] def test_module(self): k = np.array([1, 2, 3], dtype=np.float64) diff --git a/numpy/_core/tests/_locales.py b/numpy/_core/_testutils_locales.py similarity index 100% rename from numpy/_core/tests/_locales.py rename to numpy/_core/_testutils_locales.py diff --git a/numpy/_core/tests/_natype.py b/numpy/_core/_testutils_natype.py similarity index 100% rename from numpy/_core/tests/_natype.py rename to numpy/_core/_testutils_natype.py diff --git a/numpy/_core/meson.build b/numpy/_core/meson.build index 6098986618e4..f51669d6aa3f 100644 --- a/numpy/_core/meson.build +++ b/numpy/_core/meson.build @@ -1394,6 +1394,8 @@ python_sources = [ '_simd.pyi', '_string_helpers.py', '_string_helpers.pyi', + '_testutils_locales.py', + '_testutils_natype.py', '_type_aliases.py', '_type_aliases.pyi', '_ufunc_config.py', diff --git a/numpy/_core/tests/test_longdouble.py b/numpy/_core/tests/test_longdouble.py index f7edd9774573..d8b24886ab7f 100644 --- a/numpy/_core/tests/test_longdouble.py +++ b/numpy/_core/tests/test_longdouble.py @@ -4,7 +4,7 @@ import pytest import numpy as np -from numpy._core.tests._locales import CommaDecimalPointLocale +from numpy._core._testutils_locales import CommaDecimalPointLocale from numpy.testing import ( IS_MUSL, assert_, diff --git a/numpy/_core/tests/test_multiarray.py b/numpy/_core/tests/test_multiarray.py index 0faf35c64b98..f0df318774c3 100644 --- a/numpy/_core/tests/test_multiarray.py +++ b/numpy/_core/tests/test_multiarray.py @@ -26,8 +26,8 @@ import numpy as np import numpy._core._multiarray_tests as _multiarray_tests from numpy._core._rational_tests import rational +from numpy._core._testutils_locales import CommaDecimalPointLocale from numpy._core.multiarray import _get_ndarray_c_version, dot -from numpy._core.tests._locales import CommaDecimalPointLocale from numpy.exceptions import AxisError, ComplexWarning from numpy.lib import stride_tricks from numpy.lib.recfunctions import repack_fields diff --git a/numpy/_core/tests/test_print.py b/numpy/_core/tests/test_print.py index d99b2794d7ca..659c695d262d 100644 --- a/numpy/_core/tests/test_print.py +++ b/numpy/_core/tests/test_print.py @@ -4,7 +4,7 @@ import pytest import numpy as np -from numpy._core.tests._locales import CommaDecimalPointLocale +from numpy._core._testutils_locales import CommaDecimalPointLocale from numpy.testing import IS_MUSL, assert_, assert_equal _REF = {np.inf: 'inf', -np.inf: '-inf', np.nan: 'nan'} diff --git a/numpy/_core/tests/test_stringdtype.py b/numpy/_core/tests/test_stringdtype.py index 9bab810d4421..1328f9c8de2f 100644 --- a/numpy/_core/tests/test_stringdtype.py +++ b/numpy/_core/tests/test_stringdtype.py @@ -8,8 +8,8 @@ import pytest import numpy as np -from numpy._core.tests._natype import get_stringdtype_dtype as get_dtype -from numpy._core.tests._natype import pd_NA +from numpy._core._testutils_natype import get_stringdtype_dtype as get_dtype +from numpy._core._testutils_natype import pd_NA from numpy.dtypes import StringDType from numpy.testing import IS_PYPY, assert_array_equal diff --git a/numpy/conftest.py b/numpy/conftest.py index fde4defc926d..e8519563044e 100644 --- a/numpy/conftest.py +++ b/numpy/conftest.py @@ -14,7 +14,7 @@ import numpy import numpy as np from numpy._core._multiarray_tests import get_fpu_mode -from numpy._core.tests._natype import get_stringdtype_dtype, pd_NA +from numpy._core._testutils_natype import get_stringdtype_dtype, pd_NA from numpy.testing._private.utils import NOGIL_BUILD try: diff --git a/numpy/f2py/tests/__init__.py b/numpy/f2py/tests/conftest.py similarity index 100% rename from numpy/f2py/tests/__init__.py rename to numpy/f2py/tests/conftest.py diff --git a/numpy/f2py/tests/test_abstract_interface.py b/numpy/f2py/tests/test_abstract_interface.py index 21e77db3e8d3..9c1deb559dd9 100644 --- a/numpy/f2py/tests/test_abstract_interface.py +++ b/numpy/f2py/tests/test_abstract_interface.py @@ -1,15 +1,13 @@ import pytest -from numpy.f2py import crackfortran +from numpy.f2py import crackfortran, testutils from numpy.testing import IS_WASM -from . import util - @pytest.mark.skipif(IS_WASM, reason="Cannot start subprocess") @pytest.mark.slow -class TestAbstractInterface(util.F2PyTest): - sources = [util.getpath("tests", "src", "abstract_interface", "foo.f90")] +class TestAbstractInterface(testutils.F2PyTest): + sources = [testutils.getpath("tests", "src", "abstract_interface", "foo.f90")] skip = ["add1", "add2"] @@ -18,7 +16,7 @@ def test_abstract_interface(self): def test_parse_abstract_interface(self): # Test gh18403 - fpath = util.getpath("tests", "src", "abstract_interface", + fpath = testutils.getpath("tests", "src", "abstract_interface", "gh18403_mod.f90") mod = crackfortran.crackfortran([str(fpath)]) assert len(mod) == 1 diff --git a/numpy/f2py/tests/test_array_from_pyobj.py b/numpy/f2py/tests/test_array_from_pyobj.py index a8f952752cf4..38f92a5fa326 100644 --- a/numpy/f2py/tests/test_array_from_pyobj.py +++ b/numpy/f2py/tests/test_array_from_pyobj.py @@ -7,8 +7,7 @@ import numpy as np from numpy._core._type_aliases import c_names_dict as _c_names_dict - -from . import util +from numpy.f2py import testutils wrap = None @@ -34,7 +33,7 @@ def setup_module(): src = [ get_testdir() / "wrapmodule.c", ] - wrap = util.build_meson(src, module_name="test_array_from_pyobj_ext") + wrap = testutils.build_meson(src, module_name="test_array_from_pyobj_ext") def flags_info(arr): diff --git a/numpy/f2py/tests/test_assumed_shape.py b/numpy/f2py/tests/test_assumed_shape.py index cf75644d40ee..b072e9ac28e0 100644 --- a/numpy/f2py/tests/test_assumed_shape.py +++ b/numpy/f2py/tests/test_assumed_shape.py @@ -3,16 +3,16 @@ import pytest -from . import util +from numpy.f2py import testutils -class TestAssumedShapeSumExample(util.F2PyTest): +class TestAssumedShapeSumExample(testutils.F2PyTest): 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"), + testutils.getpath("tests", "src", "assumed_shape", "foo_free.f90"), + testutils.getpath("tests", "src", "assumed_shape", "foo_use.f90"), + testutils.getpath("tests", "src", "assumed_shape", "precision.f90"), + testutils.getpath("tests", "src", "assumed_shape", "foo_mod.f90"), + testutils.getpath("tests", "src", "assumed_shape", ".f2py_f2cmap"), ] @pytest.mark.slow diff --git a/numpy/f2py/tests/test_block_docstring.py b/numpy/f2py/tests/test_block_docstring.py index ba255a1b473c..54218daf226b 100644 --- a/numpy/f2py/tests/test_block_docstring.py +++ b/numpy/f2py/tests/test_block_docstring.py @@ -2,14 +2,13 @@ import pytest +from numpy.f2py import testutils from numpy.testing import IS_PYPY -from . import util - @pytest.mark.slow -class TestBlockDocString(util.F2PyTest): - sources = [util.getpath("tests", "src", "block_docstring", "foo.f")] +class TestBlockDocString(testutils.F2PyTest): + sources = [testutils.getpath("tests", "src", "block_docstring", "foo.f")] @pytest.mark.skipif(sys.platform == "win32", reason="Fails with MinGW64 Gfortran (Issue #9673)") diff --git a/numpy/f2py/tests/test_callback.py b/numpy/f2py/tests/test_callback.py index 6614efb16db8..eae69b2ba4b4 100644 --- a/numpy/f2py/tests/test_callback.py +++ b/numpy/f2py/tests/test_callback.py @@ -9,13 +9,12 @@ import pytest import numpy as np +from numpy.f2py import testutils from numpy.testing import IS_PYPY -from . import util - -class TestF77Callback(util.F2PyTest): - sources = [util.getpath("tests", "src", "callback", "foo.f")] +class TestF77Callback(testutils.F2PyTest): + sources = [testutils.getpath("tests", "src", "callback", "foo.f")] @pytest.mark.parametrize("name", ["t", "t2"]) @pytest.mark.slow @@ -206,8 +205,8 @@ class TestF77CallbackPythonTLS(TestF77Callback): options = ["-DF2PY_USE_PYTHON_TLS"] -class TestF90Callback(util.F2PyTest): - sources = [util.getpath("tests", "src", "callback", "gh17797.f90")] +class TestF90Callback(testutils.F2PyTest): + sources = [testutils.getpath("tests", "src", "callback", "gh17797.f90")] @pytest.mark.slow def test_gh17797(self): @@ -219,13 +218,13 @@ def incr(x): assert r == 123 + 1 + 2 + 3 -class TestGH18335(util.F2PyTest): +class TestGH18335(testutils.F2PyTest): """The reproduction of the reported issue requires specific input that extensions may break the issue conditions, so the reproducer is implemented as a separate test class. Do not extend this test with other tests! """ - sources = [util.getpath("tests", "src", "callback", "gh18335.f90")] + sources = [testutils.getpath("tests", "src", "callback", "gh18335.f90")] @pytest.mark.slow def test_gh18335(self): @@ -236,9 +235,9 @@ def foo(x): assert r == 123 + 1 -class TestGH25211(util.F2PyTest): - sources = [util.getpath("tests", "src", "callback", "gh25211.f"), - util.getpath("tests", "src", "callback", "gh25211.pyf")] +class TestGH25211(testutils.F2PyTest): + sources = [testutils.getpath("tests", "src", "callback", "gh25211.f"), + testutils.getpath("tests", "src", "callback", "gh25211.pyf")] module_name = "callback2" def test_gh25211(self): @@ -253,8 +252,8 @@ def bar(x): @pytest.mark.xfail(condition=(platform.system().lower() == 'darwin'), run=False, reason="Callback aborts cause CI failures on macOS") -class TestCBFortranCallstatement(util.F2PyTest): - sources = [util.getpath("tests", "src", "callback", "gh26681.f90")] +class TestCBFortranCallstatement(testutils.F2PyTest): + sources = [testutils.getpath("tests", "src", "callback", "gh26681.f90")] options = ['--lower'] def test_callstatement_fortran(self): diff --git a/numpy/f2py/tests/test_character.py b/numpy/f2py/tests/test_character.py index 74868a6f09f7..93f09ff28623 100644 --- a/numpy/f2py/tests/test_character.py +++ b/numpy/f2py/tests/test_character.py @@ -3,12 +3,12 @@ import pytest import numpy as np -from numpy.f2py.tests import util +from numpy.f2py import testutils from numpy.testing import assert_array_equal, assert_equal, assert_raises @pytest.mark.slow -class TestCharacterString(util.F2PyTest): +class TestCharacterString(testutils.F2PyTest): # options = ['--debug-capi', '--build-dir', '/tmp/test-build-f2py'] suffix = '.f90' fprefix = 'test_character_string' @@ -134,7 +134,7 @@ def test_2d_array_input(self, length): assert_array_equal(f(a), expected) -class TestCharacter(util.F2PyTest): +class TestCharacter(testutils.F2PyTest): # options = ['--debug-capi', '--build-dir', '/tmp/test-build-f2py'] suffix = '.f90' fprefix = 'test_character' @@ -432,7 +432,7 @@ def test_optional(self): assert_equal(f(b'B'), b"B") -class TestMiscCharacter(util.F2PyTest): +class TestMiscCharacter(testutils.F2PyTest): # options = ['--debug-capi', '--build-dir', '/tmp/test-build-f2py'] suffix = '.f90' fprefix = 'test_misc_character' @@ -575,8 +575,8 @@ def test_character_bc(self, state): assert_raises(Exception, lambda: f(b'c')) -class TestStringScalarArr(util.F2PyTest): - sources = [util.getpath("tests", "src", "string", "scalar_string.f90")] +class TestStringScalarArr(testutils.F2PyTest): + sources = [testutils.getpath("tests", "src", "string", "scalar_string.f90")] def test_char(self): for out in (self.module.string_test.string, @@ -594,15 +594,15 @@ def test_char_arr(self): expected = '|S12' assert out.dtype == expected -class TestStringAssumedLength(util.F2PyTest): - sources = [util.getpath("tests", "src", "string", "gh24008.f")] +class TestStringAssumedLength(testutils.F2PyTest): + sources = [testutils.getpath("tests", "src", "string", "gh24008.f")] def test_gh24008(self): self.module.greet("joe", "bob") @pytest.mark.slow -class TestStringOptionalInOut(util.F2PyTest): - sources = [util.getpath("tests", "src", "string", "gh24662.f90")] +class TestStringOptionalInOut(testutils.F2PyTest): + sources = [testutils.getpath("tests", "src", "string", "gh24662.f90")] def test_gh24662(self): self.module.string_inout_optional() @@ -615,11 +615,11 @@ def test_gh24662(self): @pytest.mark.slow -class TestNewCharHandling(util.F2PyTest): +class TestNewCharHandling(testutils.F2PyTest): # from v1.24 onwards, gh-19388 sources = [ - util.getpath("tests", "src", "string", "gh25286.pyf"), - util.getpath("tests", "src", "string", "gh25286.f90") + testutils.getpath("tests", "src", "string", "gh25286.pyf"), + testutils.getpath("tests", "src", "string", "gh25286.f90") ] module_name = "_char_handling_test" @@ -628,11 +628,11 @@ def test_gh25286(self): assert info == 2 @pytest.mark.slow -class TestBCCharHandling(util.F2PyTest): +class TestBCCharHandling(testutils.F2PyTest): # SciPy style, "incorrect" bindings with a hook sources = [ - util.getpath("tests", "src", "string", "gh25286_bc.pyf"), - util.getpath("tests", "src", "string", "gh25286.f90") + testutils.getpath("tests", "src", "string", "gh25286_bc.pyf"), + testutils.getpath("tests", "src", "string", "gh25286.f90") ] module_name = "_char_handling_test" diff --git a/numpy/f2py/tests/test_common.py b/numpy/f2py/tests/test_common.py index b9fbd84d52fb..1f97e2210e2f 100644 --- a/numpy/f2py/tests/test_common.py +++ b/numpy/f2py/tests/test_common.py @@ -1,13 +1,12 @@ import pytest import numpy as np - -from . import util +from numpy.f2py import testutils @pytest.mark.slow -class TestCommonBlock(util.F2PyTest): - sources = [util.getpath("tests", "src", "common", "block.f")] +class TestCommonBlock(testutils.F2PyTest): + sources = [testutils.getpath("tests", "src", "common", "block.f")] def test_common_block(self): self.module.initcb() @@ -16,8 +15,8 @@ def test_common_block(self): assert self.module.block.ok == np.array(3, dtype=np.int32) -class TestCommonWithUse(util.F2PyTest): - sources = [util.getpath("tests", "src", "common", "gh19161.f90")] +class TestCommonWithUse(testutils.F2PyTest): + sources = [testutils.getpath("tests", "src", "common", "gh19161.f90")] def test_common_gh19161(self): assert self.module.data.x == 0 diff --git a/numpy/f2py/tests/test_crackfortran.py b/numpy/f2py/tests/test_crackfortran.py index c3967cfb967b..8121118d67c8 100644 --- a/numpy/f2py/tests/test_crackfortran.py +++ b/numpy/f2py/tests/test_crackfortran.py @@ -7,16 +7,14 @@ import pytest import numpy as np -from numpy.f2py import crackfortran +from numpy.f2py import crackfortran, testutils from numpy.f2py.crackfortran import markinnerspaces, nameargspattern -from . import util - -class TestNoSpace(util.F2PyTest): +class TestNoSpace(testutils.F2PyTest): # issue gh-15035: add handling for endsubroutine, endfunction with no space # between "end" and the block name - sources = [util.getpath("tests", "src", "crackfortran", "gh15035.f")] + sources = [testutils.getpath("tests", "src", "crackfortran", "gh15035.f")] def test_module(self): k = np.array([1, 2, 3], dtype=np.float64) @@ -30,7 +28,7 @@ def test_module(self): class TestPublicPrivate: def test_defaultPrivate(self): - fpath = util.getpath("tests", "src", "crackfortran", "privatemod.f90") + fpath = testutils.getpath("tests", "src", "crackfortran", "privatemod.f90") mod = crackfortran.crackfortran([str(fpath)]) assert len(mod) == 1 mod = mod[0] @@ -42,7 +40,7 @@ def test_defaultPrivate(self): assert "public" in mod["vars"]["seta"]["attrspec"] def test_defaultPublic(self, tmp_path): - fpath = util.getpath("tests", "src", "crackfortran", "publicmod.f90") + fpath = testutils.getpath("tests", "src", "crackfortran", "publicmod.f90") mod = crackfortran.crackfortran([str(fpath)]) assert len(mod) == 1 mod = mod[0] @@ -52,7 +50,7 @@ def test_defaultPublic(self, tmp_path): assert "public" in mod["vars"]["seta"]["attrspec"] def test_access_type(self, tmp_path): - fpath = util.getpath("tests", "src", "crackfortran", "accesstype.f90") + fpath = testutils.getpath("tests", "src", "crackfortran", "accesstype.f90") mod = crackfortran.crackfortran([str(fpath)]) assert len(mod) == 1 tt = mod[0]['vars'] @@ -61,7 +59,7 @@ def test_access_type(self, tmp_path): assert set(tt['c']['attrspec']) == {'public'} def test_nowrap_private_proceedures(self, tmp_path): - fpath = util.getpath("tests", "src", "crackfortran", "gh23879.f90") + fpath = testutils.getpath("tests", "src", "crackfortran", "gh23879.f90") mod = crackfortran.crackfortran([str(fpath)]) assert len(mod) == 1 pyf = crackfortran.crack2fortran(mod) @@ -69,7 +67,7 @@ def test_nowrap_private_proceedures(self, tmp_path): class TestModuleProcedure: def test_moduleOperators(self, tmp_path): - fpath = util.getpath("tests", "src", "crackfortran", "operators.f90") + fpath = testutils.getpath("tests", "src", "crackfortran", "operators.f90") mod = crackfortran.crackfortran([str(fpath)]) assert len(mod) == 1 mod = mod[0] @@ -87,7 +85,7 @@ def test_moduleOperators(self, tmp_path): ["get_int", "get_real"] def test_notPublicPrivate(self, tmp_path): - fpath = util.getpath("tests", "src", "crackfortran", "pubprivmod.f90") + fpath = testutils.getpath("tests", "src", "crackfortran", "pubprivmod.f90") mod = crackfortran.crackfortran([str(fpath)]) assert len(mod) == 1 mod = mod[0] @@ -96,9 +94,9 @@ def test_notPublicPrivate(self, tmp_path): assert mod['vars']['seta']['attrspec'] == ['public', ] -class TestExternal(util.F2PyTest): +class TestExternal(testutils.F2PyTest): # issue gh-17859: add external attribute support - sources = [util.getpath("tests", "src", "crackfortran", "gh17859.f")] + sources = [testutils.getpath("tests", "src", "crackfortran", "gh17859.f")] def test_external_as_statement(self): def incr(x): @@ -115,10 +113,10 @@ def incr(x): assert r == 123 -class TestCrackFortran(util.F2PyTest): +class TestCrackFortran(testutils.F2PyTest): # gh-2848: commented lines between parameters in subroutine parameter lists - sources = [util.getpath("tests", "src", "crackfortran", "gh2848.f90"), - util.getpath("tests", "src", "crackfortran", "common_with_division.f") + sources = [testutils.getpath("tests", "src", "crackfortran", "gh2848.f90"), + testutils.getpath("tests", "src", "crackfortran", "common_with_division.f") ] def test_gh2848(self): @@ -149,7 +147,7 @@ def test_multiple_relevant_spaces(self): assert markinnerspaces(r'a "b c" "d e"') == r'a "b@_@c" "d@_@e"' -class TestDimSpec(util.F2PyTest): +class TestDimSpec(testutils.F2PyTest): """This test suite tests various expressions that are used as dimension specifications. @@ -254,13 +252,13 @@ def test_inv_array_size(self, dimspec): class TestModuleDeclaration: def test_dependencies(self, tmp_path): - fpath = util.getpath("tests", "src", "crackfortran", "foo_deps.f90") + fpath = testutils.getpath("tests", "src", "crackfortran", "foo_deps.f90") mod = crackfortran.crackfortran([str(fpath)]) assert len(mod) == 1 assert mod[0]["vars"]["abar"]["="] == "bar('abar')" -class TestEval(util.F2PyTest): +class TestEval(testutils.F2PyTest): def test_eval_scalar(self): eval_scalar = crackfortran._eval_scalar @@ -270,7 +268,7 @@ def test_eval_scalar(self): assert eval_scalar('"123"', {}) == "'123'" -class TestFortranReader(util.F2PyTest): +class TestFortranReader(testutils.F2PyTest): @pytest.mark.parametrize("encoding", ['ascii', 'utf-8', 'utf-16', 'utf-32']) def test_input_encoding(self, tmp_path, encoding): @@ -286,8 +284,8 @@ def test_input_encoding(self, tmp_path, encoding): @pytest.mark.slow -class TestUnicodeComment(util.F2PyTest): - sources = [util.getpath("tests", "src", "crackfortran", "unicode_comment.f90")] +class TestUnicodeComment(testutils.F2PyTest): + sources = [testutils.getpath("tests", "src", "crackfortran", "unicode_comment.f90")] @pytest.mark.skipif( (importlib.util.find_spec("charset_normalizer") is None), @@ -333,8 +331,8 @@ def test_nameargspattern_backtracking(self, adversary): good_version_of_adversary = repeated_adversary + '@)@' assert nameargspattern.search(good_version_of_adversary) -class TestFunctionReturn(util.F2PyTest): - sources = [util.getpath("tests", "src", "crackfortran", "gh23598.f90")] +class TestFunctionReturn(testutils.F2PyTest): + sources = [testutils.getpath("tests", "src", "crackfortran", "gh23598.f90")] @pytest.mark.slow def test_function_rettype(self): @@ -342,10 +340,10 @@ def test_function_rettype(self): assert self.module.intproduct(3, 4) == 12 -class TestFortranGroupCounters(util.F2PyTest): +class TestFortranGroupCounters(testutils.F2PyTest): def test_end_if_comment(self): # gh-23533 - fpath = util.getpath("tests", "src", "crackfortran", "gh23533.f") + fpath = testutils.getpath("tests", "src", "crackfortran", "gh23533.f") try: crackfortran.crackfortran([str(fpath)]) except Exception as exc: @@ -354,7 +352,7 @@ def test_end_if_comment(self): class TestF77CommonBlockReader: def test_gh22648(self, tmp_path): - fpath = util.getpath("tests", "src", "crackfortran", "gh22648.pyf") + fpath = testutils.getpath("tests", "src", "crackfortran", "gh22648.pyf") with contextlib.redirect_stdout(io.StringIO()) as stdout_f2py: mod = crackfortran.crackfortran([str(fpath)]) assert "Mismatch" not in stdout_f2py.getvalue() @@ -412,8 +410,8 @@ def test_param_eval_too_many_dims(self): dimspec=dimspec) @pytest.mark.slow -class TestLowerF2PYDirective(util.F2PyTest): - sources = [util.getpath("tests", "src", "crackfortran", "gh27697.f90")] +class TestLowerF2PYDirective(testutils.F2PyTest): + sources = [testutils.getpath("tests", "src", "crackfortran", "gh27697.f90")] options = ['--lower'] def test_no_lower_fail(self): diff --git a/numpy/f2py/tests/test_data.py b/numpy/f2py/tests/test_data.py index 0cea5561bd6c..ff9dcc303a0d 100644 --- a/numpy/f2py/tests/test_data.py +++ b/numpy/f2py/tests/test_data.py @@ -1,13 +1,12 @@ import pytest import numpy as np +from numpy.f2py import testutils from numpy.f2py.crackfortran import crackfortran -from . import util - -class TestData(util.F2PyTest): - sources = [util.getpath("tests", "src", "crackfortran", "data_stmts.f90")] +class TestData(testutils.F2PyTest): + sources = [testutils.getpath("tests", "src", "crackfortran", "data_stmts.f90")] # For gh-23276 @pytest.mark.slow @@ -35,8 +34,8 @@ def test_crackedlines(self): assert mod[0]['vars']['my_array']['='] == '(/(1.0d0, 2.0d0), (-3.0d0, 4.0d0)/)' assert mod[0]['vars']['z']['='] == '(/3.5, 7.0/)' -class TestDataF77(util.F2PyTest): - sources = [util.getpath("tests", "src", "crackfortran", "data_common.f")] +class TestDataF77(testutils.F2PyTest): + sources = [testutils.getpath("tests", "src", "crackfortran", "data_common.f")] # For gh-23276 def test_data_stmts(self): @@ -48,8 +47,8 @@ def test_crackedlines(self): assert mod[0]['vars']['mydata']['='] == '0' -class TestDataMultiplierF77(util.F2PyTest): - sources = [util.getpath("tests", "src", "crackfortran", "data_multiplier.f")] +class TestDataMultiplierF77(testutils.F2PyTest): + sources = [testutils.getpath("tests", "src", "crackfortran", "data_multiplier.f")] # For gh-23276 def test_data_stmts(self): @@ -60,8 +59,8 @@ def test_data_stmts(self): assert self.module.mycom.evar5 == 0 -class TestDataWithCommentsF77(util.F2PyTest): - sources = [util.getpath("tests", "src", "crackfortran", "data_with_comments.f")] +class TestDataWithCommentsF77(testutils.F2PyTest): + sources = [testutils.getpath("tests", "src", "crackfortran", "data_with_comments.f")] # For gh-23276 def test_data_stmts(self): diff --git a/numpy/f2py/tests/test_docs.py b/numpy/f2py/tests/test_docs.py index 5d9aaac9f15b..54c05d7ffdcb 100644 --- a/numpy/f2py/tests/test_docs.py +++ b/numpy/f2py/tests/test_docs.py @@ -3,10 +3,9 @@ import pytest import numpy as np +from numpy.f2py import testutils from numpy.testing import assert_array_equal, assert_equal -from . import util - def get_docdir(): parents = Path(__file__).resolve().parents @@ -33,7 +32,7 @@ def _path(*args): return get_docdir().joinpath(*args) @pytest.mark.slow -class TestDocAdvanced(util.F2PyTest): +class TestDocAdvanced(testutils.F2PyTest): # options = ['--debug-capi', '--build-dir', '/tmp/build-f2py'] sources = [_path('asterisk1.f90'), _path('asterisk2.f90'), _path('ftype.f')] diff --git a/numpy/f2py/tests/test_f2cmap.py b/numpy/f2py/tests/test_f2cmap.py index a35320ccc18a..4bc36091717c 100644 --- a/numpy/f2py/tests/test_f2cmap.py +++ b/numpy/f2py/tests/test_f2cmap.py @@ -1,12 +1,11 @@ import numpy as np +from numpy.f2py import testutils -from . import util - -class TestF2Cmap(util.F2PyTest): +class TestF2Cmap(testutils.F2PyTest): sources = [ - util.getpath("tests", "src", "f2cmap", "isoFortranEnvMap.f90"), - util.getpath("tests", "src", "f2cmap", ".f2py_f2cmap") + testutils.getpath("tests", "src", "f2cmap", "isoFortranEnvMap.f90"), + testutils.getpath("tests", "src", "f2cmap", ".f2py_f2cmap") ] # gh-15095 diff --git a/numpy/f2py/tests/test_f2py2e.py b/numpy/f2py/tests/test_f2py2e.py index 2f91eb77c4bd..5099de1957ba 100644 --- a/numpy/f2py/tests/test_f2py2e.py +++ b/numpy/f2py/tests/test_f2py2e.py @@ -9,11 +9,10 @@ import pytest +from numpy.f2py import testutils from numpy.f2py.f2py2e import main as f2pycli from numpy.testing._private.utils import NOGIL_BUILD -from . import util - ####################### # F2PY Test utilities # ###################### @@ -21,7 +20,7 @@ # Tests for CLI commands which call meson will fail if no compilers are present, these are to be skipped def compiler_check_f2pycli(): - if not util.has_fortran_compiler(): + if not testutils.has_fortran_compiler(): pytest.skip("CLI command needs a Fortran compiler") else: f2pycli() @@ -76,7 +75,7 @@ def get_io_paths(fname_inp, mname="untitled"): @pytest.fixture(scope="session") def hello_world_f90(tmpdir_factory): """Generates a single f90 file for testing""" - fdat = util.getpath("tests", "src", "cli", "hiworld.f90").read_text() + fdat = testutils.getpath("tests", "src", "cli", "hiworld.f90").read_text() fn = tmpdir_factory.getbasetemp() / "hello.f90" fn.write_text(fdat, encoding="ascii") return fn @@ -85,7 +84,7 @@ def hello_world_f90(tmpdir_factory): @pytest.fixture(scope="session") def gh23598_warn(tmpdir_factory): """F90 file for testing warnings in gh23598""" - fdat = util.getpath("tests", "src", "crackfortran", "gh23598Warn.f90").read_text() + fdat = testutils.getpath("tests", "src", "crackfortran", "gh23598Warn.f90").read_text() fn = tmpdir_factory.getbasetemp() / "gh23598Warn.f90" fn.write_text(fdat, encoding="ascii") return fn @@ -94,7 +93,7 @@ def gh23598_warn(tmpdir_factory): @pytest.fixture(scope="session") def gh22819_cli(tmpdir_factory): """F90 file for testing disallowed CLI arguments in ghff819""" - fdat = util.getpath("tests", "src", "cli", "gh_22819.pyf").read_text() + fdat = testutils.getpath("tests", "src", "cli", "gh_22819.pyf").read_text() fn = tmpdir_factory.getbasetemp() / "gh_22819.pyf" fn.write_text(fdat, encoding="ascii") return fn @@ -103,7 +102,7 @@ def gh22819_cli(tmpdir_factory): @pytest.fixture(scope="session") def hello_world_f77(tmpdir_factory): """Generates a single f77 file for testing""" - fdat = util.getpath("tests", "src", "cli", "hi77.f").read_text() + fdat = testutils.getpath("tests", "src", "cli", "hi77.f").read_text() fn = tmpdir_factory.getbasetemp() / "hello.f" fn.write_text(fdat, encoding="ascii") return fn @@ -112,7 +111,7 @@ def hello_world_f77(tmpdir_factory): @pytest.fixture(scope="session") def retreal_f77(tmpdir_factory): """Generates a single f77 file for testing""" - fdat = util.getpath("tests", "src", "return_real", "foo77.f").read_text() + fdat = testutils.getpath("tests", "src", "return_real", "foo77.f").read_text() fn = tmpdir_factory.getbasetemp() / "foo.f" fn.write_text(fdat, encoding="ascii") return fn @@ -120,8 +119,8 @@ def retreal_f77(tmpdir_factory): @pytest.fixture(scope="session") def f2cmap_f90(tmpdir_factory): """Generates a single f90 file for testing""" - fdat = util.getpath("tests", "src", "f2cmap", "isoFortranEnvMap.f90").read_text() - f2cmap = util.getpath("tests", "src", "f2cmap", ".f2py_f2cmap").read_text() + fdat = testutils.getpath("tests", "src", "f2cmap", "isoFortranEnvMap.f90").read_text() + f2cmap = testutils.getpath("tests", "src", "f2cmap", ".f2py_f2cmap").read_text() fn = tmpdir_factory.getbasetemp() / "f2cmap.f90" fmap = tmpdir_factory.getbasetemp() / "mapfile" fn.write_text(fdat, encoding="ascii") @@ -142,7 +141,7 @@ def test_gh22819_cli(capfd, gh22819_cli, monkeypatch): """ ipath = Path(gh22819_cli) monkeypatch.setattr(sys, "argv", f"f2py -m blah {ipath}".split()) - with util.switchdir(ipath.parent): + with testutils.switchdir(ipath.parent): f2pycli() gen_paths = [item.name for item in ipath.parent.rglob("*") if item.is_file()] assert "blahmodule.c" not in gen_paths # shouldn't be generated @@ -158,7 +157,7 @@ def test_gh22819_many_pyf(capfd, gh22819_cli, monkeypatch): """ ipath = Path(gh22819_cli) monkeypatch.setattr(sys, "argv", f"f2py -m blah {ipath} hello.pyf".split()) - with util.switchdir(ipath.parent): + with testutils.switchdir(ipath.parent): with pytest.raises(ValueError, match="Only one .pyf file per call"): f2pycli() @@ -170,7 +169,7 @@ def test_gh23598_warn(capfd, gh23598_warn, monkeypatch): sys, "argv", f'f2py {ipath} -m test'.split()) - with util.switchdir(ipath.parent): + with testutils.switchdir(ipath.parent): f2pycli() # Generate files wrapper = foutl.wrap90.read_text() assert "intproductf2pywrap, intpr" not in wrapper @@ -184,7 +183,7 @@ def test_gen_pyf(capfd, hello_world_f90, monkeypatch): opath = Path(hello_world_f90).stem + ".pyf" monkeypatch.setattr(sys, "argv", f'f2py -h {opath} {ipath}'.split()) - with util.switchdir(ipath.parent): + with testutils.switchdir(ipath.parent): f2pycli() # Generate wrappers out, _ = capfd.readouterr() assert "Saving signatures to file" in out @@ -197,7 +196,7 @@ def test_gen_pyf_stdout(capfd, hello_world_f90, monkeypatch): """ ipath = Path(hello_world_f90) monkeypatch.setattr(sys, "argv", f'f2py -h stdout {ipath}'.split()) - with util.switchdir(ipath.parent): + with testutils.switchdir(ipath.parent): f2pycli() out, _ = capfd.readouterr() assert "Saving signatures to file" in out @@ -211,7 +210,7 @@ def test_gen_pyf_no_overwrite(capfd, hello_world_f90, monkeypatch): ipath = Path(hello_world_f90) monkeypatch.setattr(sys, "argv", f'f2py -h faker.pyf {ipath}'.split()) - with util.switchdir(ipath.parent): + with testutils.switchdir(ipath.parent): Path("faker.pyf").write_text("Fake news", encoding="ascii") with pytest.raises(SystemExit): f2pycli() # Refuse to overwrite @@ -227,7 +226,7 @@ def test_untitled_cli(capfd, hello_world_f90, monkeypatch): """ ipath = Path(hello_world_f90) monkeypatch.setattr(sys, "argv", f"f2py --backend meson -c {ipath}".split()) - with util.switchdir(ipath.parent): + with testutils.switchdir(ipath.parent): compiler_check_f2pycli() out, _ = capfd.readouterr() assert "untitledmodule.c" in out @@ -244,14 +243,14 @@ def test_no_py312_distutils_fcompiler(capfd, hello_world_f90, monkeypatch): monkeypatch.setattr( sys, "argv", f"f2py {ipath} -c --fcompiler=gfortran -m {MNAME}".split() ) - with util.switchdir(ipath.parent): + with testutils.switchdir(ipath.parent): compiler_check_f2pycli() out, _ = capfd.readouterr() assert "--fcompiler cannot be used with meson" in out monkeypatch.setattr( sys, "argv", ["f2py", "--help-link"] ) - with util.switchdir(ipath.parent): + with testutils.switchdir(ipath.parent): f2pycli() out, _ = capfd.readouterr() assert "Use --dep for meson builds" in out @@ -259,7 +258,7 @@ def test_no_py312_distutils_fcompiler(capfd, hello_world_f90, monkeypatch): monkeypatch.setattr( sys, "argv", f"f2py {ipath} -c -m {MNAME} --backend distutils".split() ) - with util.switchdir(ipath.parent): + with testutils.switchdir(ipath.parent): f2pycli() out, _ = capfd.readouterr() assert "Cannot use distutils backend with Python>=3.12" in out @@ -278,7 +277,7 @@ def test_f2py_skip(capfd, retreal_f77, monkeypatch): sys, "argv", f'f2py {ipath} -m test skip: {toskip}'.split()) - with util.switchdir(ipath.parent): + with testutils.switchdir(ipath.parent): f2pycli() out, err = capfd.readouterr() for skey in toskip.split(): @@ -301,7 +300,7 @@ def test_f2py_only(capfd, retreal_f77, monkeypatch): sys, "argv", f'f2py {ipath} -m test only: {tokeep}'.split()) - with util.switchdir(ipath.parent): + with testutils.switchdir(ipath.parent): f2pycli() out, err = capfd.readouterr() for skey in toskip.split(): @@ -331,7 +330,7 @@ def test_file_processing_switch(capfd, hello_world_f90, retreal_f77, ), ) - with util.switchdir(ipath.parent): + with testutils.switchdir(ipath.parent): f2pycli() out, err = capfd.readouterr() for skey in toskip.split(): @@ -350,7 +349,7 @@ def test_mod_gen_f77(capfd, hello_world_f90, monkeypatch): foutl = get_io_paths(hello_world_f90, mname=MNAME) ipath = foutl.f90inp monkeypatch.setattr(sys, "argv", f'f2py {ipath} -m {MNAME}'.split()) - with util.switchdir(ipath.parent): + with testutils.switchdir(ipath.parent): f2pycli() # Always generate C module @@ -368,7 +367,7 @@ def test_mod_gen_gh25263(capfd, hello_world_f77, monkeypatch): foutl = get_io_paths(hello_world_f77, mname=MNAME) ipath = foutl.finp monkeypatch.setattr(sys, "argv", f'f2py {ipath} -m {MNAME} -h hi.pyf'.split()) - with util.switchdir(ipath.parent): + with testutils.switchdir(ipath.parent): f2pycli() with Path('hi.pyf').open() as hipyf: pyfdat = hipyf.read() @@ -386,7 +385,7 @@ def test_lower_cmod(capfd, hello_world_f77, monkeypatch): capslo = re.compile(r"hi\(\)") # Case I: --lower is passed monkeypatch.setattr(sys, "argv", f'f2py {ipath} -m test --lower'.split()) - with util.switchdir(ipath.parent): + with testutils.switchdir(ipath.parent): f2pycli() out, _ = capfd.readouterr() assert capslo.search(out) is not None @@ -394,7 +393,7 @@ def test_lower_cmod(capfd, hello_world_f77, monkeypatch): # Case II: --no-lower is passed monkeypatch.setattr(sys, "argv", f'f2py {ipath} -m test --no-lower'.split()) - with util.switchdir(ipath.parent): + with testutils.switchdir(ipath.parent): f2pycli() out, _ = capfd.readouterr() assert capslo.search(out) is None @@ -419,7 +418,7 @@ def test_lower_sig(capfd, hello_world_f77, monkeypatch): f'f2py {ipath} -h {foutl.pyf} -m test --overwrite-signature'.split(), ) - with util.switchdir(ipath.parent): + with testutils.switchdir(ipath.parent): f2pycli() out, _ = capfd.readouterr() assert capslo.search(out) is not None @@ -433,7 +432,7 @@ def test_lower_sig(capfd, hello_world_f77, monkeypatch): .split(), ) - with util.switchdir(ipath.parent): + with testutils.switchdir(ipath.parent): f2pycli() out, _ = capfd.readouterr() assert capslo.search(out) is None @@ -451,7 +450,7 @@ def test_build_dir(capfd, hello_world_f90, monkeypatch): monkeypatch.setattr(sys, "argv", f'f2py -m {mname} {ipath} --build-dir {odir}'.split()) - with util.switchdir(ipath.parent): + with testutils.switchdir(ipath.parent): f2pycli() out, _ = capfd.readouterr() assert f"Wrote C/API module \"{mname}\"" in out @@ -467,7 +466,7 @@ def test_overwrite(capfd, hello_world_f90, monkeypatch): sys, "argv", f'f2py -h faker.pyf {ipath} --overwrite-signature'.split()) - with util.switchdir(ipath.parent): + with testutils.switchdir(ipath.parent): Path("faker.pyf").write_text("Fake news", encoding="ascii") f2pycli() out, _ = capfd.readouterr() @@ -484,7 +483,7 @@ def test_latexdoc(capfd, hello_world_f90, monkeypatch): monkeypatch.setattr(sys, "argv", f'f2py -m {mname} {ipath} --latex-doc'.split()) - with util.switchdir(ipath.parent): + with testutils.switchdir(ipath.parent): f2pycli() out, _ = capfd.readouterr() assert "Documentation is saved to file" in out @@ -502,7 +501,7 @@ def test_nolatexdoc(capfd, hello_world_f90, monkeypatch): monkeypatch.setattr(sys, "argv", f'f2py -m {mname} {ipath} --no-latex-doc'.split()) - with util.switchdir(ipath.parent): + with testutils.switchdir(ipath.parent): f2pycli() out, _ = capfd.readouterr() assert "Documentation is saved to file" not in out @@ -522,7 +521,7 @@ def test_shortlatex(capfd, hello_world_f90, monkeypatch): f'f2py -m {mname} {ipath} --latex-doc --short-latex'.split(), ) - with util.switchdir(ipath.parent): + with testutils.switchdir(ipath.parent): f2pycli() out, _ = capfd.readouterr() assert "Documentation is saved to file" in out @@ -540,7 +539,7 @@ def test_restdoc(capfd, hello_world_f90, monkeypatch): monkeypatch.setattr(sys, "argv", f'f2py -m {mname} {ipath} --rest-doc'.split()) - with util.switchdir(ipath.parent): + with testutils.switchdir(ipath.parent): f2pycli() out, _ = capfd.readouterr() assert "ReST Documentation is saved to file" in out @@ -558,7 +557,7 @@ def test_norestexdoc(capfd, hello_world_f90, monkeypatch): monkeypatch.setattr(sys, "argv", f'f2py -m {mname} {ipath} --no-rest-doc'.split()) - with util.switchdir(ipath.parent): + with testutils.switchdir(ipath.parent): f2pycli() out, _ = capfd.readouterr() assert "ReST Documentation is saved to file" not in out @@ -574,7 +573,7 @@ def test_debugcapi(capfd, hello_world_f90, monkeypatch): monkeypatch.setattr(sys, "argv", f'f2py -m {mname} {ipath} --debug-capi'.split()) - with util.switchdir(ipath.parent): + with testutils.switchdir(ipath.parent): f2pycli() with Path(f"./{mname}module.c").open() as ocmod: assert r"#define DEBUGCFUNCS" in ocmod.read() @@ -591,7 +590,7 @@ def test_debugcapi_bld(hello_world_f90, monkeypatch): monkeypatch.setattr(sys, "argv", f'f2py -m {mname} {ipath} -c --debug-capi'.split()) - with util.switchdir(ipath.parent): + with testutils.switchdir(ipath.parent): f2pycli() cmd_run = shlex.split(f"{sys.executable} -c \"import blah; blah.hi()\"") rout = subprocess.run(cmd_run, capture_output=True, encoding='UTF-8') @@ -620,7 +619,7 @@ def test_wrapfunc_def(capfd, hello_world_f90, monkeypatch): mname = "blah" monkeypatch.setattr(sys, "argv", f'f2py -m {mname} {ipath}'.split()) - with util.switchdir(ipath.parent): + with testutils.switchdir(ipath.parent): f2pycli() out, _ = capfd.readouterr() assert r"Fortran 77 wrappers are saved to" in out @@ -629,7 +628,7 @@ def test_wrapfunc_def(capfd, hello_world_f90, monkeypatch): monkeypatch.setattr(sys, "argv", f'f2py -m {mname} {ipath} --wrap-functions'.split()) - with util.switchdir(ipath.parent): + with testutils.switchdir(ipath.parent): f2pycli() out, _ = capfd.readouterr() assert r"Fortran 77 wrappers are saved to" in out @@ -645,7 +644,7 @@ def test_nowrapfunc(capfd, hello_world_f90, monkeypatch): monkeypatch.setattr(sys, "argv", f'f2py -m {mname} {ipath} --no-wrap-functions'.split()) - with util.switchdir(ipath.parent): + with testutils.switchdir(ipath.parent): f2pycli() out, _ = capfd.readouterr() assert r"Fortran 77 wrappers are saved to" not in out @@ -666,7 +665,7 @@ def test_inclheader(capfd, hello_world_f90, monkeypatch): split(), ) - with util.switchdir(ipath.parent): + with testutils.switchdir(ipath.parent): f2pycli() with Path(f"./{mname}module.c").open() as ocmod: ocmr = ocmod.read() @@ -700,7 +699,7 @@ def test_f2cmap(capfd, f2cmap_f90, monkeypatch): ipath = Path(f2cmap_f90) monkeypatch.setattr(sys, "argv", f'f2py -m blah {ipath} --f2cmap mapfile'.split()) - with util.switchdir(ipath.parent): + with testutils.switchdir(ipath.parent): f2pycli() out, _ = capfd.readouterr() assert "Reading f2cmap from 'mapfile' ..." in out @@ -718,7 +717,7 @@ def test_quiet(capfd, hello_world_f90, monkeypatch): ipath = Path(hello_world_f90) monkeypatch.setattr(sys, "argv", f'f2py -m blah {ipath} --quiet'.split()) - with util.switchdir(ipath.parent): + with testutils.switchdir(ipath.parent): f2pycli() out, _ = capfd.readouterr() assert len(out) == 0 @@ -732,7 +731,7 @@ def test_verbose(capfd, hello_world_f90, monkeypatch): ipath = Path(hello_world_f90) monkeypatch.setattr(sys, "argv", f'f2py -m blah {ipath} --verbose'.split()) - with util.switchdir(ipath.parent): + with testutils.switchdir(ipath.parent): f2pycli() out, _ = capfd.readouterr() assert "analyzeline" in out @@ -760,7 +759,7 @@ def test_npdistop(hello_world_f90, monkeypatch): ipath = Path(hello_world_f90) monkeypatch.setattr(sys, "argv", f'f2py -m blah {ipath} -c'.split()) - with util.switchdir(ipath.parent): + with testutils.switchdir(ipath.parent): f2pycli() cmd_run = shlex.split(f"{sys.executable} -c \"import blah; blah.hi()\"") rout = subprocess.run(cmd_run, capture_output=True, encoding='UTF-8') @@ -777,7 +776,7 @@ def test_no_freethreading_compatible(hello_world_f90, monkeypatch): ipath = Path(hello_world_f90) monkeypatch.setattr(sys, "argv", f'f2py -m blah {ipath} -c --no-freethreading-compatible'.split()) - with util.switchdir(ipath.parent): + with testutils.switchdir(ipath.parent): compiler_check_f2pycli() cmd = f"{sys.executable} -c \"import blah; blah.hi();" if NOGIL_BUILD: @@ -802,7 +801,7 @@ def test_freethreading_compatible(hello_world_f90, monkeypatch): ipath = Path(hello_world_f90) monkeypatch.setattr(sys, "argv", f'f2py -m blah {ipath} -c --freethreading-compatible'.split()) - with util.switchdir(ipath.parent): + with testutils.switchdir(ipath.parent): compiler_check_f2pycli() cmd = f"{sys.executable} -c \"import blah; blah.hi();" if NOGIL_BUILD: diff --git a/numpy/f2py/tests/test_isoc.py b/numpy/f2py/tests/test_isoc.py index f3450f15fead..bbc698b9e62f 100644 --- a/numpy/f2py/tests/test_isoc.py +++ b/numpy/f2py/tests/test_isoc.py @@ -1,14 +1,13 @@ import pytest import numpy as np +from numpy.f2py import testutils from numpy.testing import assert_allclose -from . import util - -class TestISOC(util.F2PyTest): +class TestISOC(testutils.F2PyTest): sources = [ - util.getpath("tests", "src", "isocintrin", "isoCtests.f90"), + testutils.getpath("tests", "src", "isocintrin", "isoCtests.f90"), ] # gh-24553 diff --git a/numpy/f2py/tests/test_kind.py b/numpy/f2py/tests/test_kind.py index ce223a555456..4357b40d14c6 100644 --- a/numpy/f2py/tests/test_kind.py +++ b/numpy/f2py/tests/test_kind.py @@ -3,6 +3,7 @@ import pytest +from numpy.f2py import testutils from numpy.f2py.crackfortran import ( _selected_int_kind_func as selected_int_kind, ) @@ -10,11 +11,9 @@ _selected_real_kind_func as selected_real_kind, ) -from . import util - -class TestKind(util.F2PyTest): - sources = [util.getpath("tests", "src", "kind", "foo.f90")] +class TestKind(testutils.F2PyTest): + sources = [testutils.getpath("tests", "src", "kind", "foo.f90")] @pytest.mark.skipif(sys.maxsize < 2 ** 31 + 1, reason="Fails for 32 bit machines") diff --git a/numpy/f2py/tests/test_mixed.py b/numpy/f2py/tests/test_mixed.py index 07f43e2bcfaa..5c67dda94cc7 100644 --- a/numpy/f2py/tests/test_mixed.py +++ b/numpy/f2py/tests/test_mixed.py @@ -2,16 +2,15 @@ import pytest +from numpy.f2py import testutils from numpy.testing import IS_PYPY -from . import util - -class TestMixed(util.F2PyTest): +class TestMixed(testutils.F2PyTest): sources = [ - util.getpath("tests", "src", "mixed", "foo.f"), - util.getpath("tests", "src", "mixed", "foo_fixed.f90"), - util.getpath("tests", "src", "mixed", "foo_free.f90"), + testutils.getpath("tests", "src", "mixed", "foo.f"), + testutils.getpath("tests", "src", "mixed", "foo_fixed.f90"), + testutils.getpath("tests", "src", "mixed", "foo_free.f90"), ] @pytest.mark.slow diff --git a/numpy/f2py/tests/test_modules.py b/numpy/f2py/tests/test_modules.py index 96d5ffc66093..fc9725864d7a 100644 --- a/numpy/f2py/tests/test_modules.py +++ b/numpy/f2py/tests/test_modules.py @@ -2,15 +2,14 @@ import pytest +from numpy.f2py import testutils from numpy.testing import IS_PYPY -from . import util - @pytest.mark.slow -class TestModuleFilterPublicEntities(util.F2PyTest): +class TestModuleFilterPublicEntities(testutils.F2PyTest): sources = [ - util.getpath( + testutils.getpath( "tests", "src", "modules", "gh26920", "two_mods_with_one_public_routine.f90" ) @@ -24,9 +23,9 @@ def test_gh26920(self): @pytest.mark.slow -class TestModuleWithoutPublicEntities(util.F2PyTest): +class TestModuleWithoutPublicEntities(testutils.F2PyTest): sources = [ - util.getpath( + testutils.getpath( "tests", "src", "modules", "gh26920", "two_mods_with_no_public_entities.f90" ) @@ -39,8 +38,8 @@ def test_gh26920(self): @pytest.mark.slow -class TestModuleDocString(util.F2PyTest): - sources = [util.getpath("tests", "src", "modules", "module_data_docstring.f90")] +class TestModuleDocString(testutils.F2PyTest): + sources = [testutils.getpath("tests", "src", "modules", "module_data_docstring.f90")] @pytest.mark.xfail(IS_PYPY, reason="PyPy cannot modify tp_doc after PyType_Ready") def test_module_docstring(self): @@ -56,11 +55,11 @@ def test_module_docstring(self): @pytest.mark.slow -class TestModuleAndSubroutine(util.F2PyTest): +class TestModuleAndSubroutine(testutils.F2PyTest): module_name = "example" sources = [ - util.getpath("tests", "src", "modules", "gh25337", "data.f90"), - util.getpath("tests", "src", "modules", "gh25337", "use_data.f90"), + testutils.getpath("tests", "src", "modules", "gh25337", "data.f90"), + testutils.getpath("tests", "src", "modules", "gh25337", "use_data.f90"), ] def test_gh25337(self): @@ -69,10 +68,10 @@ def test_gh25337(self): @pytest.mark.slow -class TestUsedModule(util.F2PyTest): +class TestUsedModule(testutils.F2PyTest): module_name = "fmath" sources = [ - util.getpath("tests", "src", "modules", "use_modules.f90"), + testutils.getpath("tests", "src", "modules", "use_modules.f90"), ] def test_gh25867(self): diff --git a/numpy/f2py/tests/test_parameter.py b/numpy/f2py/tests/test_parameter.py index 513d021002b7..846f82a495be 100644 --- a/numpy/f2py/tests/test_parameter.py +++ b/numpy/f2py/tests/test_parameter.py @@ -1,19 +1,18 @@ import pytest import numpy as np +from numpy.f2py import testutils -from . import util - -class TestParameters(util.F2PyTest): +class TestParameters(testutils.F2PyTest): # Check that intent(in out) translates as intent(inout) 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"), - util.getpath("tests", "src", "parameter", "constant_array.f90"), + testutils.getpath("tests", "src", "parameter", "constant_real.f90"), + testutils.getpath("tests", "src", "parameter", "constant_integer.f90"), + testutils.getpath("tests", "src", "parameter", "constant_both.f90"), + testutils.getpath("tests", "src", "parameter", "constant_compound.f90"), + testutils.getpath("tests", "src", "parameter", "constant_non_compound.f90"), + testutils.getpath("tests", "src", "parameter", "constant_array.f90"), ] @pytest.mark.slow diff --git a/numpy/f2py/tests/test_quoted_character.py b/numpy/f2py/tests/test_quoted_character.py index 3cbcb3c55b4f..ae4656f6f5c3 100644 --- a/numpy/f2py/tests/test_quoted_character.py +++ b/numpy/f2py/tests/test_quoted_character.py @@ -5,11 +5,11 @@ import pytest -from . import util +from numpy.f2py import testutils -class TestQuotedCharacter(util.F2PyTest): - sources = [util.getpath("tests", "src", "quoted_character", "foo.f")] +class TestQuotedCharacter(testutils.F2PyTest): + sources = [testutils.getpath("tests", "src", "quoted_character", "foo.f")] @pytest.mark.skipif(sys.platform == "win32", reason="Fails with MinGW64 Gfortran (Issue #9673)") diff --git a/numpy/f2py/tests/test_regression.py b/numpy/f2py/tests/test_regression.py index 93eb29e8e723..b3d9d417bb2e 100644 --- a/numpy/f2py/tests/test_regression.py +++ b/numpy/f2py/tests/test_regression.py @@ -5,13 +5,12 @@ import numpy as np import numpy.testing as npt +from numpy.f2py import testutils -from . import util - -class TestIntentInOut(util.F2PyTest): +class TestIntentInOut(testutils.F2PyTest): # Check that intent(in out) translates as intent(inout) - sources = [util.getpath("tests", "src", "regression", "inout.f90")] + sources = [testutils.getpath("tests", "src", "regression", "inout.f90")] @pytest.mark.slow def test_inout(self): @@ -25,9 +24,9 @@ def test_inout(self): assert np.allclose(x, [3, 1, 2]) -class TestDataOnlyMultiModule(util.F2PyTest): +class TestDataOnlyMultiModule(testutils.F2PyTest): # Check that modules without subroutines work - sources = [util.getpath("tests", "src", "regression", "datonly.f90")] + sources = [testutils.getpath("tests", "src", "regression", "datonly.f90")] @pytest.mark.slow def test_mdat(self): @@ -37,9 +36,9 @@ def test_mdat(self): assert self.module.simple_subroutine(5) == 1014 -class TestModuleWithDerivedType(util.F2PyTest): +class TestModuleWithDerivedType(testutils.F2PyTest): # Check that modules with derived types work - sources = [util.getpath("tests", "src", "regression", "mod_derived_types.f90")] + sources = [testutils.getpath("tests", "src", "regression", "mod_derived_types.f90")] @pytest.mark.slow def test_mtypes(self): @@ -47,9 +46,9 @@ def test_mtypes(self): assert self.module.type_subroutine(10) == 210 -class TestNegativeBounds(util.F2PyTest): +class TestNegativeBounds(testutils.F2PyTest): # Check that negative bounds work correctly - sources = [util.getpath("tests", "src", "negative_bounds", "issue_20853.f90")] + sources = [testutils.getpath("tests", "src", "negative_bounds", "issue_20853.f90")] @pytest.mark.slow def test_negbound(self): @@ -68,10 +67,10 @@ def ubound(xl, xh): assert np.allclose(rval, expval) -class TestNumpyVersionAttribute(util.F2PyTest): +class TestNumpyVersionAttribute(testutils.F2PyTest): # Check that th attribute __f2py_numpy_version__ is present # in the compiled module and that has the value np.__version__. - sources = [util.getpath("tests", "src", "regression", "inout.f90")] + sources = [testutils.getpath("tests", "src", "regression", "inout.f90")] @pytest.mark.slow def test_numpy_version_attribute(self): @@ -93,10 +92,10 @@ def test_include_path(): assert fname in fnames_in_dir -class TestIncludeFiles(util.F2PyTest): - sources = [util.getpath("tests", "src", "regression", "incfile.f90")] - options = [f"-I{util.getpath('tests', 'src', 'regression')}", - f"--include-paths {util.getpath('tests', 'src', 'regression')}"] +class TestIncludeFiles(testutils.F2PyTest): + sources = [testutils.getpath("tests", "src", "regression", "incfile.f90")] + options = [f"-I{testutils.getpath('tests', 'src', 'regression')}", + f"--include-paths {testutils.getpath('tests', 'src', 'regression')}"] @pytest.mark.slow def test_gh25344(self): @@ -104,9 +103,9 @@ def test_gh25344(self): res = self.module.add(3.0, 4.0) assert exp == res -class TestF77Comments(util.F2PyTest): +class TestF77Comments(testutils.F2PyTest): # Check that comments are stripped from F77 continuation lines - sources = [util.getpath("tests", "src", "regression", "f77comments.f")] + sources = [testutils.getpath("tests", "src", "regression", "f77comments.f")] @pytest.mark.slow def test_gh26148(self): @@ -123,9 +122,9 @@ def test_gh26466(self): res = self.module.testsub2() npt.assert_allclose(expected, res) -class TestF90Contiuation(util.F2PyTest): +class TestF90Contiuation(testutils.F2PyTest): # Check that comments are stripped from F90 continuation lines - sources = [util.getpath("tests", "src", "regression", "f90continuation.f90")] + sources = [testutils.getpath("tests", "src", "regression", "f90continuation.f90")] @pytest.mark.slow def test_gh26148b(self): @@ -135,9 +134,9 @@ def test_gh26148b(self): assert res[0] == 8 assert res[1] == 15 -class TestLowerF2PYDirectives(util.F2PyTest): +class TestLowerF2PYDirectives(testutils.F2PyTest): # Check variables are cased correctly - sources = [util.getpath("tests", "src", "regression", "lower_f2py_fortran.f90")] + sources = [testutils.getpath("tests", "src", "regression", "lower_f2py_fortran.f90")] @pytest.mark.slow def test_gh28014(self): @@ -148,8 +147,8 @@ def test_gh28014(self): def test_gh26623(): # Including libraries with . should not generate an incorrect meson.build try: - aa = util.build_module( - [util.getpath("tests", "src", "regression", "f90continuation.f90")], + aa = testutils.build_module( + [testutils.getpath("tests", "src", "regression", "f90continuation.f90")], ["-lfoo.bar"], module_name="Blah", ) @@ -162,8 +161,8 @@ def test_gh26623(): def test_gh25784(): # Compile dubious file using passed flags try: - aa = util.build_module( - [util.getpath("tests", "src", "regression", "f77fixedform.f95")], + aa = testutils.build_module( + [testutils.getpath("tests", "src", "regression", "f77fixedform.f95")], options=[ # Meson will collect and dedup these to pass to fortran_args: "--f77flags='-ffixed-form -O2'", @@ -176,9 +175,9 @@ def test_gh25784(): @pytest.mark.slow -class TestAssignmentOnlyModules(util.F2PyTest): +class TestAssignmentOnlyModules(testutils.F2PyTest): # Ensure that variables are exposed without functions or subroutines in a module - sources = [util.getpath("tests", "src", "regression", "assignOnlyModule.f90")] + sources = [testutils.getpath("tests", "src", "regression", "assignOnlyModule.f90")] @pytest.mark.slow def test_gh27167(self): diff --git a/numpy/f2py/tests/test_return_character.py b/numpy/f2py/tests/test_return_character.py index aae3f0f91671..8de7b760f2f6 100644 --- a/numpy/f2py/tests/test_return_character.py +++ b/numpy/f2py/tests/test_return_character.py @@ -3,14 +3,13 @@ import pytest from numpy import array - -from . import util +from numpy.f2py import testutils IS_S390X = platform.machine() == "s390x" @pytest.mark.slow -class TestReturnCharacter(util.F2PyTest): +class TestReturnCharacter(testutils.F2PyTest): def check_function(self, t, tname): if tname in ["t0", "t1", "s0", "s1"]: assert t("23") == b"2" @@ -33,8 +32,8 @@ def check_function(self, t, tname): class TestFReturnCharacter(TestReturnCharacter): sources = [ - util.getpath("tests", "src", "return_character", "foo77.f"), - util.getpath("tests", "src", "return_character", "foo90.f90"), + testutils.getpath("tests", "src", "return_character", "foo77.f"), + testutils.getpath("tests", "src", "return_character", "foo90.f90"), ] @pytest.mark.xfail(IS_S390X, reason="callback returns ' '") diff --git a/numpy/f2py/tests/test_return_complex.py b/numpy/f2py/tests/test_return_complex.py index aa3f28e679f8..9ad126946f43 100644 --- a/numpy/f2py/tests/test_return_complex.py +++ b/numpy/f2py/tests/test_return_complex.py @@ -1,12 +1,11 @@ import pytest from numpy import array - -from . import util +from numpy.f2py import testutils @pytest.mark.slow -class TestReturnComplex(util.F2PyTest): +class TestReturnComplex(testutils.F2PyTest): def check_function(self, t, tname): if tname in ["t0", "t8", "s0", "s8"]: err = 1e-5 @@ -53,8 +52,8 @@ def check_function(self, t, tname): class TestFReturnComplex(TestReturnComplex): sources = [ - util.getpath("tests", "src", "return_complex", "foo77.f"), - util.getpath("tests", "src", "return_complex", "foo90.f90"), + testutils.getpath("tests", "src", "return_complex", "foo77.f"), + testutils.getpath("tests", "src", "return_complex", "foo90.f90"), ] @pytest.mark.parametrize("name", ["t0", "t8", "t16", "td", "s0", "s8", "s16", "sd"]) diff --git a/numpy/f2py/tests/test_return_integer.py b/numpy/f2py/tests/test_return_integer.py index 13a9f862f311..fb541b0f3fd0 100644 --- a/numpy/f2py/tests/test_return_integer.py +++ b/numpy/f2py/tests/test_return_integer.py @@ -1,12 +1,11 @@ import pytest from numpy import array - -from . import util +from numpy.f2py import testutils @pytest.mark.slow -class TestReturnInteger(util.F2PyTest): +class TestReturnInteger(testutils.F2PyTest): def check_function(self, t, tname): assert t(123) == 123 assert t(123.6) == 123 @@ -39,8 +38,8 @@ def check_function(self, t, tname): class TestFReturnInteger(TestReturnInteger): sources = [ - util.getpath("tests", "src", "return_integer", "foo77.f"), - util.getpath("tests", "src", "return_integer", "foo90.f90"), + testutils.getpath("tests", "src", "return_integer", "foo77.f"), + testutils.getpath("tests", "src", "return_integer", "foo90.f90"), ] @pytest.mark.parametrize("name", diff --git a/numpy/f2py/tests/test_return_logical.py b/numpy/f2py/tests/test_return_logical.py index a4a339572366..64fb9745a478 100644 --- a/numpy/f2py/tests/test_return_logical.py +++ b/numpy/f2py/tests/test_return_logical.py @@ -1,11 +1,10 @@ import pytest from numpy import array +from numpy.f2py import testutils -from . import util - -class TestReturnLogical(util.F2PyTest): +class TestReturnLogical(testutils.F2PyTest): def check_function(self, t): assert t(True) == 1 assert t(False) == 0 @@ -49,8 +48,8 @@ def check_function(self, t): class TestFReturnLogical(TestReturnLogical): sources = [ - util.getpath("tests", "src", "return_logical", "foo77.f"), - util.getpath("tests", "src", "return_logical", "foo90.f90"), + testutils.getpath("tests", "src", "return_logical", "foo77.f"), + testutils.getpath("tests", "src", "return_logical", "foo90.f90"), ] @pytest.mark.slow diff --git a/numpy/f2py/tests/test_return_real.py b/numpy/f2py/tests/test_return_real.py index c871ed3d4fc2..9ed1fa6b1aa8 100644 --- a/numpy/f2py/tests/test_return_real.py +++ b/numpy/f2py/tests/test_return_real.py @@ -3,13 +3,12 @@ import pytest from numpy import array +from numpy.f2py import testutils from numpy.testing import IS_64BIT -from . import util - @pytest.mark.slow -class TestReturnReal(util.F2PyTest): +class TestReturnReal(testutils.F2PyTest): def check_function(self, t, tname): if tname in ["t0", "t4", "s0", "s4"]: err = 1e-5 @@ -96,8 +95,8 @@ def test_all(self, name): class TestFReturnReal(TestReturnReal): sources = [ - util.getpath("tests", "src", "return_real", "foo77.f"), - util.getpath("tests", "src", "return_real", "foo90.f90"), + testutils.getpath("tests", "src", "return_real", "foo77.f"), + testutils.getpath("tests", "src", "return_real", "foo90.f90"), ] @pytest.mark.parametrize("name", ["t0", "t4", "t8", "td", "s0", "s4", "s8", "sd"]) diff --git a/numpy/f2py/tests/test_routines.py b/numpy/f2py/tests/test_routines.py index 01135dd692a6..66f81f676f3b 100644 --- a/numpy/f2py/tests/test_routines.py +++ b/numpy/f2py/tests/test_routines.py @@ -1,13 +1,13 @@ import pytest -from . import util +from numpy.f2py import testutils @pytest.mark.slow -class TestRenamedFunc(util.F2PyTest): +class TestRenamedFunc(testutils.F2PyTest): sources = [ - util.getpath("tests", "src", "routines", "funcfortranname.f"), - util.getpath("tests", "src", "routines", "funcfortranname.pyf"), + testutils.getpath("tests", "src", "routines", "funcfortranname.f"), + testutils.getpath("tests", "src", "routines", "funcfortranname.pyf"), ] module_name = "funcfortranname" @@ -17,10 +17,10 @@ def test_gh25799(self): @pytest.mark.slow -class TestRenamedSubroutine(util.F2PyTest): +class TestRenamedSubroutine(testutils.F2PyTest): sources = [ - util.getpath("tests", "src", "routines", "subrout.f"), - util.getpath("tests", "src", "routines", "subrout.pyf"), + testutils.getpath("tests", "src", "routines", "subrout.f"), + testutils.getpath("tests", "src", "routines", "subrout.pyf"), ] module_name = "subrout" diff --git a/numpy/f2py/tests/test_semicolon_split.py b/numpy/f2py/tests/test_semicolon_split.py index 2a16b191beba..6aa4dda9ed4b 100644 --- a/numpy/f2py/tests/test_semicolon_split.py +++ b/numpy/f2py/tests/test_semicolon_split.py @@ -2,10 +2,9 @@ import pytest +from numpy.f2py import testutils from numpy.testing import IS_64BIT -from . import util - @pytest.mark.skipif( platform.system() == "Darwin", @@ -15,7 +14,7 @@ @pytest.mark.skipif( not IS_64BIT, reason="32-bit builds are buggy" ) -class TestMultiline(util.F2PyTest): +class TestMultiline(testutils.F2PyTest): suffix = ".pyf" module_name = "multiline" code = f""" @@ -48,7 +47,7 @@ def test_multiline(self): not IS_64BIT, reason="32-bit builds are buggy" ) @pytest.mark.slow -class TestCallstatement(util.F2PyTest): +class TestCallstatement(testutils.F2PyTest): suffix = ".pyf" module_name = "callstatement" code = f""" diff --git a/numpy/f2py/tests/test_size.py b/numpy/f2py/tests/test_size.py index ac2eaf1413ef..049b48ffc531 100644 --- a/numpy/f2py/tests/test_size.py +++ b/numpy/f2py/tests/test_size.py @@ -1,12 +1,11 @@ import pytest import numpy as np +from numpy.f2py import testutils -from . import util - -class TestSizeSumExample(util.F2PyTest): - sources = [util.getpath("tests", "src", "size", "foo.f90")] +class TestSizeSumExample(testutils.F2PyTest): + sources = [testutils.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 f484ea3f11a9..75beb3492822 100644 --- a/numpy/f2py/tests/test_string.py +++ b/numpy/f2py/tests/test_string.py @@ -1,12 +1,11 @@ import pytest import numpy as np +from numpy.f2py import testutils -from . import util - -class TestString(util.F2PyTest): - sources = [util.getpath("tests", "src", "string", "char.f90")] +class TestString(testutils.F2PyTest): + sources = [testutils.getpath("tests", "src", "string", "char.f90")] @pytest.mark.slow def test_char(self): @@ -19,8 +18,8 @@ def test_char(self): assert out == pytest.approx(expected) -class TestDocStringArguments(util.F2PyTest): - sources = [util.getpath("tests", "src", "string", "string.f")] +class TestDocStringArguments(testutils.F2PyTest): + sources = [testutils.getpath("tests", "src", "string", "string.f")] def test_example(self): a = np.array(b"123\0\0") @@ -36,8 +35,8 @@ def test_example(self): assert d.tobytes() == b"D23" -class TestFixedString(util.F2PyTest): - sources = [util.getpath("tests", "src", "string", "fixed_string.f90")] +class TestFixedString(testutils.F2PyTest): + sources = [testutils.getpath("tests", "src", "string", "fixed_string.f90")] @staticmethod def _sint(s, start=0, end=None): diff --git a/numpy/f2py/tests/test_symbolic.py b/numpy/f2py/tests/test_symbolic.py index ec23f522128b..b0416f605e1c 100644 --- a/numpy/f2py/tests/test_symbolic.py +++ b/numpy/f2py/tests/test_symbolic.py @@ -1,5 +1,6 @@ import pytest +from numpy.f2py import testutils from numpy.f2py.symbolic import ( ArithOp, Expr, @@ -30,10 +31,8 @@ normalize, ) -from . import util - -class TestSymbolic(util.F2PyTest): +class TestSymbolic(testutils.F2PyTest): def test_eliminate_quotes(self): def worker(s): r, d = eliminate_quotes(s) diff --git a/numpy/f2py/tests/test_value_attrspec.py b/numpy/f2py/tests/test_value_attrspec.py index 1afae08bfe0e..eef3b466e3aa 100644 --- a/numpy/f2py/tests/test_value_attrspec.py +++ b/numpy/f2py/tests/test_value_attrspec.py @@ -1,10 +1,10 @@ import pytest -from . import util +from numpy.f2py import testutils -class TestValueAttr(util.F2PyTest): - sources = [util.getpath("tests", "src", "value_attrspec", "gh21665.f90")] +class TestValueAttr(testutils.F2PyTest): + sources = [testutils.getpath("tests", "src", "value_attrspec", "gh21665.f90")] # gh-21665 @pytest.mark.slow diff --git a/numpy/f2py/tests/util.py b/numpy/f2py/testutils.py similarity index 100% rename from numpy/f2py/tests/util.py rename to numpy/f2py/testutils.py diff --git a/numpy/fft/meson.build b/numpy/fft/meson.build index e18949af5e31..58ba18913ae0 100644 --- a/numpy/fft/meson.build +++ b/numpy/fft/meson.build @@ -31,7 +31,6 @@ py.install_sources( py.install_sources( [ - 'tests/__init__.py', 'tests/test_helper.py', 'tests/test_pocketfft.py', ], diff --git a/numpy/fft/tests/__init__.py b/numpy/fft/tests/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/numpy/lib/tests/__init__.py b/numpy/lib/tests/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/numpy/linalg/meson.build b/numpy/linalg/meson.build index e2f8136208d6..f80399502e04 100644 --- a/numpy/linalg/meson.build +++ b/numpy/linalg/meson.build @@ -55,7 +55,6 @@ py.install_sources( py.install_sources( [ - 'tests/__init__.py', 'tests/test_deprecations.py', 'tests/test_linalg.py', 'tests/test_regression.py', diff --git a/numpy/linalg/tests/__init__.py b/numpy/linalg/tests/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/numpy/ma/tests/__init__.py b/numpy/ma/tests/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/numpy/matrixlib/tests/__init__.py b/numpy/matrixlib/tests/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/numpy/polynomial/tests/__init__.py b/numpy/polynomial/tests/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/numpy/random/meson.build b/numpy/random/meson.build index 16450278c846..35ec70a1ea78 100644 --- a/numpy/random/meson.build +++ b/numpy/random/meson.build @@ -120,7 +120,6 @@ py.install_sources( py.install_sources( [ - 'tests/__init__.py', 'tests/test_direct.py', 'tests/test_extending.py', 'tests/test_generator_mt19937.py', diff --git a/numpy/random/tests/__init__.py b/numpy/random/tests/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/numpy/testing/tests/__init__.py b/numpy/testing/tests/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/numpy/tests/__init__.py b/numpy/tests/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/numpy/tests/test_public_api.py b/numpy/tests/test_public_api.py index 6a36358c3a06..f9aa896f4cf0 100644 --- a/numpy/tests/test_public_api.py +++ b/numpy/tests/test_public_api.py @@ -189,6 +189,7 @@ def test_NPY_NO_EXPORT(): "f2py.func2subr", "f2py.rules", "f2py.symbolic", + "f2py.testutils", "f2py.use_rules", "fft.helper", "lib.user_array", # note: not in np.lib, but probably should just be deleted diff --git a/numpy/typing/tests/__init__.py b/numpy/typing/tests/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/pytest.ini b/pytest.ini index 132af0bb78ab..e60f9d24f514 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,5 +1,5 @@ [pytest] -addopts = -l +addopts = -l --import-mode=importlib norecursedirs = doc tools numpy/linalg/lapack_lite numpy/_core/code_generators numpy/_core/src/common/pythoncapi-compat doctest_optionflags = NORMALIZE_WHITESPACE ELLIPSIS ALLOW_UNICODE ALLOW_BYTES junit_family=xunit2 @@ -29,4 +29,4 @@ filterwarnings = ignore:`numpy.typing.mypy_plugin` is deprecated:DeprecationWarning # Ignore DeprecationWarning from struct module # see https://github.com/numpy/numpy/issues/28926 - ignore:Due to \'_pack_\', the \ No newline at end of file + ignore:Due to \'_pack_\', the diff --git a/ruff.toml b/ruff.toml index 7454c6c05e5b..fe99cd5388d0 100644 --- a/ruff.toml +++ b/ruff.toml @@ -94,8 +94,8 @@ ignore = [ "numpy/_core/_add_newdocs.py" = ["E501"] "numpy/_core/_add_newdocs_scalars.py" = ["E501"] "numpy/_core/code_generators/generate_umath.py" = ["E501"] -"numpy/lib/tests/test_function_base.py" = ["E501"] "numpy/lib/tests/test_format.py" = ["E501"] +"numpy/lib/tests/test_function_base.py" = ["E501"] "numpy/lib/tests/test_io.py" = ["E501"] "numpy/lib/tests/test_polynomial.py" = ["E501"] "numpy/linalg/tests/test_linalg.py" = ["E501"]