def test_error_empty(f2003_create): '''Test that an InternalError is raised if the input is empty. ''' with pytest.raises(InternalError) as excinfo: _ = Kind_Selector("") assert "too short to be valid" in str(excinfo.value)
def test_kind_spaces(f2003_create): '''Test that a kind selector with 'kind=' present and spaces can be parsed successfully. ''' reader = get_reader(" ( kind = some_kind ) ") ast = Kind_Selector(reader) assert "(KIND = some_kind)" in str(ast)
def test_error_star_only(f2003_create): '''Test that an InternalError is raised if there are less than two characters in the string as valid input must have at least two. ''' with pytest.raises(InternalError) as excinfo: _ = Kind_Selector("*") assert "too short to be valid" in str(excinfo.value)
def test_nokind_spaces(f2003_create): '''Test that a kind selector with 'kind=' not present and spaces can be parsed successfully. Note, the parser automatically adds-in kind for the output. ''' reader = get_reader(" ( some_kind ) ") ast = Kind_Selector(reader) assert "(KIND = some_kind)" in str(ast)
def test_size_extension(f2003_create): '''Test that a kind selector with the '*number' format e.g. integer*4 can be parsed successfully. This is an extension to the standard but is well used and is supported in mainstream compilers so is also supported here. Note, we can't use a reader as it will not read '*2' so we pass the string directly. ''' ast = Kind_Selector("*2") assert "*2" in str(ast)
def test_tostr_error_nitems(f2003_create, monkeypatch): '''Test that the appropriate exception is raised if the number of elements in the self.items list is >3 or <2. ''' ast = Kind_Selector("*8") monkeypatch.setattr(ast, "items", ["*"]) with pytest.raises(InternalError) as excinfo: _ = str(ast) assert ("tostr() has '1' items, but expecting 2 or 3" in str(excinfo.value))
def test_nokind_kind_function(f2003_create): '''Test that a kind selector with 'kind=' not present and a kind function can be parsed successfully. This is a test as there is a risk that the pattern match will think the kind function is the start of 'kind='. Note, the parser automatically adds-in kind for the output. ''' reader = get_reader("(kind(kind_id))") ast = Kind_Selector(reader) assert "(KIND = kind(kind_id))" in str(ast)
def test_nokind_short(f2003_create): '''Test that a kind selector with 'kind=' not present and a name less than 6 characters can be parsed successfully. This is important as there is a pattern match for 'kind=' so we need to test we don't accidentally access outside of the string. Note, the parser automatically adds-in kind for the output. ''' reader = get_reader("(a)") ast = Kind_Selector(reader) assert "(KIND = a)" in str(ast)
def test_error_none(f2003_create): '''Test that an InternalError is raised if the input is None.''' with pytest.raises(InternalError) as excinfo: _ = Kind_Selector(None) assert "method match() is None" in str(excinfo.value)
def test_error_kind_equals(f2003_create): '''Test that None is returned if the '=' after 'kind' is not there.''' reader = get_reader("(KIND some_kind") ast = Kind_Selector(reader) assert not ast
def test_error_kind_name(f2003_create): '''Test that None is returned if the name 'kind' is incorrect.''' reader = get_reader("(KINE = some_kind") ast = Kind_Selector(reader) assert not ast
def test_error_right_bracket(f2003_create): '''Test that None is returned if the right bracket is missing.''' reader = get_reader("(KIND = some_kind") ast = Kind_Selector(reader) assert not ast