From 55b16bf711c7d1d1e7405320a0ead7d664c1278e Mon Sep 17 00:00:00 2001 From: Namami Shanker Date: Tue, 21 Jun 2022 17:20:47 +0530 Subject: [PATCH 1/2] TST: Add f2py2e f2cmap flag test --- numpy/f2py/tests/test_f2py2e.py | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/numpy/f2py/tests/test_f2py2e.py b/numpy/f2py/tests/test_f2py2e.py index 9de043d73a71..ef8e4668851b 100644 --- a/numpy/f2py/tests/test_f2py2e.py +++ b/numpy/f2py/tests/test_f2py2e.py @@ -79,6 +79,17 @@ def retreal_f77(tmpdir_factory): fn.write_text(fdat, encoding="ascii") return fn +@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() + fn = tmpdir_factory.getbasetemp() / "f2cmap.f90" + fmap = tmpdir_factory.getbasetemp() / "mapfile" + fn.write_text(fdat, encoding="ascii") + fmap.write_text(f2cmap, encoding="ascii") + return fn + def test_gen_pyf(capfd, hello_world_f90, monkeypatch): """Ensures that a signature file is generated via the CLI @@ -533,13 +544,22 @@ def test_hlink(): pass -def test_f2cmap(): +def test_f2cmap(capfd, f2cmap_f90, monkeypatch): """Check that Fortran-to-Python KIND specs can be passed CLI :: --f2cmap """ - # TODO: populate - pass + ipath = Path(f2cmap_f90) + monkeypatch.setattr(sys, "argv", f'f2py -m blah {ipath} --f2cmap mapfile'.split()) + + with util.switchdir(ipath.parent): + f2pycli() + out, _ = capfd.readouterr() + assert "Reading f2cmap from 'mapfile' ..." in out + assert "Mapping \"real(kind=real32)\" to \"float\"" in out + assert "Mapping \"real(kind=real64)\" to \"double\"" in out + assert "Mapping \"integer(kind=int64)\" to \"long_long\"" in out + assert "Successfully applied user defined f2cmap changes" in out def test_quiet(capfd, hello_world_f90, monkeypatch): From 02533c5da4b5e4328d49dcafb8d0a5592ae337c7 Mon Sep 17 00:00:00 2001 From: Namami Shanker Date: Tue, 21 Jun 2022 17:38:24 +0530 Subject: [PATCH 2/2] TST: Tighten test_gen_pyf_stdout check --- numpy/f2py/tests/test_f2py2e.py | 1 + 1 file changed, 1 insertion(+) diff --git a/numpy/f2py/tests/test_f2py2e.py b/numpy/f2py/tests/test_f2py2e.py index ef8e4668851b..2c10f046f1d9 100644 --- a/numpy/f2py/tests/test_f2py2e.py +++ b/numpy/f2py/tests/test_f2py2e.py @@ -116,6 +116,7 @@ def test_gen_pyf_stdout(capfd, hello_world_f90, monkeypatch): f2pycli() out, _ = capfd.readouterr() assert "Saving signatures to file" in out + assert "function hi() ! in " in out def test_gen_pyf_no_overwrite(capfd, hello_world_f90, monkeypatch):