Skip to content

Commit

Permalink
TERM and fish test
Browse files Browse the repository at this point in the history
  • Loading branch information
mjurbanski-reef committed Mar 27, 2024
1 parent 22d9fed commit 69dd411
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
11 changes: 7 additions & 4 deletions b2/_internal/_cli/autocomplete_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,22 +193,25 @@ def is_enabled(self) -> bool:
That alone cannot be used, since fish tends to always propose completions (e.g. suggesting similarly
named filenames).
"""
environ = os.environ.copy()
environ.setdefault("TERM", "xterm") # TERM has to be set for fish to load completions
return _silent_success_run(
[
self.shell_exec, '-i', '-c',
f'string length -q -- (complete -C{quote(f"{self.prog} ")} >/dev/null && complete -c {quote(self.prog)})'
]
],
env=environ,
)


def _silent_success_run(cmd: list[str], timeout: int | None = 60) -> bool:
# start_new_session prevents `zsh -i` interaction with parent terminal under pytest-xdist
def _silent_success_run(cmd: list[str], timeout: int | None = 60, env: dict | None = None) -> bool:
p = subprocess.Popen(
cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
stdin=subprocess.DEVNULL,
start_new_session=True,
start_new_session=True, # prevents `zsh -i` messing with parent tty under pytest-xdist
env=env,
)

try:
Expand Down
2 changes: 2 additions & 0 deletions test/unit/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ def env(homedir, monkeypatch):
"""Get ENV for running b2 command from shell level."""
monkeypatch.setenv("HOME", str(homedir))
monkeypatch.setenv("SHELL", "/bin/bash") # fix for running under github actions
if "TERM" not in os.environ:
monkeypatch.setenv("TERM", "xterm")
yield os.environ


Expand Down
3 changes: 0 additions & 3 deletions test/unit/console_tool/test_install_autocomplete.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ def test_install_autocomplete(b2_cli, env, shell, monkeypatch):
expected_part_of_stdout=f"Autocomplete successfully installed for {shell}",
)

if shell == "fish": # no idea how to test fish autocompletion (does not seem to work with dummy terminal)
return

with pexpect_shell(shell_bin, env=env) as pshell:
pshell.send("b2 \t\t")
pshell.expect_exact(["authorize-account", "download-file", "get-bucket"], timeout=30)

0 comments on commit 69dd411

Please sign in to comment.