Debian Codegraph @

test/unit/console_tool/test_install_autocomplete.py

raw
1 ######################################################################
2 #
3 # File: test/unit/console_tool/test_install_autocomplete.py
4 #
5 # Copyright 2024 Backblaze Inc. All Rights Reserved.
6 #
7 # License https://www.backblaze.com/using_b2_code.html
8 #
9 ######################################################################
10
11 import contextlib
12 import shutil
13 from test.helpers import skip_on_windows
14
15 import pexpect
16 import pytest
17
18
19 @contextlib.contextmanager
20 def pexpect_shell(shell_bin, env):
21 p = pexpect.spawn(f"{shell_bin} -i", env=env, maxread=1000)
22 p.setwinsize(100, 100) # required to see all suggestions in tests
23 yield p
24 p.close()
25
26
27 @pytest.mark.parametrize("shell", ["bash", "zsh", "fish"])
28 @skip_on_windows
29 def test_install_autocomplete(b2_cli, env, shell, monkeypatch):
30 shell_bin = shutil.which(shell)
31 if shell_bin is None:
32 pytest.skip(f"{shell} is not installed")
33
34 monkeypatch.setenv("SHELL", shell_bin)
35 b2_cli.run(
36 ["install-autocomplete"],
37 expected_part_of_stdout=f"Autocomplete successfully installed for {shell}",
38 )
39
40 with pexpect_shell(shell_bin, env=env) as pshell:
41 pshell.send("b2 \t\t")
42 pshell.expect_exact(["authorize-account", "download-file", "get-bucket"], timeout=30)