Esempio n. 1
0
def test_patch_completer():
    client = Client("127.0.0.1", "6379", None)
    grammar = get_command_grammar("MGET")
    completer = GrammarCompleter(grammar, completer_mapping)
    client.pre_hook(
        "MGET foo bar hello world", "MGET", "foo bar hello world", completer
    )
    assert completer.completers["key"].words == ["world", "hello", "bar", "foo"]
    assert completer.completers["keys"].words == ["world", "hello", "bar", "foo"]

    grammar = get_command_grammar("GET")
    completer = GrammarCompleter(grammar, completer_mapping)
    client.pre_hook("GET bar", "GET", "bar", completer)
    assert completer.completers["keys"].words == ["bar", "world", "hello", "foo"]
Esempio n. 2
0
def test_running_with_pipeline(clean_redis, iredis_client, capfd):
    grammar = get_command_grammar("get")
    completer = GrammarCompleter(grammar, get_completer_mapping())
    clean_redis.set("foo", "hello \n world")
    with pytest.raises(StopIteration):
        next(iredis_client.send_command("get foo | grep w", completer))
    out, err = capfd.readouterr()
    assert out == " world\n"
Esempio n. 3
0
def test_split_shell_command(iredis_client):
    grammar = get_command_grammar("get")

    assert iredis_client.split_command_and_pipeline(" get json | rg . ",
                                                    grammar) == (
                                                        " get json ",
                                                        "rg . ",
                                                    )

    assert iredis_client.split_command_and_pipeline(
        """ get "json | \\" hello" | rg . """,
        grammar) == (""" get "json | \\" hello" """, "rg . ")
Esempio n. 4
0
    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