def test_build_invalid_fortran(tmpdir): ''' Check that we raise the expected error when attempting to compile some invalid Fortran. Skips test if --compile not supplied to py.test on command-line. ''' Compile.skip_if_compilation_disabled() invalid_code = HELLO_CODE.replace("write", "wite", 1) old_pwd = tmpdir.chdir() try: with open("hello_world.f90", "w") as ffile: ffile.write(invalid_code) _compile = Compile(tmpdir) with pytest.raises(CompileError) as excinfo: _compile.compile_file("hello_world.f90") finally: old_pwd.chdir() assert "Compile error" in str(excinfo.value)
def test_compiler_with_flags(tmpdir): ''' Check that we can pass through flags to the Fortran compiler. Since correct flags are compiler-dependent and hard to test, we pass something that is definitely not a flag and check that the compiler complains. This test is skipped if no compilation tests have been requested (--compile flag to py.test). ''' Compile.skip_if_compilation_disabled() old_pwd = tmpdir.chdir() try: with open("hello_world.f90", "w") as ffile: ffile.write(HELLO_CODE) _compile = Compile(tmpdir) _compile._f90flags = "not-a-flag" with pytest.raises(CompileError) as excinfo: _compile.compile_file("hello_world.f90") assert "not-a-flag" in str(excinfo.value) # For completeness we also try with a valid flag although we # can't actually check its effect. _compile._f90flags = "-g" _compile.compile_file("hello_world.f90", link=True) finally: old_pwd.chdir()