| 1 | import importlib.util |
| 2 | import os |
| 3 | import subprocess |
| 4 | from pathlib import Path |
| 5 | import unittest |
| 6 | from unittest.mock import patch |
| 7 | |
| 8 | ROOT = Path(__file__).resolve().parents[2] |
| 9 | SPEC = importlib.util.spec_from_file_location( |
| 10 | "native_smoke", ROOT / "tests/rust-app-ui/native_smoke.py" |
| 11 | ) |
| 12 | SMOKE = importlib.util.module_from_spec(SPEC) |
| 13 | SPEC.loader.exec_module(SMOKE) |
| 14 | |
| 15 | |
| 16 | class NativeSmokePathsTests(unittest.TestCase): |
| 17 | def test_default_binary_uses_common_work_target(self): |
| 18 | common = Path(subprocess.check_output( |
| 19 | ["git", "rev-parse", "--path-format=absolute", "--git-common-dir"], |
| 20 | cwd=ROOT, text=True, |
| 21 | ).strip()).resolve() |
| 22 | expected = common.parent / "tests/work/rust-local" |
| 23 | with patch.dict(os.environ): |
| 24 | os.environ.pop("ZIPELO_CI_JOB", None) |
| 25 | os.environ.pop("CARGO_TARGET_DIR", None) |
| 26 | work = SMOKE.work_directory() |
| 27 | self.assertEqual(work, expected) |
| 28 | self.assertEqual(SMOKE.binary_path(work), |
| 29 | work / "target/debug/zipelo-ui-memory-app") |
| 30 | |
| 31 | def test_job_and_target_overrides_are_honored(self): |
| 32 | work = SMOKE.work_directory().parent / "native-smoke-paths" |
| 33 | target = work / "custom-target" |
| 34 | with patch.dict(os.environ, {"ZIPELO_CI_JOB": "native-smoke-paths", |
| 35 | "CARGO_TARGET_DIR": str(target)}): |
| 36 | self.assertEqual(SMOKE.work_directory(), work) |
| 37 | self.assertEqual(SMOKE.binary_path(work), |
| 38 | target / "debug/zipelo-ui-memory-app") |
| 39 | |
| 40 | |
| 41 | if __name__ == "__main__": |
| 42 | unittest.main() |