Skip to content

Commit

Permalink
refactor: use tmp path instead of /usr/bin
Browse files Browse the repository at this point in the history
  • Loading branch information
msto committed Sep 19, 2024
1 parent 122cb80 commit 3adfd3e
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions tests/util/test_executable_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,24 @@ def test_validate_executable_path_not_executable() -> None:
ExecutableRunner.validate_executable_path(executable=tmpfile.name)


@pytest.mark.parametrize("executable", ["yes", "/usr/bin/yes", Path("/usr/bin/yes")])
def test_validate_executable_path(executable: str | Path) -> None:
def test_validate_executable_path(tmp_path: Path) -> None:
"""
`validate_executable_path` should return the `yes` executable in the following scenarios:
1. When the name of the executable is passed as a string.
2. When the absolute path to the executable is passed, either as a string or a Path.
"""
expected_path: Path = Path("/usr/bin/yes")
expected_path = tmp_path / "yes"
expected_path.touch() # create the file
expected_path.chmod(755) # make it executable

# Clear the PATH, in case the user has a local version of `yes` elsewhere on their PATH
with mock.patch.dict(os.environ, clear=True):
os.environ["PATH"] = "/usr/bin"
os.environ["PATH"] = str(tmp_path)

validated_path: Path = ExecutableRunner.validate_executable_path(executable=executable)
assert validated_path == expected_path
executables: list[str | Path] = ["yes", expected_path, str(expected_path)]
for executable in executables:
validated_path: Path = ExecutableRunner.validate_executable_path(executable=executable)
assert validated_path == expected_path


def test_validate_executable_path_rejects_paths() -> None:
Expand Down

0 comments on commit 3adfd3e

Please sign in to comment.