diff --git a/tests/offline/test_cargo_test_runners.py b/tests/offline/test_cargo_test_runners.py index cff97e16..8a2b9113 100644 --- a/tests/offline/test_cargo_test_runners.py +++ b/tests/offline/test_cargo_test_runners.py @@ -40,8 +40,16 @@ class CargoTestRunnersTest(unittest.TestCase): 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__": diff --git a/tools/test_gpu_acr_bootstrap.py b/tools/test_gpu_acr_bootstrap.py index cde01b20..bc16e4e9 100644 --- a/tools/test_gpu_acr_bootstrap.py +++ b/tools/test_gpu_acr_bootstrap.py @@ -16,13 +16,17 @@ def find_cargo() -> str: which = shutil.which('cargo') if which: return which - candidates = [] - if os.environ.get('CARGO_HOME'): - candidates.append(Path(os.environ['CARGO_HOME']) / 'bin/cargo') - candidates.append(Path.home() / '.cargo/bin/cargo') - for candidate in candidates: + cargo_home = os.environ.get('CARGO_HOME') + if cargo_home: + candidate = Path(cargo_home) / 'bin/cargo' if candidate.is_file() and os.access(candidate, os.X_OK): return str(candidate) + try: + home_cargo = Path.home() / '.cargo/bin/cargo' + except RuntimeError: + home_cargo = None + if home_cargo is not None and home_cargo.is_file() and os.access(home_cargo, os.X_OK): + return str(home_cargo) raise SystemExit('cargo not found; set CARGO, CARGO_HOME, or add cargo to PATH') diff --git a/tools/test_gpu_falcon_boot_parent.py b/tools/test_gpu_falcon_boot_parent.py index cb63c760..ce5a9bf8 100644 --- a/tools/test_gpu_falcon_boot_parent.py +++ b/tools/test_gpu_falcon_boot_parent.py @@ -16,13 +16,17 @@ def find_cargo() -> str: which = shutil.which('cargo') if which: return which - candidates = [] - if os.environ.get('CARGO_HOME'): - candidates.append(Path(os.environ['CARGO_HOME']) / 'bin/cargo') - candidates.append(Path.home() / '.cargo/bin/cargo') - for candidate in candidates: + cargo_home = os.environ.get('CARGO_HOME') + if cargo_home: + candidate = Path(cargo_home) / 'bin/cargo' if candidate.is_file() and os.access(candidate, os.X_OK): return str(candidate) + try: + home_cargo = Path.home() / '.cargo/bin/cargo' + except RuntimeError: + home_cargo = None + if home_cargo is not None and home_cargo.is_file() and os.access(home_cargo, os.X_OK): + return str(home_cargo) raise SystemExit('cargo not found; set CARGO, CARGO_HOME, or add cargo to PATH') diff --git a/tools/test_gpu_wpr_shadow.py b/tools/test_gpu_wpr_shadow.py index b59a9268..b107ddd1 100644 --- a/tools/test_gpu_wpr_shadow.py +++ b/tools/test_gpu_wpr_shadow.py @@ -16,13 +16,17 @@ def find_cargo() -> str: which = shutil.which('cargo') if which: return which - candidates = [] - if os.environ.get('CARGO_HOME'): - candidates.append(Path(os.environ['CARGO_HOME']) / 'bin/cargo') - candidates.append(Path.home() / '.cargo/bin/cargo') - for candidate in candidates: + cargo_home = os.environ.get('CARGO_HOME') + if cargo_home: + candidate = Path(cargo_home) / 'bin/cargo' if candidate.is_file() and os.access(candidate, os.X_OK): return str(candidate) + try: + home_cargo = Path.home() / '.cargo/bin/cargo' + except RuntimeError: + home_cargo = None + if home_cargo is not None and home_cargo.is_file() and os.access(home_cargo, os.X_OK): + return str(home_cargo) raise SystemExit('cargo not found; set CARGO, CARGO_HOME, or add cargo to PATH')