Пример #1
0
def test_complete_path(xonsh_builtins):
    xonsh_builtins.__xonsh_env__ = {'CASE_SENSITIVE_COMPLETIONS': False,
                                    'GLOB_SORTED': True,
                                    'SUBSEQUENCE_PATH_COMPLETION': False,
                                    'FUZZY_PATH_COMPLETION': False,
                                    'SUGGEST_THRESHOLD': 3,
                                    'CDPATH': set(),
    }
    xcp.complete_path('[1-0.1]', '[1-0.1]', 0, 7, dict())
Пример #2
0
def test_complete_path(xonsh_builtins):
    xonsh_builtins.__xonsh_env__ = {'CASE_SENSITIVE_COMPLETIONS': False,
                                    'GLOB_SORTED': True,
                                    'SUBSEQUENCE_PATH_COMPLETION': False,
                                    'FUZZY_PATH_COMPLETION': False,
                                    'SUGGEST_THRESHOLD': 3,
                                    'CDPATH': set(),
    }
    xcp.complete_path('[1-0.1]', '[1-0.1]', 0, 7, dict())
Пример #3
0
def test_complete_path(xession, completion_context_parse):
    xession.env = {
        "CASE_SENSITIVE_COMPLETIONS": False,
        "GLOB_SORTED": True,
        "SUBSEQUENCE_PATH_COMPLETION": False,
        "FUZZY_PATH_COMPLETION": False,
        "SUGGEST_THRESHOLD": 3,
        "CDPATH": set(),
    }
    xcp.complete_path(completion_context_parse("[1-0.1]", 7))
Пример #4
0
def test_complete_path(xonsh_builtins):
    xonsh_builtins.__xonsh__.env = {
        "CASE_SENSITIVE_COMPLETIONS": False,
        "GLOB_SORTED": True,
        "SUBSEQUENCE_PATH_COMPLETION": False,
        "FUZZY_PATH_COMPLETION": False,
        "SUGGEST_THRESHOLD": 3,
        "CDPATH": set(),
    }
    xcp.complete_path("[1-0.1]", "[1-0.1]", 0, 7, dict())
Пример #5
0
def test_cd_path_no_cd(mock_add_cdpaths, xonsh_builtins):
    xonsh_builtins.__xonsh_env__ = {'CASE_SENSITIVE_COMPLETIONS': False,
                                    'GLOB_SORTED': True,
                                    'SUBSEQUENCE_PATH_COMPLETION': False,
                                    'FUZZY_PATH_COMPLETION': False,
                                    'SUGGEST_THRESHOLD': 3,
                                    'CDPATH': ['/'],
    }
    xcp.complete_path('a', 'cat a', 4, 5, dict())
    mock_add_cdpaths.assert_not_called()
Пример #6
0
def test_complete_path(xonsh_builtins):
    xonsh_builtins.__xonsh__.env = {
        "CASE_SENSITIVE_COMPLETIONS": False,
        "GLOB_SORTED": True,
        "SUBSEQUENCE_PATH_COMPLETION": False,
        "FUZZY_PATH_COMPLETION": False,
        "SUGGEST_THRESHOLD": 3,
        "CDPATH": set(),
    }
    xcp.complete_path("[1-0.1]", "[1-0.1]", 0, 7, dict())
Пример #7
0
def test_cd_path_no_cd(mock_add_cdpaths, xession, completion_context_parse):
    xession.env = {
        "CASE_SENSITIVE_COMPLETIONS": False,
        "GLOB_SORTED": True,
        "SUBSEQUENCE_PATH_COMPLETION": False,
        "FUZZY_PATH_COMPLETION": False,
        "SUGGEST_THRESHOLD": 3,
        "CDPATH": ["/"],
    }
    xcp.complete_path(completion_context_parse("cat a", 5))
    mock_add_cdpaths.assert_not_called()
Пример #8
0
def test_cd_path_no_cd(mock_add_cdpaths, xonsh_builtins):
    xonsh_builtins.__xonsh__.env = {
        "CASE_SENSITIVE_COMPLETIONS": False,
        "GLOB_SORTED": True,
        "SUBSEQUENCE_PATH_COMPLETION": False,
        "FUZZY_PATH_COMPLETION": False,
        "SUGGEST_THRESHOLD": 3,
        "CDPATH": ["/"],
    }
    xcp.complete_path("a", "cat a", 4, 5, dict())
    mock_add_cdpaths.assert_not_called()
Пример #9
0
def test_cd_path_no_cd(mock_add_cdpaths, xonsh_builtins):
    xonsh_builtins.__xonsh__.env = {
        "CASE_SENSITIVE_COMPLETIONS": False,
        "GLOB_SORTED": True,
        "SUBSEQUENCE_PATH_COMPLETION": False,
        "FUZZY_PATH_COMPLETION": False,
        "SUGGEST_THRESHOLD": 3,
        "CDPATH": ["/"],
    }
    xcp.complete_path("a", "cat a", 4, 5, dict())
    mock_add_cdpaths.assert_not_called()
Пример #10
0
def test_path_in_python_code(num_args, completion_context_parse):
    with tempfile.NamedTemporaryFile(prefix="long_name") as tmp:
        args = []
        if num_args:
            args = ["blah"] * 3 + [tmp.name[:-2]]
            args = args[-num_args:]

        inner_line = " ".join(map(repr, args))
        exp = xcp.complete_path(
            completion_context_parse(inner_line, len(inner_line)))
        line = "@(" + inner_line
        out = xcp.complete_path(completion_context_parse(line, len(line)))
        assert out == exp
Пример #11
0
def complete_base(prefix, line, start, end, ctx):
    """If the line is empty, complete based on valid commands, python names,
    and paths.  If we are completing the first argument, complete based on
    valid commands and python names.
    """
    if line.strip() and prefix != line:
        # don't do unnecessary completions
        return set()

    # get and unpack python completions
    python_comps = complete_python(prefix, line, start, end, ctx)
    if isinstance(python_comps, cabc.Sequence):
        python_comps, python_comps_len = python_comps
    else:
        python_comps_len = None
    # add command completions
    out = python_comps | complete_command(prefix, line, start, end, ctx)
    # add paths, if needed
    if line.strip() == "":
        paths = complete_path(prefix, line, start, end, ctx, False)
        return (out | paths[0]), paths[1]
    elif prefix == line:
        if python_comps_len is None:
            return out
        else:
            return out, python_comps_len
    return set()
Пример #12
0
def invoke_completer(prefix: str, line: str, begidx: int, endidx: int,
                     ctx: dict):
    if not line.startswith("inv"):
        return set()
    args = line.split(" ")
    if len(args) > 1 and args[-2] == "-f":
        from xonsh.completers.path import complete_path

        return complete_path(prefix, line, begidx, endidx, ctx)
    tasks = silent_run("invoke --complete")
    return set(tasks.split("\n"))
Пример #13
0
def complete_base(prefix, line, start, end, ctx):
    """If the line is empty, complete based on valid commands, python names,
    and paths.  If we are completing the first argument, complete based on
    valid commands and python names.
    """
    if line.strip() == '':
        out = (complete_python(prefix, line, start, end, ctx) |
               complete_command(prefix, line, start, end, ctx))
        paths = complete_path(prefix, line, start, end, ctx, False)
        return (out | paths[0]), paths[1]
    elif prefix == line:
        return (complete_python(prefix, line, start, end, ctx) |
                complete_command(prefix, line, start, end, ctx))
    return set()
Пример #14
0
def complete_base(prefix, line, start, end, ctx):
    """If the line is empty, complete based on valid commands, python names,
    and paths.  If we are completing the first argument, complete based on
    valid commands and python names.
    """
    if line.strip() == '':
        out = (complete_python(prefix, line, start, end, ctx)
               | complete_command(prefix, line, start, end, ctx))
        paths = complete_path(prefix, line, start, end, ctx, False)
        return (out | paths[0]), paths[1]
    elif prefix == line:
        return (complete_python(prefix, line, start, end, ctx)
                | complete_command(prefix, line, start, end, ctx))
    return set()
Пример #15
0
def test_complete_path_ending_with_equal_sign(xession,
                                              completion_context_parse):
    xession.env = {
        "CASE_SENSITIVE_COMPLETIONS": True,
        "GLOB_SORTED": True,
        "SUBSEQUENCE_PATH_COMPLETION": False,
        "FUZZY_PATH_COMPLETION": False,
        "SUGGEST_THRESHOLD": 1,
        "CDPATH": set(),
    }
    with tempfile.NamedTemporaryFile(suffix="=") as tmp:
        prefix_file_name = tmp.name.replace("=", "")
        prefix = prefix_file_name
        line = f"ls {prefix}"
        out = xcp.complete_path(completion_context_parse(line, len(line)))
        expected = f"{tmp.name} "  # has trailing space
        assert expected == out[0].pop()
Пример #16
0
def test_complete_path_when_prefix_is_raw_path_string(quote, xonsh_builtins):
    xonsh_builtins.__xonsh__.env = {
        "CASE_SENSITIVE_COMPLETIONS": True,
        "GLOB_SORTED": True,
        "SUBSEQUENCE_PATH_COMPLETION": False,
        "FUZZY_PATH_COMPLETION": False,
        "SUGGEST_THRESHOLD": 1,
        "CDPATH": set(),
    }
    with tempfile.NamedTemporaryFile(suffix="_dummySuffix") as tmp:
        prefix_file_name = tmp.name.replace("_dummySuffix", "")
        prefix = f"pr{quote}{prefix_file_name}"
        line = f"ls {prefix}"
        out = xcp.complete_path(prefix, line, line.find(prefix), len(line),
                                dict())
        expected = f"pr{quote}{tmp.name}{quote}"
        assert expected == out[0].pop()
Пример #17
0
def complete_base(prefix, line, start, end, ctx):
    """If the line is empty, complete based on valid commands, python names,
    and paths.  If we are completing the first argument, complete based on
    valid commands and python names.
    """
    if line.strip() == "":
        out = complete_python(prefix, line, start, end, ctx) | complete_command(
            prefix, line, start, end, ctx
        )
        paths = complete_path(prefix, line, start, end, ctx, False)
        return (out | paths[0]), paths[1]
    elif prefix == line:
        python_comps = complete_python(prefix, line, start, end, ctx)
        if isinstance(python_comps, cabc.Sequence):
            return (
                python_comps[0] | complete_command(prefix, line, start, end, ctx),
                python_comps[1],
            )
        else:
            return python_comps | complete_command(prefix, line, start, end, ctx)
    return set()
Пример #18
0
def complete_base(prefix, line, start, end, ctx):
    """If the line is empty, complete based on valid commands, python names,
    and paths.  If we are completing the first argument, complete based on
    valid commands and python names.
    """
    # get and unpack python completions
    python_comps = complete_python(prefix, line, start, end, ctx)
    if isinstance(python_comps, cabc.Sequence):
        python_comps, python_comps_len = python_comps
    else:
        python_comps_len = None
    # add command completions
    out = python_comps | complete_command(prefix, line, start, end, ctx)
    # add paths, if needed
    if line.strip() == "":
        paths = complete_path(prefix, line, start, end, ctx, False)
        return (out | paths[0]), paths[1]
    elif prefix == line:
        if python_comps_len is None:
            return out
        else:
            return out, python_comps_len
    return set()