Skip to content

Commit

Permalink
Make changes to tests as discussed in Issue #405
Browse files Browse the repository at this point in the history
  • Loading branch information
baileythegreen committed Jul 29, 2022
1 parent 93cc99f commit 582bdc4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 13 deletions.
9 changes: 8 additions & 1 deletion pyani/versiondb.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,20 @@ def get_version(alembic_exe: Path = pyani_config.ALEMBIC_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:
alembic_path = Path(shutil.which(alembic_exe)) # type:ignore
# Returns a TypeError if `alembic_exe` is None
try:
alembic_path = shutil.which(alembic_exe) # type:ignore
except TypeError:
return f"expected path to alembic executable; received {alembic_exe}"
# Returns a TypeError if `alembic_path` is not on the PATH
alembic_path = Path(alembic_path)
except TypeError:
return f"{alembic_exe} is not found in $PATH"

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

assert versiondb.get_version(test_file_0) == f"{test_file_0} is not found in $PATH"
assert (
versiondb.get_version(test_file_0)
== f"expected path to alembic 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 versiondb.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/alembic")
assert versiondb.get_version(test_file_1) == f"No alembic at {test_file_1}"
test_file_2 = Path("/non/existent/alembic")
assert versiondb.get_version(test_file_2) == f"No alembic 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/alembic")
test_file_3 = Path("/non/executable/alembic")
assert (
versiondb.get_version(test_file_2)
== f"alembic exists at {test_file_2} but not executable"
versiondb.get_version(test_file_3)
== f"alembic 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/alembic")
test_file_4 = Path("/missing/version/alembic")
assert (
versiondb.get_version(test_file_3)
== f"alembic exists at {test_file_3} but could not retrieve version"
versiondb.get_version(test_file_4)
== f"alembic exists at {test_file_4} but could not retrieve version"
)


Expand Down

0 comments on commit 582bdc4

Please sign in to comment.