Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit af43752

Browse files
committed
TST: Ensure distutils is not imported on >3.12
1 parent 887c4be commit af43752

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

numpy/f2py/tests/test_f2py2e.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,39 @@ def test_untitled_cli(capfd, hello_world_f90, monkeypatch):
213213
assert "untitledmodule.c" in out
214214

215215

216+
@pytest.mark.skipif(platform.system() != 'Linux', reason='Compiler required')
217+
def test_no_py312_distutils_fcompiler(capfd, hello_world_f90, monkeypatch):
218+
"""Check that no distutils imports are performed on 3.12
219+
CLI :: --fcompiler --help-link --backend distutils
220+
"""
221+
MNAME = "hi"
222+
foutl = get_io_paths(hello_world_f90, mname=MNAME)
223+
ipath = foutl.f90inp
224+
monkeypatch.setattr(
225+
sys, "argv", f"f2py {ipath} --backend meson -c --fcompiler=gfortran -m {MNAME}".split()
226+
)
227+
with util.switchdir(ipath.parent):
228+
f2pycli()
229+
out, _ = capfd.readouterr()
230+
assert "--fcompiler cannot be used with meson" in out
231+
monkeypatch.setattr(
232+
sys, "argv", f"f2py --help-link".split()
233+
)
234+
with util.switchdir(ipath.parent):
235+
f2pycli()
236+
out, _ = capfd.readouterr()
237+
assert "Use --dep for meson builds" in out
238+
if (sys.version_info >= (3, 12)):
239+
MNAME = "hi2" # Needs to be different for a new -c
240+
monkeypatch.setattr(
241+
sys, "argv", f"f2py {ipath} -c -m {MNAME} --backend distutils".split()
242+
)
243+
with util.switchdir(ipath.parent):
244+
f2pycli()
245+
out, _ = capfd.readouterr()
246+
assert "Cannot use distutils backend with Python>=3.12" in out
247+
248+
216249
@pytest.mark.xfail
217250
def test_f2py_skip(capfd, retreal_f77, monkeypatch):
218251
"""Tests that functions can be skipped

0 commit comments

Comments
 (0)