mirror of
https://github.com/dredx/prole.git
synced 2026-09-27 14:14:31 +00:00
133 lines
5.0 KiB
Python
133 lines
5.0 KiB
Python
"""
|
|
Unit tests for installer/deploy.py helpers.
|
|
|
|
Covers check_xcode_tools and build_knoe_app_core error paths without
|
|
requiring a real macOS Xcode build environment.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import subprocess
|
|
from pathlib import Path
|
|
from unittest.mock import MagicMock, patch
|
|
import pytest
|
|
|
|
from knoe.deploy import check_xcode_tools, build_knoe_app_core
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# check_xcode_tools
|
|
# ---------------------------------------------------------------------------
|
|
|
|
def test_check_xcode_tools_not_darwin():
|
|
with patch("knoe.deploy.platform.system", return_value="Linux"):
|
|
assert check_xcode_tools() is False
|
|
|
|
|
|
def test_check_xcode_tools_not_darwin_windows():
|
|
with patch("knoe.deploy.platform.system", return_value="Windows"):
|
|
assert check_xcode_tools() is False
|
|
|
|
|
|
def test_check_xcode_tools_darwin_success():
|
|
mock_result = MagicMock()
|
|
mock_result.returncode = 0
|
|
with patch("knoe.deploy.platform.system", return_value="Darwin"), \
|
|
patch("knoe.deploy.subprocess.run", return_value=mock_result):
|
|
assert check_xcode_tools() is True
|
|
|
|
|
|
def test_check_xcode_tools_darwin_failure():
|
|
mock_result = MagicMock()
|
|
mock_result.returncode = 1
|
|
with patch("knoe.deploy.platform.system", return_value="Darwin"), \
|
|
patch("knoe.deploy.subprocess.run", return_value=mock_result):
|
|
assert check_xcode_tools() is False
|
|
|
|
|
|
def test_check_xcode_tools_darwin_exception():
|
|
with patch("knoe.deploy.platform.system", return_value="Darwin"), \
|
|
patch("knoe.deploy.subprocess.run", side_effect=FileNotFoundError("xcrun not found")):
|
|
assert check_xcode_tools() is False
|
|
|
|
|
|
def test_check_xcode_tools_darwin_timeout():
|
|
with patch("knoe.deploy.platform.system", return_value="Darwin"), \
|
|
patch("knoe.deploy.subprocess.run", side_effect=subprocess.TimeoutExpired("xcrun", 10)):
|
|
assert check_xcode_tools() is False
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# build_knoe_app_core — error paths
|
|
# ---------------------------------------------------------------------------
|
|
|
|
def test_build_knoe_app_core_not_darwin(tmp_path):
|
|
with patch("knoe.deploy.platform.system", return_value="Linux"):
|
|
with pytest.raises(Exception, match="macOS"):
|
|
build_knoe_app_core(tmp_path)
|
|
|
|
|
|
def test_build_knoe_app_core_no_xcode(tmp_path):
|
|
with patch("knoe.deploy.platform.system", return_value="Darwin"), \
|
|
patch("knoe.deploy.check_xcode_tools", return_value=False):
|
|
with pytest.raises(Exception, match="[Xx]code"):
|
|
build_knoe_app_core(tmp_path)
|
|
|
|
|
|
def test_build_knoe_app_core_no_build_script(tmp_path):
|
|
# xcode ok but knoe-app/build.sh missing
|
|
knoe_app = tmp_path / "knoe-app"
|
|
knoe_app.mkdir()
|
|
with patch("knoe.deploy.platform.system", return_value="Darwin"), \
|
|
patch("knoe.deploy.check_xcode_tools", return_value=True):
|
|
with pytest.raises(Exception, match="[Bb]uild script"):
|
|
build_knoe_app_core(tmp_path)
|
|
|
|
|
|
def test_build_knoe_app_core_build_fails(tmp_path):
|
|
knoe_app = tmp_path / "knoe-app"
|
|
knoe_app.mkdir()
|
|
build_sh = knoe_app / "build.sh"
|
|
build_sh.write_text("#!/bin/bash\nexit 1\n")
|
|
mock_result = MagicMock()
|
|
mock_result.returncode = 1
|
|
mock_result.stderr = "build error"
|
|
mock_result.stdout = ""
|
|
with patch("knoe.deploy.platform.system", return_value="Darwin"), \
|
|
patch("knoe.deploy.check_xcode_tools", return_value=True), \
|
|
patch("knoe.deploy.subprocess.run", return_value=mock_result):
|
|
with pytest.raises(Exception, match="[Bb]uild failed"):
|
|
build_knoe_app_core(tmp_path)
|
|
|
|
|
|
def test_build_knoe_app_core_app_missing_after_build(tmp_path):
|
|
knoe_app = tmp_path / "knoe-app"
|
|
knoe_app.mkdir()
|
|
build_sh = knoe_app / "build.sh"
|
|
build_sh.write_text("#!/bin/bash\nexit 0\n")
|
|
mock_result = MagicMock()
|
|
mock_result.returncode = 0
|
|
mock_result.stderr = ""
|
|
mock_result.stdout = "Build OK"
|
|
with patch("knoe.deploy.platform.system", return_value="Darwin"), \
|
|
patch("knoe.deploy.check_xcode_tools", return_value=True), \
|
|
patch("knoe.deploy.subprocess.run", return_value=mock_result):
|
|
# dist/Knoe.app is not created → should raise
|
|
with pytest.raises(Exception, match="[Pp]role.app"):
|
|
build_knoe_app_core(tmp_path)
|
|
|
|
|
|
def test_build_knoe_app_core_success(tmp_path):
|
|
knoe_app = tmp_path / "knoe-app"
|
|
(knoe_app / "dist").mkdir(parents=True)
|
|
app_path = knoe_app / "dist" / "Knoe.app"
|
|
app_path.mkdir()
|
|
build_sh = knoe_app / "build.sh"
|
|
build_sh.write_text("#!/bin/bash\nexit 0\n")
|
|
mock_result = MagicMock()
|
|
mock_result.returncode = 0
|
|
with patch("knoe.deploy.platform.system", return_value="Darwin"), \
|
|
patch("knoe.deploy.check_xcode_tools", return_value=True), \
|
|
patch("knoe.deploy.subprocess.run", return_value=mock_result):
|
|
result = build_knoe_app_core(tmp_path)
|
|
assert result == app_path
|