File: test_install_autocomplete.py

package info (click to toggle)
backblaze-b2 3.19.1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,372 kB
  • sloc: python: 12,571; makefile: 21; sh: 12
file content (42 lines) | stat: -rw-r--r-- 1,264 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
######################################################################
#
# File: test/unit/console_tool/test_install_autocomplete.py
#
# Copyright 2024 Backblaze Inc. All Rights Reserved.
#
# License https://www.backblaze.com/using_b2_code.html
#
######################################################################

import contextlib
import shutil
from test.helpers import skip_on_windows

import pexpect
import pytest


@contextlib.contextmanager
def pexpect_shell(shell_bin, env):
    p = pexpect.spawn(f"{shell_bin} -i", env=env, maxread=1000)
    p.setwinsize(100, 100)  # required to see all suggestions in tests
    yield p
    p.close()


@pytest.mark.parametrize("shell", ["bash", "zsh", "fish"])
@skip_on_windows
def test_install_autocomplete(b2_cli, env, shell, monkeypatch):
    shell_bin = shutil.which(shell)
    if shell_bin is None:
        pytest.skip(f"{shell} is not installed")

    monkeypatch.setenv("SHELL", shell_bin)
    b2_cli.run(
        ["install-autocomplete"],
        expected_part_of_stdout=f"Autocomplete successfully installed for {shell}",
    )

    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)