MCPcopy Create free account
hub / github.com/numpy/numpy / test_f2py_init_compile

Function test_f2py_init_compile

numpy/f2py/tests/test_compile_function.py:27–76  ·  view source on GitHub ↗
(extra_args)

Source from the content-addressed store, hash-verified

25 [["--noopt", "--debug"], "--noopt --debug", ""])
26@pytest.mark.leaks_references(reason="Imported module seems never deleted.")
27def test_f2py_init_compile(extra_args):
28 # flush through the f2py __init__ compile() function code path as a
29 # crude test for input handling following migration from
30 # exec_command() to subprocess.check_output() in gh-11937
31
32 # the Fortran 77 syntax requires 6 spaces before any commands, but
33 # more space may be added/
34 fsource = """
35 integer function foo()
36 foo = 10 + 5
37 return
38 end
39 """
40 # use various helper functions in util.py to enable robust build /
41 # compile and reimport cycle in test suite
42 moddir = util.get_module_dir()
43 modname = util.get_temp_module_name()
44
45 cwd = os.getcwd()
46 target = os.path.join(moddir, str(uuid.uuid4()) + ".f")
47 # try running compile() with and without a source_fn provided so
48 # that the code path where a temporary file for writing Fortran
49 # source is created is also explored
50 for source_fn in [target, None]:
51 # mimic the path changing behavior used by build_module() in
52 # util.py, but don't actually use build_module() because it has
53 # its own invocation of subprocess that circumvents the
54 # f2py.compile code block under test
55 with util.switchdir(moddir):
56 ret_val = numpy.f2py.compile(fsource,
57 modulename=modname,
58 extra_args=extra_args,
59 source_fn=source_fn)
60
61 # check for compile success return value
62 assert ret_val == 0
63
64 # we are not currently able to import the Python-Fortran
65 # interface module on Windows / Appveyor, even though we do get
66 # successful compilation on that platform with Python 3.x
67 if sys.platform != "win32":
68 # check for sensible result of Fortran function; that means
69 # we can import the module name in Python and retrieve the
70 # result of the sum operation
71 return_check = import_module(modname)
72 calc_result = return_check.foo()
73 assert calc_result == 15
74 # Removal from sys.modules, is not as such necessary. Even with
75 # removal, the module (dict) stays alive.
76 del sys.modules[modname]
77
78
79def test_f2py_init_compile_failure():

Callers

nothing calls this directly

Calls 3

joinMethod · 0.45
compileMethod · 0.45
fooMethod · 0.45

Tested by

no test coverage detected