diff --git a/pyani/fastani.py b/pyani/fastani.py index 4039c9a1..8bad236e 100644 --- a/pyani/fastani.py +++ b/pyani/fastani.py @@ -92,9 +92,13 @@ def get_version(fastani_exe: Path = pyani_config.FASTANI_DEFAULT) -> str: """ try: fastani_path = Path(shutil.which(fastani_exe)) # type:ignore + # Returns a TypeError if `fastani_exe` is None except TypeError: - return f"{fastani_exe} is not found in $PATH" + return f"expected file location; received {fastani_exe}" + # 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" diff --git a/tests/test_fastani.py b/tests/test_fastani.py index 05f9fa38..3bf821ff 100644 --- a/tests/test_fastani.py +++ b/tests/test_fastani.py @@ -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 file location; 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" ) diff --git a/tests/test_subcmd_09_fastani.py b/tests/test_subcmd_09_fastani.py index 6fa29e9d..e016a01c 100644 --- a/tests/test_subcmd_09_fastani.py +++ b/tests/test_subcmd_09_fastani.py @@ -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