Exemplo n.º 1
0
 def check_include(reader):
     '''Internal helper function to avoid code replication.'''
     ast = Include_Stmt(reader)
     assert "INCLUDE 'my-non-existant-file.inc'" in str(ast)
     assert repr(ast).replace("u'", "'") == \
         ("Include_Stmt(Include_Filename("
          "'my-non-existant-file.inc'))")
Exemplo n.º 2
0
def test_no_space(f2003_create):
    '''Check that no space is required between the include keyword and the
    file string.

    '''
    line = "include'my-non-existant-file.inc'"
    ast = Include_Stmt(line)
    assert "INCLUDE 'my-non-existant-file.inc'" in str(ast)
Exemplo n.º 3
0
def test_spaces(f2003_create):
    '''Check that spaces are allowed before and after an include keyword
    as well as after the file string.

    '''
    line = " include 'my-non-existant-file.inc' "
    ast = Include_Stmt(line)
    assert "INCLUDE 'my-non-existant-file.inc'" in str(ast)
Exemplo n.º 4
0
def test_errors(f2003_create):
    '''Check that syntax errors produce a NoMatchError exception.'''
    for line in [
            None, "", "  ", "includ", "includ 'x'", "include", "include ''",
            "include \"x'", "include 'x\"", "include 'xxx", "include \"xxx",
            "include xxx'", "include xxx\"", "include x'x'", "include 'x'x",
            "x include 'x'"
    ]:
        with pytest.raises(NoMatchError) as excinfo:
            _ = Include_Stmt(line)
        assert "Include_Stmt: '{0}'".format(line) in str(excinfo.value)
Exemplo n.º 5
0
def test_include_filename_error(f2003_create, monkeypatch):
    '''Check that we raise an InternalError if a return from
    Include_Filename is None or an empty string. This should never
    happen as any matching errors would cause this class to raise an
    exception.

    '''

    monkeypatch.setattr("fparser.two.Fortran2003.Include_Filename",
                        lambda file_name: None)
    line = "include ' '"
    with pytest.raises(InternalError) as excinfo:
        _ = Include_Stmt(line)
    assert ("Include_Filename should never return None or an empty "
            "name") in str(excinfo.value)
Exemplo n.º 6
0
def test_double_quotes(f2003_create):
    '''Check that double quotes are allowed for the file string.'''
    line = 'include "my-non-existant-file.inc"'
    ast = Include_Stmt(line)
    assert "INCLUDE 'my-non-existant-file.inc'" in str(ast)
Exemplo n.º 7
0
def test_case(f2003_create):
    '''Check that different case is allowed for the include keyword.'''
    line = "InClUdE 'my-non-existant-file.inc'"
    ast = Include_Stmt(line)
    assert "INCLUDE 'my-non-existant-file.inc'" in str(ast)