xonsh/tests/completers/test_completer_command.py
Noorhteen Raja NJ 769dfbe6aa
Py 312 pre-liminary support (#5156)
* refactor: project requires 3.9+

changed as per NEP-29
https://numpy.org/neps/nep-0029-deprecation_policy.html

* test: nose type tests are deprecated in pytest now

* fix: deprecation of ast.Str and ast.Bytes and .s attribute access

* fix: deprecation of ast.Num,ast.NameConstant,ast.Ellipsis

* refactor: upgrade code to be py39+ using ruff

the changes are auto-generated

* refactor: remove typing.Annotated compatibility code

* fix: temporarily disable having xonsh syntax inside f-strings

* test: skip failing tests

there is no workaround for this version. It might get solved in the
final release though

* refactor: make XonshSession.completer lazily populated

this speedsup the tests as cmd_cache would not be actively populated
when used in default_completers function

* refactor: make presence of walrus operator default
2023-07-04 22:18:37 +05:30

58 lines
1.5 KiB
Python

import pytest
from xonsh.completers._aliases import complete_aliases
@pytest.fixture
def mock_completer(monkeypatch, xsh_with_aliases):
def dummy_completer(*_):
return
xsh = xsh_with_aliases
monkeypatch.setattr(
xsh, "_completers", {"one": dummy_completer, "two": complete_aliases}
)
monkeypatch.setattr(xsh, "ctx", {"three": lambda: 1, "four": lambda: 2})
return xsh
@pytest.mark.parametrize(
"args, positionals, options",
[
(
"completer",
{"add", "remove", "rm", "list", "ls", "complete"},
{"--help", "-h"},
),
(
"completer add",
set(),
{"--help", "-h"},
),
(
"completer add newcompleter",
{"three", "four"},
{"--help", "-h"},
),
(
"completer add newcompleter three",
{"<one", ">two", ">one", "<two", "end", "start"},
{"--help", "-h"},
),
(
"completer remove",
{"one", "two"},
{"--help", "-h"},
),
(
"completer list",
set(),
{"--help", "-h"},
),
],
)
def test_completer_command(args, positionals, options, mock_completer, check_completer):
assert check_completer(args) == positionals
mock_completer.env["ALIAS_COMPLETIONS_OPTIONS_BY_DEFAULT"] = True
assert check_completer(args) == positionals.union(options)