43 lines
2.4 KiB
Python
43 lines
2.4 KiB
Python
import os
|
|
from pathlib import Path
|
|
import tempfile
|
|
import unittest
|
|
from unittest.mock import patch
|
|
|
|
from scripts import ci_tools
|
|
|
|
|
|
class CIToolsTests(unittest.TestCase):
|
|
def test_installed_tools_are_checked_without_downloads(self):
|
|
with tempfile.TemporaryDirectory() as temp, patch.object(ci_tools, "ROOT", Path(temp)), \
|
|
patch.dict(os.environ), patch.object(ci_tools.shutil, "which", return_value="/usr/bin/tool"), \
|
|
patch.object(ci_tools, "fetch") as fetch, patch.object(ci_tools.subprocess, "run") as run:
|
|
ci_tools.prepare()
|
|
fetch.assert_not_called()
|
|
self.assertEqual([call.args[0][0] for call in run.call_args_list], ["ffmpeg", "ffprobe", "typst"])
|
|
|
|
def test_missing_tools_are_provisioned_locally_and_typst_is_pinned(self):
|
|
with tempfile.TemporaryDirectory() as temp, patch.object(ci_tools, "ROOT", Path(temp)), \
|
|
patch.dict(os.environ), patch.object(ci_tools.shutil, "which", return_value=None), \
|
|
patch.object(ci_tools.platform, "system", return_value="Linux"), \
|
|
patch.object(ci_tools.platform, "machine", return_value="x86_64"), \
|
|
patch.object(ci_tools.subprocess, "run") as run:
|
|
binary = Path(temp) / "downloaded"
|
|
binary.write_bytes(b"fixture")
|
|
with patch.object(ci_tools, "fetch", return_value=(binary, Path(temp))) as fetch:
|
|
ci_tools.prepare()
|
|
self.assertEqual([c.kwargs["program"] for c in fetch.call_args_list], ["ffmpeg", "ffprobe"])
|
|
self.assertEqual((Path(temp) / "downloads/ci-tools/bin/ffmpeg").resolve(), binary)
|
|
install = next(c.args[0] for c in run.call_args_list if c.args[0][0] == "cargo")
|
|
self.assertIn("--locked", install)
|
|
self.assertEqual(install[install.index("--version") + 1], "0.13.1")
|
|
|
|
def test_download_failure_propagates(self):
|
|
with tempfile.TemporaryDirectory() as temp, patch.object(ci_tools, "ROOT", Path(temp)), \
|
|
patch.dict(os.environ), patch.object(ci_tools.shutil, "which", return_value=None), \
|
|
patch.object(ci_tools.platform, "system", return_value="Linux"), \
|
|
patch.object(ci_tools.platform, "machine", return_value="x86_64"), \
|
|
patch.object(ci_tools, "fetch", side_effect=ValueError("checksum mismatch")):
|
|
with self.assertRaisesRegex(ValueError, "checksum mismatch"):
|
|
ci_tools.prepare()
|