Skip to content

Commit

Permalink
Parse versions before comparing in testing
Browse files Browse the repository at this point in the history
This will ensure that the versions are parsed in a manner that will
provide correct comparison.
  • Loading branch information
mcdonnnj committed Feb 15, 2025
1 parent ddb666a commit f8e9eea
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
2 changes: 0 additions & 2 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
--requirement requirements-test.txt
ipython
pipenv
# The bump-version script requires at least version 3 of semver.
semver>=3
2 changes: 2 additions & 0 deletions requirements-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
pre-commit
pytest
python-on-whales
# The bump-version script requires at least version 3 of semver.
semver>=3
3 changes: 2 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# Third-Party Libraries
import pytest
from python_on_whales import docker
from semver import parse_version_info

MAIN_SERVICE_NAME = "guacscanner"
VERSION_SERVICE_NAME = f"{MAIN_SERVICE_NAME}-version"
Expand Down Expand Up @@ -42,7 +43,7 @@ def version_container(dockerc):
def project_version():
"""Return the version of the project."""
with open(VERSION_FILE) as f:
project_version = f.read().strip()
project_version = parse_version_info(f.read().strip())
return project_version


Expand Down
5 changes: 3 additions & 2 deletions tests/container_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

# Third-Party Libraries
import pytest
from semver import parse_version_info

RELEASE_TAG = os.getenv("RELEASE_TAG")
VERSION_FILE = "src/version.txt"
Expand Down Expand Up @@ -68,9 +69,9 @@ def test_log_version(dockerc, project_version, version_container):
"""Verify the container outputs the correct version to the logs."""
# make sure container exited if running test isolated
dockerc.wait(version_container.id)
log_output = version_container.logs().strip()
log_version = parse_version_info(version_container.logs().strip())
assert (
log_output == project_version
log_version == project_version
), f"Container version output to log does not match project version file {VERSION_FILE}"


Expand Down

0 comments on commit f8e9eea

Please sign in to comment.