def check_use(reader):
     '''Internal helper function to avoid code replication.'''
     ast = Cray_Pointer_Stmt(reader)
     assert "POINTER(a, b)" in str(ast)
     assert (repr(ast).replace(
         'u',
         '') == "Cray_Pointer_Stmt('POINTER', Cray_Pointer_Decl_List(',', "
             "(Cray_Pointer_Decl(Name('a'), Name('b')),)))")
Esempio n. 2
0
def test_errors(f2003_create):
    '''Check that syntax errors produce a NoMatchError exception.'''
    for line in [
            "", "  ", "ponter (a, b)", "pointer", "pointer a, b"
            "pointer (a, b) (a, b)"
    ]:
        with pytest.raises(NoMatchError) as excinfo:
            _ = Cray_Pointer_Stmt(line)
        assert "Cray_Pointer_Stmt: '{0}'".format(line) in str(excinfo)
Esempio n. 3
0
def test_valid_cray_pointer(f2003_create, monkeypatch):
    '''Test that the cray-pointer extension to the standard produces the
    expected output if it is named as a valid extension.

    '''
    from fparser.two import utils
    monkeypatch.setattr(utils, "EXTENSIONS", ["cray-pointer"])
    myinput = "pointer(mypointer, mypointee)"
    result = Cray_Pointer_Stmt(myinput)
    assert str(result).lower() == myinput
Esempio n. 4
0
def test_invalid_cray_pointer(f2003_create, monkeypatch):
    '''Test that the cray-pointer extension to the standard raises an
    exception if it is not named as a valid extension.

    '''
    from fparser.two import utils
    monkeypatch.setattr(utils, "EXTENSIONS", [])
    myinput = "pointer (mypointer, mypointee)"
    with pytest.raises(NoMatchError) as excinfo:
        _ = Cray_Pointer_Stmt(myinput)
        assert "Cray_Pointer_Stmt: '{0}'".format(myinput) \
            in str(excinfo.value)
Esempio n. 5
0
def test_list(f2003_create):
    '''Check that a list of Cray-pointers is supported.'''
    line = "pointer (a, b), (c, d(1:n)), (e, f)"
    ast = Cray_Pointer_Stmt(line)
    assert "POINTER(a, b), (c, d(1 : n)), (e, f)" in str(ast)
Esempio n. 6
0
def test_case(f2003_create):
    '''Check that different case is allowed.'''
    line = "PoInTeR (a, b)"
    ast = Cray_Pointer_Stmt(line)
    assert "POINTER(a, b)" in str(ast)
Esempio n. 7
0
def test_spaces(f2003_create):
    '''Check that spaces are allowed.'''
    line = "  pointer  ( a , b )  "
    ast = Cray_Pointer_Stmt(line)
    assert "POINTER(a, b)" in str(ast)
Esempio n. 8
0
 def check_use(reader):
     '''Internal helper function to avoid code replication.'''
     ast = Cray_Pointer_Stmt(reader)
     assert "POINTER(a, b)" in str(ast)
     assert repr(ast) == ("Cray_Pointer_Stmt('POINTER', Cray_Pointer_Decl"
                          "(Name('a'), Name('b')))")