Esempio n. 1
0
    :param command: string: text that user started typing
    :param expected: list: expected completions
    """
    completer.set_fuzzy_match(True)

    position = len(command)
    result = list(completer.get_completions(
        Document(text=command, cursor_position=position),
        complete_event))

    expected = list(map(lambda t: Completion(t, -len(command)), expected))

    assert result == expected


pso = list(filter(lambda x: x.name.startswith('-'), all_options('ps')))


@pytest.mark.parametrize("command, expected, expected_pos", [
    ("ps ", pso, 0),
    ("ps --", list(filter(
        lambda x: x.long_name and x.long_name.startswith('--'), pso)), -2),
    ("ps --h", list(filter(
        lambda x: x.long_name and x.long_name.startswith('--h'), pso)), -3),
    ("ps --all ", list(filter(
        lambda x: x.long_name not in ['--all'], pso)), 0),
    ("ps --all --quiet ", list(filter(
        lambda x: x.long_name not in ['--all', '--quiet'], pso)), 0),
])
def test_options_completion_long(completer, complete_event, command, expected, expected_pos):
    """
Esempio n. 2
0
    :param command: string: text that user started typing
    :param expected: list: expected completions
    """
    completer.set_fuzzy_match(True)

    position = len(command)
    result = list(completer.get_completions(
        Document(text=command, cursor_position=position),
        complete_event))

    expected = list(map(lambda t: Completion(t, -len(command)), expected))

    assert result == expected


pso = list(filter(lambda x: x.name.startswith('-'), all_options('ps')))


@pytest.mark.parametrize("command, expected, expected_pos", [
    ("ps ", pso, 0),
    ("ps --", list(filter(
        lambda x: x.long_name and x.long_name.startswith('--'), pso)), -2),
    ("ps --h", list(filter(
        lambda x: x.long_name and x.long_name.startswith('--h'), pso)), -3),
    ("ps --all ", list(filter(
        lambda x: x.long_name not in ['--all'], pso)), 0),
    ("ps --all --quiet ", list(filter(
        lambda x: x.long_name not in ['--all', '--quiet'], pso)), 0),
])
def test_options_completion_long(completer, complete_event, command, expected, expected_pos):
    """
Esempio n. 3
0
def option_map(cmd, is_long):
    result = {}
    for x in all_options(cmd):
        if x.name.startswith('-'):
            result[x.get_name(is_long)] = x.display
    return result
Esempio n. 4
0
def option_map(cmd, is_long):
    result = {}
    for x in all_options(cmd):
        if x.name.startswith('-'):
            result[x.get_name(is_long)] = x.display
    return result