-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: version message, add test for version #191
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
cfd8b2f
fix: version message, add test for version
axif0 9108b61
rename version test file
axif0 6ee057e
rename update to Upgrade
axif0 e5e1bfd
fix test message
axif0 dcf61cf
Merge branch 'main' into testing
andrewtavis 5a02908
Minor formatting and fixing usage of renamed function
andrewtavis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
""" | ||
Tests for the CLI version functionality. | ||
|
||
.. raw:: html | ||
<!-- | ||
* Copyright (C) 2024 Scribe | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
--> | ||
""" | ||
|
||
import unittest | ||
from unittest.mock import patch | ||
|
||
import pkg_resources | ||
from scribe_data.cli.version import ( | ||
get_latest_version, | ||
get_local_version, | ||
get_version_message, | ||
) | ||
|
||
|
||
class TestVersionFunctions(unittest.TestCase): | ||
@patch("pkg_resources.get_distribution") | ||
def test_get_local_version_installed(self, mock_get_distribution): | ||
mock_get_distribution.return_value.version = "1.0.0" | ||
self.assertEqual(get_local_version(), "1.0.0") | ||
|
||
@patch( | ||
"pkg_resources.get_distribution", side_effect=pkg_resources.DistributionNotFound | ||
) | ||
def test_get_local_version_not_installed(self, mock_get_distribution): | ||
self.assertEqual(get_local_version(), "Unknown (Not installed via pip)") | ||
|
||
@patch("requests.get") | ||
def test_get_latest_version(self, mock_get): | ||
mock_get.return_value.status_code = 200 | ||
mock_get.return_value.json.return_value = {"name": "v1.0.1"} | ||
self.assertEqual(get_latest_version(), "v1.0.1") | ||
|
||
@patch("requests.get", side_effect=Exception("Unable to fetch version")) | ||
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_latest_version", return_value="Scribe-Data v1.0.0" | ||
) | ||
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" | ||
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_latest_version", return_value="Scribe-Data v1.0.1" | ||
) | ||
def test_get_version_message_update_available( | ||
self, mock_latest_version, mock_local_version | ||
): | ||
""" | ||
Tests the scenario where a newer version is available, suggesting an update. | ||
""" | ||
expected_message = "Scribe-Data v1.0.0 (Upgrade available: Scribe-Data v1.0.1)\nTo update: pip scribe-data --upgrade" | ||
self.assertEqual(get_version_message(), expected_message) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very minor thing here that is more a personal thing for me, @axif0, I added the periods here as Python standards state that comments that are their own line should have a period at the end (and should also start with a capitalized work - they're full sentences). For inline comments it's best to not capitalize the first word and not end in a period :)
For next time! 😊