tests/f2: make ManagedPath searchable

Change-Id: Idccf83a4471d76362153535125a269abbbb03c62
This commit is contained in:
eldritch horrors
2025-12-26 20:56:51 +00:00
parent 9ebe5acf39
commit 1546ea0d5f
2 changed files with 15 additions and 0 deletions
@@ -127,6 +127,12 @@ class _ManagedPath:
ret.append(p)
return ret
def which(self, program_name: str) -> Path:
path = shutil.which(program_name, path=self.to_path())
if not path:
raise ValueError(f"{program_name} is not in configured path")
return Path(path)
@dataclasses.dataclass
class _Dirs:
@@ -223,3 +223,12 @@ def test_path_sandbox_entire_store_package():
assert len(sb_paths) == 2
assert sb_paths[0] == "/path/to/build_shell"
assert re.fullmatch(r"^/nix/store/\w{32}-python3-3\.\d{1,2}\.\d{1,2}-[^/]+$", sb_paths[1])
def test_path_which():
path = _ManagedPath("/path/to/build_shell")
with pytest.raises(ValueError, match="not in configured path"):
path.which("pytest")
wanted = shutil.which("pytest")
path.add_program(wanted)
assert str(path.which("pytest")) == wanted