示例#1
0
def test_single_entry(f2003_create):
    '''Test that a data_ref object is not returned when the sequence is
    valid but contains a single entry.

    '''
    for string in ["a", " a ", "A"]:
        result = Data_Ref(string)
        assert str(result) == str(result).strip()
        assert isinstance(result, Name)

    result = Data_Ref("a(2)")
    assert str(result) == str(result).strip()
    assert isinstance(result, Part_Ref)
示例#2
0
def test_valid_sequence(f2003_create):
    '''Test that a data_ref object is returned when a valid sequence is
    supplied.

    '''
    for string in ["a%b", " a % b ", "a%b%c", "A%B%C"]:
        result = Data_Ref(string)
        assert str(result) == str(result).strip()
        assert isinstance(result, Data_Ref)
示例#3
0
def test_match_instance(f2003_create):
    '''Test the sequencebase init, tostr and torepr methods.'''
    from fparser.two.Fortran2003 import Data_Ref, Type_Param_Name_List

    # ',' separator.
    obj = Type_Param_Name_List("a,b,c")
    assert obj.tostr() == "a, b, c"
    assert (obj.torepr() ==
            "Type_Param_Name_List(',', (Name('a'), Name('b'), Name('c')))")

    # '%' separator.
    obj = Data_Ref("a%b%c")
    assert obj.tostr() == "a % b % c"
    assert obj.torepr() == "Data_Ref('%', (Name('a'), Name('b'), Name('c')))"
示例#4
0
def test_createvarname_error2(monkeypatch):
    '''Test that if the create_var_name function does not recognise
    content within a Data_Ref passed to it, then it raises an
    exception in the expected way.

    '''
    name = "class"
    if six.PY2:
        name = "type"
    content = Data_Ref("a%b")
    monkeypatch.setattr(content, "items", ["invalid", "invalid"])
    with pytest.raises(InternalError) as excinfo:
        _ = create_var_name(content)
    assert ("algorithm.py:create_var_name unrecognised structure "
            "'<{0} 'str'>' in '<class 'fparser.two.Fortran2003."
            "Data_Ref'>'".format(name) in str(excinfo.value))
示例#5
0
    '''
    name = "class"
    if six.PY2:
        name = "type"
    content = Data_Ref("a%b")
    monkeypatch.setattr(content, "items", ["invalid", "invalid"])
    with pytest.raises(InternalError) as excinfo:
        _ = create_var_name(content)
    assert ("algorithm.py:create_var_name unrecognised structure "
            "'<{0} 'str'>' in '<class 'fparser.two.Fortran2003."
            "Data_Ref'>'".format(name) in str(excinfo.value))


@pytest.mark.parametrize("expression,expected", [
    (Name("a"), "a"), (Part_Ref("a"), "a"), (Part_Ref("a(1,n)"), "a"),
    (Data_Ref("c%b%a"), "c_b_a"), (Data_Ref("c(0)%b%a(1,n)"), "c_b_a"),
    (Proc_Component_Ref("self%a"), "self_a")])
def test_createvarname(expression, expected):
    '''Test that create var name works as expected (for cases with Name,
    Part_Ref, Data_Ref and Proc_Component_Ref).

    '''
    assert create_var_name(expression) == expected

# class KernelCall() tests


def test_kernelcall_repr():
    '''Test that the __repr__ method in KernelCall() behaves as expected.'''

    class KtypeDummy(object):
示例#6
0
def test_invalid(f2003_create):
    '''Test that there is no match when the input is invalid. '''

    for string in ["", "  ", "1", "%", "a b"]:
        with pytest.raises(NoMatchError):
            assert Data_Ref(string) is None