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
|
import sys
from unittest import mock
import pytest # type: ignore[import-not-found]
from helpers import run_pipx_cli
from pipx import main
def test_help_text(monkeypatch, capsys):
mock_exit = mock.Mock(side_effect=ValueError("raised in test to exit early"))
with mock.patch.object(sys, "exit", mock_exit), pytest.raises(ValueError, match="raised in test to exit early"):
assert not run_pipx_cli(["--help"])
captured = capsys.readouterr()
assert "usage: pipx" in captured.out
def test_version(monkeypatch, capsys):
mock_exit = mock.Mock(side_effect=ValueError("raised in test to exit early"))
with mock.patch.object(sys, "exit", mock_exit), pytest.raises(ValueError, match="raised in test to exit early"):
assert not run_pipx_cli(["--version"])
captured = capsys.readouterr()
mock_exit.assert_called_with(0)
assert main.__version__ in captured.out.strip()
@pytest.mark.parametrize(
("argv", "executable", "expected"),
[
("/usr/bin/pipx", "", "pipx"),
("__main__.py", "/usr/bin/python", "/usr/bin/python -m pipx"),
],
)
def test_prog_name(monkeypatch, argv, executable, expected):
monkeypatch.setattr("pipx.main.sys.argv", [argv])
monkeypatch.setattr("pipx.main.sys.executable", executable)
assert main.prog_name() == expected
def test_limit_verbosity():
assert not run_pipx_cli(["list", "-qqq"])
assert not run_pipx_cli(["list", "-vvvv"])
|