Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue# 405: New test case for previously missed code in fastani #409

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion pyani/fastani.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,25 @@ def get_version(fastani_exe: Path = pyani_config.FASTANI_DEFAULT) -> str:

The following circumstances are explicitly reported as strings:

- a value of None given for the executable
- no executable at passed path
- non-executable file at passed path (this includes cases where the user doesn't have execute permissions on the file)
- no version info returned
"""
try:
fastani_path = Path(shutil.which(fastani_exe)) # type:ignore
# Returns a TypeError if `fastani_exe` is None
try:
fastani_path = shutil.which(fastani_exe) # type:ignore
except TypeError:
return f"expected path to fastANI executable; received {fastani_exe}"
# Returns a TypeError if `fastani_path` is not on the PATH
fastani_path = Path(fastani_path)
except TypeError:
return f"{fastani_exe} is not found in $PATH"

# If a string that is not an executable is passed to
# shutil.which(), the return value will be None, so
# this check is still needed
if fastani_path is None:
return f"{fastani_exe} is not found in $PATH"

Expand Down
35 changes: 23 additions & 12 deletions tests/test_fastani.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,33 +91,44 @@ def test_get_version_nonetype():
"""Test behaviour when no location for the executable is given."""
test_file_0 = None

assert fastani.get_version(test_file_0) == f"{test_file_0} is not found in $PATH"
assert (
fastani.get_version(test_file_0)
== f"expected path to fastANI executable; received {test_file_0}"
)


# Test case 1: no such file exists
def test_get_version_random_string():
"""Test behaviour when the given 'file' is not one."""
test_file_1 = "string"

assert fastani.get_version(test_file_1) == f"{test_file_1} is not found in $PATH"

# Test case 1: there is no executable

# Test case 2: there is no executable
def test_get_version_no_exe(executable_missing, monkeypatch):
"""Test behaviour when there is no file at the specified executable location."""
test_file_1 = Path("/non/existent/blastn")
assert fastani.get_version(test_file_1) == f"No fastANI executable at {test_file_1}"
test_file_2 = Path("/non/existent/fastani")
assert fastani.get_version(test_file_2) == f"No fastANI executable at {test_file_2}"


# Test case 2: there is a file, but it is not executable
# Test case 3: there is a file, but it is not executable
def test_get_version_exe_not_executable(executable_not_executable, monkeypatch):
"""Test behaviour when the file at the executable location is not executable."""
test_file_2 = Path("/non/executable/blastn")
test_file_3 = Path("/non/executable/fastani")
assert (
fastani.get_version(test_file_2)
== f"fastANI exists at {test_file_2} but not executable"
fastani.get_version(test_file_3)
== f"fastANI exists at {test_file_3} but not executable"
)


# Test case 3: there is an executable file, but the version can't be retrieved
# Test case 4: there is an executable file, but the version can't be retrieved
def test_get_version_exe_no_version(executable_without_version, monkeypatch):
"""Test behaviour when the version for the executable can not be retrieved."""
test_file_3 = Path("/missing/version/blastn")
test_file_4 = Path("/missing/version/fastani")
assert (
fastani.get_version(test_file_3)
== f"fastANI exists at {test_file_3} but could not retrieve version"
fastani.get_version(test_file_4)
== f"fastANI exists at {test_file_4} but could not retrieve version"
)


Expand Down
2 changes: 1 addition & 1 deletion tests/test_subcmd_09_fastani.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def setUp(self):
self.scheduler = "multiprocessing"

# Null logger instance
self.logger = logging.getLogger("TestIndexSubcommand logger")
self.logger = logging.getLogger("TestfastANISubcommand logger")
self.logger.addHandler(logging.NullHandler())

# Command line namespaces
Expand Down