Files
EvoScientist/tests/test_updater.py
T

53 lines
1.7 KiB
Python

"""Tests for EvoScientist.updater deployment detection and plan building."""
import json
import pytest
from pathlib import Path
from EvoScientist.updater import (
DEPLOY_DOCKER,
DEPLOY_PIPX,
DEPLOY_SYSTEMD,
DEPLOY_UVTOOL,
DEPLOY_VENV,
SystemProbe,
build_install_command,
detect_deployment,
)
def _probe(**kw):
base = dict(in_container=False, invocation_id=None, uv_tool_pkg=False, pipx_pkg=False)
return SystemProbe(**{**base, **kw})
def test_docker_wins_over_systemd_marker():
assert detect_deployment(_probe(in_container=True, invocation_id="abc")) == DEPLOY_DOCKER
def test_systemd_before_cli():
assert detect_deployment(_probe(invocation_id="abc", uv_tool_pkg=True)) == DEPLOY_SYSTEMD
def test_uvtool_pipx_venv_order():
assert detect_deployment(_probe(uv_tool_pkg=True, pipx_pkg=True)) == DEPLOY_UVTOOL
assert detect_deployment(_probe(pipx_pkg=True)) == DEPLOY_PIPX
assert detect_deployment(_probe()) == DEPLOY_VENV
def test_install_commands():
artifact = Path("/tmp/updates/v1/EvoScientist-1-py3-none-any.whl")
assert build_install_command(DEPLOY_UVTOOL, artifact, "/usr/bin/python3") == [
"uv", "tool", "install", "--force", str(artifact),
]
assert build_install_command(DEPLOY_PIPX, artifact, "/usr/bin/python3") == [
"pipx", "install", "--force", str(artifact),
]
assert build_install_command(DEPLOY_VENV, artifact, "/usr/bin/python3") == [
"/usr/bin/python3", "-m", "pip", "install", "--force-reinstall", str(artifact),
]
systemd_cmd = build_install_command(DEPLOY_SYSTEMD, artifact, "/usr/bin/python3")
assert systemd_cmd[0:2] == ["uv", "tool"] or systemd_cmd[0] == "/usr/bin/python3"