Skip to content

Commit

Permalink
fix: test
Browse files Browse the repository at this point in the history
  • Loading branch information
msto committed Sep 18, 2024
1 parent 34faeab commit 5212328
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions tests/util/test_executable_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,11 @@ 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:
@pytest.mark.parametrize("executable", ["/usr/bin/yes", Path("/usr/bin/yes")])
def test_validate_executable_path_returns_existing_paths(executable: str | Path) -> None:
"""
`validate_executable_path` should find the `yes` executable in the following scenarios:
1. when the string "yes" is passed
2. when the absolute path to the `yes` executable is passed, either as a string or a Path
`validate_executable_path` should return the `yes` executable when the absolute path to the
executable is passed, either as a string or a Path.
"""
expected_path: Path = Path("/usr/bin/yes")

Expand All @@ -47,6 +46,18 @@ def test_validate_executable_path(executable: str | Path) -> None:
assert validated_path == expected_path


def test_validate_executable_finds_on_path() -> None:
"""
`validate_executable_path` should find executables on the PATH when the name of the executable
is passed as a string.
"""
expected_path: Path = Path("/usr/bin/yes")

with mock.patch("shutil.which", return_value=expected_path.as_posix()):
validated_path: Path = ExecutableRunner.validate_executable_path(executable="yes")
assert validated_path == expected_path


def test_validate_executable_path_rejects_paths() -> None:
"""
`validate_executable_path` should not treat non-existent Path objects as valid executables.
Expand Down

0 comments on commit 5212328

Please sign in to comment.