From 1546ea0d5f84f96c9da56f054816bdc62bbb3c52 Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Mon, 22 Dec 2025 23:31:06 +0100 Subject: [PATCH] tests/f2: make ManagedPath searchable Change-Id: Idccf83a4471d76362153535125a269abbbb03c62 --- tests/functional2/testlib/fixtures/env.py | 6 ++++++ tests/functional2/testlib/fixtures/test_env.py | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/tests/functional2/testlib/fixtures/env.py b/tests/functional2/testlib/fixtures/env.py index a8d8b2d66..b560f28fa 100644 --- a/tests/functional2/testlib/fixtures/env.py +++ b/tests/functional2/testlib/fixtures/env.py @@ -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: diff --git a/tests/functional2/testlib/fixtures/test_env.py b/tests/functional2/testlib/fixtures/test_env.py index 192afb1a2..2ea19d689 100644 --- a/tests/functional2/testlib/fixtures/test_env.py +++ b/tests/functional2/testlib/fixtures/test_env.py @@ -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