def judge_command_func(input_text, expect): if expect == "invalid": with pytest.raises(InvalidArguments): split_command_args(input_text) return command, _ = split_command_args(input_text) grammar = get_command_grammar(command) m = grammar.match(input_text) # test on not match if not expect: assert m is None return variables = m.variables() print("Found variables: {}".format(variables)) for expect_token, expect_value in expect.items(): all_variables = variables.getall(expect_token) if len(all_variables) > 1: assert sorted(all_variables) == sorted(expect_value) else: assert variables.get(expect_token) == expect_value
def test_split_commands_fail_on_unfinished_command(): with pytest.raises(InvalidArguments): split_command_args("setn")
def test_split_commands_fail_on_partially_input(command): with pytest.raises(AmbiguousCommand): split_command_args(command)
def test_split_commands_fail_on_unknown_command(): with pytest.raises(InvalidArguments): split_command_args("FOO BAR")
def test_split_commands(command, expected, args): parsed_command, parsed_args = split_command_args(command) assert expected == parsed_command assert args == parsed_args
def test_split_commands(command, expected): assert split_command_args(command)[0] == expected