Skip to content

Commit

Permalink
better error text when no version was found
Browse files Browse the repository at this point in the history
Fixes #76
  • Loading branch information
peterbe committed Sep 27, 2018
1 parent d682470 commit 2fcb0df
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
4 changes: 2 additions & 2 deletions hashin.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,11 @@ def get_latest_version(data, include_prereleases):
count_prereleases += 1
all_versions.sort(reverse=True)
if not all_versions:
msg = "Not a single valid version found."
msg = "No valid version found."
if not include_prereleases and count_prereleases:
msg += (
" But, found {0} pre-releases. Consider running again "
"with the --include-prereleases flag."
"with the --include-prereleases flag.".format(count_prereleases)
)
raise NoVersionsError(msg)
# return the highest non-pre-release version
Expand Down
36 changes: 20 additions & 16 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,23 +99,27 @@ def test_get_latest_version_non_pre_release(self, murlopen):

@mock.patch('hashin.urlopen')
def test_get_latest_version_only_pre_release(self, murlopen):
self.assertRaises(
hashin.NoVersionsError,
hashin.get_latest_version,
{
'info': {
'version': '0.3',
with self.assertRaises(hashin.NoVersionsError) as cm:
hashin.get_latest_version(
{
'info': {
'version': '0.3',
},
'releases': {
'1.1.0rc1': {},
'1.1rc1': {},
'1.0a1': {},
'2.0b2': {},
'2.0c3': {},
}
},
'releases': {
'1.1.0rc1': {},
'1.1rc1': {},
'1.0a1': {},
'2.0b2': {},
'2.0c3': {},
}
},
False,
)
False
)
exception = cm.exception
self.assertEqual(str(exception), (
"No valid version found. But, found 5 pre-releases. "
"Consider running again with the --include-prereleases flag."
))

version = hashin.get_latest_version({
'info': {
Expand Down

0 comments on commit 2fcb0df

Please sign in to comment.