mirror of
https://github.com/QuixiAI/nvdriver.git
synced 2026-12-06 06:28:39 +00:00
57 lines
2.1 KiB
Python
57 lines
2.1 KiB
Python
#!/usr/bin/env python3
|
|
"""Offline tests for portable Cargo discovery and import safety in
|
|
test_gpu_acr_bootstrap, test_gpu_falcon_boot_parent, and test_gpu_wpr_shadow.
|
|
"""
|
|
import importlib.util
|
|
import os
|
|
from pathlib import Path
|
|
import shutil
|
|
import tempfile
|
|
import unittest
|
|
from unittest import mock
|
|
|
|
ROOT = Path(__file__).resolve().parents[2]
|
|
|
|
|
|
def _load(name: str, rel: str):
|
|
spec = importlib.util.spec_from_file_location(name, ROOT / rel)
|
|
mod = importlib.util.module_from_spec(spec)
|
|
assert spec.loader is not None
|
|
spec.loader.exec_module(mod)
|
|
return mod
|
|
|
|
|
|
class CargoTestRunnersTest(unittest.TestCase):
|
|
def test_python_runners_are_import_safe_and_resolve_cargo_portably(self):
|
|
for rel in (
|
|
"tools/test_gpu_acr_bootstrap.py",
|
|
"tools/test_gpu_falcon_boot_parent.py",
|
|
"tools/test_gpu_wpr_shadow.py",
|
|
):
|
|
mod = _load(Path(rel).stem, rel)
|
|
self.assertTrue(callable(mod.main))
|
|
with mock.patch.dict(os.environ, {"CARGO": "/custom/cargo"}, clear=True):
|
|
self.assertEqual(mod.find_cargo(), "/custom/cargo")
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
fake = Path(tmp) / "bin/cargo"
|
|
fake.parent.mkdir(parents=True)
|
|
fake.write_text("", encoding="utf-8")
|
|
fake.chmod(0o755)
|
|
with (
|
|
mock.patch.dict(os.environ, {"CARGO_HOME": tmp}, clear=True),
|
|
mock.patch.object(shutil, "which", return_value=None),
|
|
mock.patch.object(Path, "home", side_effect=RuntimeError("no home")),
|
|
):
|
|
self.assertEqual(mod.find_cargo(), str(fake))
|
|
with (
|
|
mock.patch.dict(os.environ, {}, clear=True),
|
|
mock.patch.object(shutil, "which", return_value=None),
|
|
mock.patch.object(Path, "home", side_effect=RuntimeError("no home")),
|
|
):
|
|
with self.assertRaises(SystemExit):
|
|
mod.find_cargo()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|