def test_invalid_arg_spec(self): data = ''' *** Keywords *** Invalid [Arguments] ooops ${optional}=default ${required} ... @{too} @{many} &{notlast} ${x} ''' expected = Keyword( header=KeywordName( tokens=[Token(Token.KEYWORD_NAME, 'Invalid', 2, 0)]), body=[ Arguments( tokens=[ Token(Token.ARGUMENTS, '[Arguments]', 3, 4), Token(Token.ARGUMENT, 'ooops', 3, 19), Token(Token.ARGUMENT, '${optional}=default', 3, 28), Token(Token.ARGUMENT, '${required}', 3, 51), Token(Token.ARGUMENT, '@{too}', 4, 11), Token(Token.ARGUMENT, '@{many}', 4, 21), Token(Token.ARGUMENT, '&{notlast}', 4, 32), Token(Token.ARGUMENT, '${x}', 4, 46) ], errors=("Invalid argument syntax 'ooops'.", 'Non-default argument after default arguments.', 'Cannot have multiple varargs.', 'Only last argument can be kwargs.')) ], ) get_and_assert_model(data, expected, depth=1)
def test_break(self): model = get_model('''\ *** Keywords *** Name WHILE True Break BREAK BREAK END ''', data_only=True) expected = KeywordSection( header=SectionHeader( tokens=[Token(Token.KEYWORD_HEADER, '*** Keywords ***', 1, 0) ]), body=[ Keyword( header=KeywordName( tokens=[Token(Token.KEYWORD_NAME, 'Name', 2, 0)]), body=[ While(header=WhileHeader([ Token(Token.WHILE, 'WHILE', 3, 4), Token(Token.ARGUMENT, 'True', 3, 13) ]), body=[ KeywordCall([ Token(Token.KEYWORD, 'Break', 4, 8), Token(Token.ARGUMENT, 'BREAK', 4, 17) ]), Break([Token(Token.BREAK, 'BREAK', 5, 8)]) ], end=End([Token(Token.END, 'END', 6, 4)])) ], ) ]) assert_model(model.sections[0], expected)
def test_return(self): model = get_model('''\ *** Keywords *** Name Return RETURN RETURN RETURN ''', data_only=True) expected = KeywordSection( header=SectionHeader( tokens=[Token(Token.KEYWORD_HEADER, '*** Keywords ***', 1, 0) ]), body=[ Keyword( header=KeywordName( tokens=[Token(Token.KEYWORD_NAME, 'Name', 2, 0)]), body=[ KeywordCall([ Token(Token.KEYWORD, 'Return', 3, 4), Token(Token.ARGUMENT, 'RETURN', 3, 14) ]), ReturnStatement([ Token(Token.RETURN_STATEMENT, 'RETURN', 4, 4), Token(Token.ARGUMENT, 'RETURN', 4, 14) ]) ], ) ]) assert_model(model.sections[0], expected)
def test_continue(self): model = get_model('''\ *** Keywords *** Name FOR ${x} IN @{stuff} Continue CONTINUE CONTINUE END ''', data_only=True) expected = KeywordSection( header=SectionHeader( tokens=[Token(Token.KEYWORD_HEADER, '*** Keywords ***', 1, 0)] ), body=[ Keyword( header=KeywordName( tokens=[Token(Token.KEYWORD_NAME, 'Name', 2, 0)] ), body=[ For( header=ForHeader([Token(Token.FOR, 'FOR', 3, 4), Token(Token.VARIABLE, '${x}', 3, 11), Token(Token.FOR_SEPARATOR, 'IN', 3, 19), Token(Token.ARGUMENT, '@{stuff}', 3, 25)]), body=[KeywordCall([Token(Token.KEYWORD, 'Continue', 4, 8), Token(Token.ARGUMENT, 'CONTINUE', 4, 20)]), Continue([Token(Token.CONTINUE, 'CONTINUE', 5, 8)])], end=End([Token(Token.END, 'END', 6, 4)]) ) ], ) ] ) assert_model(model.sections[0], expected)
def test_return(self): data = ''' *** Keywords *** Name Return RETURN RETURN RETURN ''' expected = Keyword( header=KeywordName( tokens=[Token(Token.KEYWORD_NAME, 'Name', 2, 0)]), body=[ KeywordCall([ Token(Token.KEYWORD, 'Return', 3, 4), Token(Token.ARGUMENT, 'RETURN', 3, 14) ]), ReturnStatement([ Token(Token.RETURN_STATEMENT, 'RETURN', 4, 4), Token(Token.ARGUMENT, 'RETURN', 4, 14) ]) ], ) get_and_assert_model(data, expected, depth=1)
def test_invalid_arg_spec(self): model = get_model('''\ *** Keywords *** Invalid [Arguments] ooops ${optional}=default ${required} ... @{too} @{many} &{notlast} ${x} ''', data_only=True) expected = KeywordSection( header=SectionHeader( tokens=[Token(Token.KEYWORD_HEADER, '*** Keywords ***', 1, 0) ]), body=[ Keyword( header=KeywordName( tokens=[Token(Token.KEYWORD_NAME, 'Invalid', 2, 0)]), body=[ Arguments( tokens=[ Token(Token.ARGUMENTS, '[Arguments]', 3, 4), Token(Token.ARGUMENT, 'ooops', 3, 19), Token(Token.ARGUMENT, '${optional}=default', 3, 28), Token(Token.ARGUMENT, '${required}', 3, 51), Token(Token.ARGUMENT, '@{too}', 4, 11), Token(Token.ARGUMENT, '@{many}', 4, 21), Token(Token.ARGUMENT, '&{notlast}', 4, 32), Token(Token.ARGUMENT, '${x}', 4, 46) ], errors=( "Invalid argument syntax 'ooops'.", 'Non-default argument after default arguments.', 'Cannot have multiple varargs.', 'Only last argument can be kwargs.')) ], ) ]) assert_model(model.sections[0], expected)
Token('COMMENT', 'continues', 11, 13), Token('EOL', '\n', 11, 22), ]), Keyword( header=KeywordName( [ Token('KEYWORD_NAME', 'Keyword', 12, 0), Token('EOL', '\n', 12, 7) ]), body=[ Arguments([ Token('SEPARATOR', ' ', 13, 0), Token('ARGUMENTS', '[Arguments]', 13, 4), Token('SEPARATOR', ' ', 13, 15), Token('ARGUMENT', '${arg1}', 13, 19), Token('SEPARATOR', ' ', 13, 26), Token('ARGUMENT', '${arg2}', 13, 30), Token('EOL', '\n', 13, 37) ]), KeywordCall([ Token('SEPARATOR', ' ', 14, 0), Token('KEYWORD', 'Log', 14, 4), Token('SEPARATOR', ' ', 14, 7), Token('ARGUMENT', 'Got ${arg1} and ${arg}!', 14, 11), Token('EOL', '\n', 14, 34) ]) ]) ]) ])
Token('KEYWORD_HEADER', '*** Keywords ***', 7, 0), Token('EOL', '\n', 7, 16) ]), body=[ Keyword(header=Name([ Token('NAME', 'Keyword', 8, 0), Token('EOL', '\n', 8, 7) ]), body=[ Arguments([ Token('SEPARATOR', ' ', 9, 0), Token('ARGUMENTS', '[Arguments]', 9, 4), Token('SEPARATOR', ' ', 9, 15), Token('ARGUMENT', '${arg1}', 9, 19), Token('SEPARATOR', ' ', 9, 26), Token('ARGUMENT', '${arg2}', 9, 30), Token('EOL', '\n', 9, 37) ]), KeywordCall([ Token('SEPARATOR', ' ', 10, 0), Token('KEYWORD', 'Log', 10, 4), Token('SEPARATOR', ' ', 10, 7), Token('ARGUMENT', 'Got ${arg1} and ${arg}!', 10, 11), Token('EOL', '\n', 10, 34) ]) ]) ]) ])