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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
import sys
import pytest # type: ignore[import-not-found]
from helpers import PIPX_METADATA_LEGACY_VERSIONS, mock_legacy_venv, run_pipx_cli, skip_if_windows
def test_reinstall(pipx_temp_env, capsys):
assert not run_pipx_cli(["install", "pycowsay"])
assert not run_pipx_cli(["reinstall", "--python", sys.executable, "pycowsay"])
@skip_if_windows
def test_reinstall_global(pipx_temp_env, capsys):
assert not run_pipx_cli(["install", "--global", "pycowsay"])
assert not run_pipx_cli(["reinstall", "--global", "--python", sys.executable, "pycowsay"])
def test_reinstall_nonexistent(pipx_temp_env, capsys):
assert run_pipx_cli(["reinstall", "--python", sys.executable, "nonexistent"])
assert "Nothing to reinstall for nonexistent" in capsys.readouterr().out
@pytest.mark.parametrize("metadata_version", PIPX_METADATA_LEGACY_VERSIONS)
def test_reinstall_legacy_venv(pipx_temp_env, capsys, metadata_version):
assert not run_pipx_cli(["install", "pycowsay"])
mock_legacy_venv("pycowsay", metadata_version=metadata_version)
assert not run_pipx_cli(["reinstall", "--python", sys.executable, "pycowsay"])
def test_reinstall_suffix(pipx_temp_env, capsys):
suffix = "_x"
assert not run_pipx_cli(["install", "pycowsay", f"--suffix={suffix}"])
assert not run_pipx_cli(["reinstall", "--python", sys.executable, f"pycowsay{suffix}"])
@pytest.mark.parametrize("metadata_version", ["0.1"])
def test_reinstall_suffix_legacy_venv(pipx_temp_env, capsys, metadata_version):
suffix = "_x"
assert not run_pipx_cli(["install", "pycowsay", f"--suffix={suffix}"])
mock_legacy_venv(f"pycowsay{suffix}", metadata_version=metadata_version)
assert not run_pipx_cli(["reinstall", "--python", sys.executable, f"pycowsay{suffix}"])
def test_reinstall_specifier(pipx_temp_env, capsys):
assert not run_pipx_cli(["install", "pylint==3.0.4"])
# clear capsys before reinstall
captured = capsys.readouterr()
assert not run_pipx_cli(["reinstall", "--python", sys.executable, "pylint"])
captured = capsys.readouterr()
assert "installed package pylint 3.0.4" in captured.out
def test_reinstall_with_path(pipx_temp_env, capsys, tmp_path):
path = tmp_path / "some" / "path"
assert run_pipx_cli(["reinstall", str(path)])
captured = capsys.readouterr()
assert "Expected the name of an installed package" in captured.err.replace("\n", " ")
assert run_pipx_cli(["reinstall", str(path.resolve())])
captured = capsys.readouterr()
assert "Expected the name of an installed package" in captured.err.replace("\n", " ")
def test_reinstall_pinned_package(pipx_temp_env, capsys):
assert not run_pipx_cli(["install", "black"])
assert not run_pipx_cli(["pin", "black"])
assert run_pipx_cli(["reinstall", "black"])
captured = capsys.readouterr()
assert "pinned" in captured.err
assert not run_pipx_cli(["unpin", "black"])
assert not run_pipx_cli(["reinstall", "black"])
captured = capsys.readouterr()
assert "installed package black" in captured.out
|