Skip to content

Commit

Permalink
Merge pull request #535 from harikrishnatp/version_fetch_issue
Browse files Browse the repository at this point in the history
Fix version comparison bug in get_version_message() due to prefix inconsistencies
  • Loading branch information
andrewtavis authored Dec 28, 2024
2 parents f9a1d91 + 92bbbbd commit 64d1c31
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 21 deletions.
21 changes: 10 additions & 11 deletions src/scribe_data/cli/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,18 @@ def get_latest_version():


def get_version_message():
local_version = f"Scribe-Data v{get_local_version()}"
local_version = get_local_version()
latest_version = get_latest_version()

if (
local_version == "Unknown (Not installed via pip)"
or latest_version == "Unknown (Unable to fetch version)"
):
return f"{local_version}"
if local_version == "Unknown (Not installed via pip)":
return f"Scribe-Data {local_version}"
elif latest_version == "Unknown (Unable to fetch version)":
return f"Scribe-Data {latest_version}"

if local_version == latest_version:
return f"{local_version}"
local_version_clean = local_version.strip()
latest_version_clean = latest_version.replace("Scribe-Data", "").strip()

update_message = f"{local_version} (Upgrade available: {latest_version})\n"
update_message += "To update: pip scribe-data --upgrade"
if local_version_clean == latest_version_clean:
return f"Scribe-Data v{local_version_clean}"

return update_message
return f"Scribe-Data v{local_version_clean} (Upgrade available: Scribe-Data v{latest_version_clean})\nTo update: pip install --upgrade scribe-data"
47 changes: 37 additions & 10 deletions tests/cli/test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,28 +53,55 @@ def test_get_latest_version(self, mock_get):
def test_get_latest_version_failure(self, mock_get):
self.assertEqual(get_latest_version(), "Unknown (Unable to fetch version)")

@patch("scribe_data.cli.version.get_local_version", return_value="1.0.0")
@patch("scribe_data.cli.version.get_local_version", return_value="X.Y.Z")
@patch(
"scribe_data.cli.version.get_latest_version", return_value="Scribe-Data v1.0.0"
"scribe_data.cli.version.get_latest_version", return_value="Scribe-Data X.Y.Z"
)
def test_get_version_message_up_to_date(
self, mock_latest_version, mock_local_version
):
"""
Tests the scenario where the local version is up to date with the latest version.
"""
expected_message = "Scribe-Data v1.0.0"
expected_message = "Scribe-Data vX.Y.Z"
self.assertEqual(get_version_message(), expected_message)

@patch("scribe_data.cli.version.get_local_version", return_value="1.0.0")
@patch("scribe_data.cli.version.get_local_version", return_value="X.Y.Y")
@patch(
"scribe_data.cli.version.get_latest_version", return_value="Scribe-Data v1.0.1"
"scribe_data.cli.version.get_latest_version", return_value="Scribe-Data X.Y.Z"
)
def test_get_version_message_update_available(
self, mock_latest_version, mock_local_version
):
def test_upgrade_available(self, mock_latest_version, mock_local_version):
"""
Test case where a newer version is available.
"""
expected_message = (
"Scribe-Data vX.Y.Y (Upgrade available: Scribe-Data vX.Y.Z)\n"
"To update: pip install --upgrade scribe-data"
)
self.assertEqual(get_version_message(), expected_message)

@patch(
"scribe_data.cli.version.get_local_version",
return_value="Unknown (Not installed via pip)",
)
@patch(
"scribe_data.cli.version.get_latest_version", return_value="Scribe-Data X.Y.Z"
)
def test_local_version_unknown(self, mock_latest_version, mock_local_version):
"""
Test case where the local version is unknown.
"""
expected_message = "Scribe-Data Unknown (Not installed via pip)"
self.assertEqual(get_version_message(), expected_message)

@patch("scribe_data.cli.version.get_local_version", return_value="X.Y.Z")
@patch(
"scribe_data.cli.version.get_latest_version",
return_value="Unknown (Unable to fetch version)",
)
def test_latest_version_unknown(self, mock_latest_version, mock_local_version):
"""
Tests the scenario where a newer version is available, suggesting an update.
Test case where the latest version cannot be fetched.
"""
expected_message = "Scribe-Data v1.0.0 (Upgrade available: Scribe-Data v1.0.1)\nTo update: pip scribe-data --upgrade"
expected_message = "Scribe-Data Unknown (Unable to fetch version)"
self.assertEqual(get_version_message(), expected_message)

0 comments on commit 64d1c31

Please sign in to comment.