forked from IQ.Lvbs/IQ.Pilot
67 lines
2.0 KiB
Python
67 lines
2.0 KiB
Python
# Copyright © IQ.Lvbs, apart of Project Teal Lvbs, All Rights Reserved, licensed under https://konn3kt.com/tos
|
|
|
|
import os
|
|
from pathlib import Path
|
|
import subprocess
|
|
|
|
|
|
IQ_COMMAND = Path(__file__).parents[1] / "iq.sh"
|
|
|
|
|
|
def make_checkout(tmp_path: Path) -> Path:
|
|
checkout = tmp_path / "checkout"
|
|
(checkout / "iqpilot").mkdir(parents=True)
|
|
(checkout / "launch_iqpilot.sh").touch()
|
|
return checkout
|
|
|
|
|
|
def run_pkg(checkout: Path, path: Path) -> subprocess.CompletedProcess[str]:
|
|
env = os.environ.copy()
|
|
env["PATH"] = f"{path}:{env['PATH']}"
|
|
return subprocess.run(
|
|
["bash", str(IQ_COMMAND), "--dir", str(checkout), "pkg"],
|
|
check=False,
|
|
capture_output=True,
|
|
env=env,
|
|
text=True,
|
|
)
|
|
|
|
|
|
def test_public_checkout_skips_private_package_source_setup(tmp_path: Path):
|
|
checkout = make_checkout(tmp_path)
|
|
|
|
result = run_pkg(checkout, tmp_path)
|
|
|
|
assert result.returncode == 0
|
|
assert "private package sources are not present" in result.stdout
|
|
assert "setup_private_packages.py" not in result.stderr
|
|
|
|
|
|
def test_internal_checkout_runs_private_package_source_setup(tmp_path: Path):
|
|
checkout = make_checkout(tmp_path)
|
|
setup_script = checkout / "iqpilot/tools/scripts/setup_private_packages.py"
|
|
setup_script.parent.mkdir(parents=True)
|
|
setup_script.touch()
|
|
python_log = tmp_path / "python.log"
|
|
python = tmp_path / "python3"
|
|
python.write_text(f"#!/usr/bin/env bash\nprintf '%s\\n' \"$*\" > {python_log!s}\n")
|
|
python.chmod(0o755)
|
|
|
|
result = run_pkg(checkout, tmp_path)
|
|
|
|
assert result.returncode == 0
|
|
assert python_log.read_text().strip() == "iqpilot/tools/scripts/setup_private_packages.py"
|
|
|
|
|
|
def test_public_checkout_runs_bundled_package_installer(tmp_path: Path):
|
|
checkout = make_checkout(tmp_path)
|
|
installer_log = tmp_path / "installer.log"
|
|
installer = checkout / "artifacts/runtime/ensure_private_installed.sh"
|
|
installer.parent.mkdir(parents=True)
|
|
installer.write_text(f"printf installed > {installer_log!s}\n")
|
|
|
|
result = run_pkg(checkout, tmp_path)
|
|
|
|
assert result.returncode == 0
|
|
assert installer_log.read_text() == "installed"
|