Public Access
Post-merge / detect-type (push) Failing after 9s
Post-merge / validate-commit-msg (push) Has been skipped
Post-merge / release (push) Has been skipped
Post-merge / sync-wiki (push) Has been skipped
Post-merge / vikunja (push) Has been skipped
Post-merge / configure-repo (push) Has been skipped
Post-merge / badges (push) Failing after 25s
Port core modules (config, exceptions, i18n, api_clients, gitea_cli), 14 CI scripts, 6 dev tools, 5 molecule tools, CLI entry point, workflows, Makefile, tests (784 tests, 100% coverage), and documentation from GRM. The devx package is published to the Gitea PyPI registry and consumed by GRM, infra, and other oblachno-oss projects as a pip dependency. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
95 lines
3.4 KiB
Python
95 lines
3.4 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
|
|
|
|
|
|
class TestArch:
|
|
def test_amd64(self) -> None:
|
|
with patch.object(platform, "machine", return_value="x86_64"):
|
|
assert install_checkmake._arch() == "amd64"
|
|
|
|
def test_arm64(self) -> None:
|
|
with patch.object(platform, "machine", return_value="aarch64"):
|
|
assert install_checkmake._arch() == "arm64"
|
|
|
|
def test_unsupported(self) -> None:
|
|
with patch.object(platform, "machine", return_value="riscv64"):
|
|
with pytest.raises(ClickException):
|
|
install_checkmake._arch()
|
|
|
|
|
|
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:
|
|
with patch("shutil.which", return_value="/usr/bin/checkmake"):
|
|
install_checkmake.main()
|
|
|
|
def test_install_with_go(self) -> None:
|
|
with patch("shutil.which", side_effect=[None, "/usr/bin/go"]):
|
|
with patch("subprocess.run") as mock_run:
|
|
install_checkmake.main()
|
|
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:
|
|
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:
|
|
install_checkmake.main()
|
|
mock_retrieve.assert_called_once()
|