From 757126b65d083ca34485c5bbd6d2ed4c268103dc Mon Sep 17 00:00:00 2001 From: baileythegreen Date: Mon, 14 Feb 2022 06:43:11 +0000 Subject: [PATCH 1/2] Fix minor errors in tests --- tests/test_fastani.py | 6 +++--- tests/test_subcmd_09_fastani.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test_fastani.py b/tests/test_fastani.py index 05f9fa38..9da3e8cd 100644 --- a/tests/test_fastani.py +++ b/tests/test_fastani.py @@ -97,14 +97,14 @@ def test_get_version_nonetype(): # Test case 1: 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") + test_file_1 = Path("/non/existent/fastani") assert fastani.get_version(test_file_1) == f"No fastANI executable at {test_file_1}" # Test case 2: 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_2 = Path("/non/executable/fastani") assert ( fastani.get_version(test_file_2) == f"fastANI exists at {test_file_2} but not executable" @@ -114,7 +114,7 @@ def test_get_version_exe_not_executable(executable_not_executable, monkeypatch): # Test case 3: 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_3 = Path("/missing/version/fastani") assert ( fastani.get_version(test_file_3) == f"fastANI exists at {test_file_3} 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 From 72cba53a3547888dbe544d7460ba0f0275bd813f Mon Sep 17 00:00:00 2001 From: baileythegreen Date: Fri, 22 Jul 2022 16:08:54 +0100 Subject: [PATCH 2/2] Add missing `get_version()` test case --- pyani/fastani.py | 6 +++++- tests/test_fastani.py | 35 +++++++++++++++++++++++------------ 2 files changed, 28 insertions(+), 13 deletions(-) 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 9da3e8cd..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/fastani") - 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/fastani") + 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/fastani") + 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" )