Files
devx/tests/unit/test_install_checkmake.py
T
emil 55c530eb00
Post-merge / detect-type (push) Successful in 8s
Post-merge / validate-commit-msg (push) Successful in 9s
Post-merge / vikunja (push) Successful in 11s
Post-merge / configure-repo (push) Successful in 9s
Post-merge / sync-wiki (push) Successful in 18s
Post-merge / release (push) Successful in 25s
Post-merge / badges (push) Successful in 28s
Build Images / detect-type (push) Successful in 41s
Post-merge / publish (push) Successful in 15s
Build Images / build-and-push (push) Successful in 3m1s
Build Images / cleanup (push) Successful in 2m25s
DEVX-93: fix: force pip upgrade in setup-image to install new dependencies
2026-06-28 12:14:31 +00:00

105 lines
3.7 KiB
Python

from __future__ import annotations
import platform
from pathlib import Path
from unittest.mock import patch
import pytest
from click import ClickException
import devx.tools.install_checkmake as install_checkmake
from devx.tools._shared import arch_string
class TestArchString:
def test_amd64(self) -> None:
with patch.object(platform, "machine", return_value="x86_64"):
assert arch_string() == "amd64"
def test_arm64(self) -> None:
with patch.object(platform, "machine", return_value="aarch64"):
assert arch_string() == "arm64"
def test_unsupported(self) -> None:
with patch.object(platform, "machine", return_value="riscv64"):
with pytest.raises(ClickException):
arch_string()
class TestInstallWithGo:
def test_no_go(self) -> None:
with patch("shutil.which", return_value=None):
assert install_checkmake._install_with_go() is False
def test_with_go(self) -> None:
with patch("shutil.which", return_value="/usr/bin/go"):
with patch("subprocess.run") as mock_run:
assert install_checkmake._install_with_go() is True
mock_run.assert_called_once_with(
[
"/usr/bin/go",
"install",
"github.com/checkmake/checkmake/cmd/checkmake@latest",
],
check=True,
)
class TestDownloadBinary:
def test_download(self, tmp_path: Path) -> None:
target = tmp_path / "checkmake"
def _write_file(url: str, path: str) -> tuple[str, None]:
Path(path).write_bytes(b"binary")
return path, None
with patch.object(install_checkmake, "TARGET_PATH", target):
with patch.object(platform, "machine", return_value="x86_64"):
with patch("urllib.request.urlretrieve", side_effect=_write_file) as mock_retrieve:
install_checkmake._download_binary()
mock_retrieve.assert_called_once()
assert target.exists()
assert target.stat().st_mode & 0o111
class TestMain:
def test_already_installed(self) -> None:
from click.testing import CliRunner
with patch("shutil.which", return_value="/usr/bin/checkmake"):
runner = CliRunner()
runner.invoke(install_checkmake.cli, [])
def test_install_with_go(self) -> None:
from click.testing import CliRunner
with patch("shutil.which", side_effect=[None, "/usr/bin/go"]):
with patch("subprocess.run") as mock_run:
runner = CliRunner()
runner.invoke(install_checkmake.cli, [])
mock_run.assert_called_once_with(
[
"/usr/bin/go",
"install",
"github.com/checkmake/checkmake/cmd/checkmake@latest",
],
check=True,
)
def test_download_when_no_go(self, tmp_path: Path) -> None:
from click.testing import CliRunner
target = tmp_path / "checkmake"
def _write_file(url: str, path: str) -> tuple[str, None]:
Path(path).write_bytes(b"binary")
return path, None
with patch.object(install_checkmake, "TARGET_PATH", target):
with patch("shutil.which", side_effect=[None, None]):
with patch.object(platform, "machine", return_value="x86_64"):
with patch("urllib.request.urlretrieve", side_effect=_write_file) as mock_retrieve:
runner = CliRunner()
runner.invoke(install_checkmake.cli, [])
mock_retrieve.assert_called_once()