-
Notifications
You must be signed in to change notification settings - Fork 527
Expand file tree
/
Copy pathtest_shared_libs.py
More file actions
53 lines (37 loc) · 1.72 KB
/
test_shared_libs.py
File metadata and controls
53 lines (37 loc) · 1.72 KB
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
import os
import time
import pytest # type: ignore[import-not-found]
from pipx import shared_libs
@pytest.mark.parametrize(
"mtime_minus_now,needs_upgrade",
[
(-shared_libs.SHARED_LIBS_MAX_AGE_SEC - 5 * 60, True),
(-shared_libs.SHARED_LIBS_MAX_AGE_SEC + 5 * 60, False),
],
)
def test_auto_update_shared_libs(capsys, pipx_ultra_temp_env, mtime_minus_now, needs_upgrade):
now = time.time()
shared_libs.shared_libs.create(verbose=True, pip_args=[])
shared_libs.shared_libs.has_been_updated_this_run = False
access_time = now # this can be anything
os.utime(shared_libs.shared_libs.pip_path, (access_time, mtime_minus_now + now))
assert shared_libs.shared_libs.needs_upgrade is needs_upgrade
def test_disable_auto_upgrade_env_var(capsys, pipx_ultra_temp_env, monkeypatch):
"""Test that PIPX_DISABLE_SHARED_LIBS_AUTO_UPGRADE prevents automatic upgrades."""
# Set the environment variable
monkeypatch.setenv("PIPX_DISABLE_SHARED_LIBS_AUTO_UPGRADE", "1")
# Reimport to pick up the new environment variable value
from importlib import reload
import pipx.constants
reload(pipx.constants)
# Verify the constant is set
from pipx.constants import DISABLE_SHARED_LIBS_AUTO_UPGRADE
assert DISABLE_SHARED_LIBS_AUTO_UPGRADE == "1"
# Install a package which normally triggers auto-upgrade
from helpers import run_pipx_cli
assert run_pipx_cli(["install", "pycowsay"]) == 0
# Verify shared libs were NOT automatically upgraded during install
# by checking the logs/output
capsys.readouterr()
# Note: The exact assertion may need adjustment based on actual output
# The key is that we should NOT see upgrade messages when env var is set