Exemplo n.º 1
0
def test_compiler_works(tmpdir):
    ''' Check that the specified compiler works for a hello-world
    example '''
    Compile.skip_if_compilation_disabled()

    old_pwd = tmpdir.chdir()
    try:
        with open("hello_world.f90", "w") as ffile:
            ffile.write(HELLO_CODE)
        Compile(tmpdir).compile_file("hello_world.f90", link=True)
    finally:
        old_pwd.chdir()
Exemplo n.º 2
0
def test_compile_str(monkeypatch, tmpdir):
    ''' Checks for the routine that compiles Fortran supplied as a string '''
    # Check that we always return True if compilation testing is disabled
    Compile.skip_if_compilation_disabled()
    _compile = Compile(tmpdir)
    test_compile = "psyclone.tests.utilities.Compile"
    monkeypatch.setattr(test_compile + ".TEST_COMPILE", False)
    monkeypatch.setattr(test_compile + ".TEST_COMPILE_OPENCL", False)
    assert _compile.string_compiles("not fortran")
    # Re-enable compilation testing and check that we can build hello world
    monkeypatch.setattr(test_compile + ".TEST_COMPILE", True)
    assert _compile.string_compiles(HELLO_CODE)
    # Repeat for some broken code
    invalid_code = HELLO_CODE.replace("write", "wite", 1)
    assert not _compile.string_compiles(invalid_code)
Exemplo n.º 3
0
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)
Exemplo n.º 4
0
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()