Skip to content

Commit

Permalink
Add values to error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
dcamron committed Nov 14, 2023
1 parent 642ca4d commit cdcd04d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/metpy/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,22 @@ def version_check(version_spec):
module_name, comparison, version_number = _parse_version_spec(version_spec)

# Check MetPy metadata for minimum required version of same package
_, _, minimum_version_number = _parse_version_spec(_get_metadata_spec(module_name))
metadata_spec = _get_metadata_spec(module_name)
_, _, minimum_version_number = _parse_version_spec(metadata_spec)

installed_version = Version(version(module_name))
specified_version = Version(version_number)
minimum_version = Version(minimum_version_number)

if specified_version < minimum_version:
raise ValueError('Specified package version older than MetPy minimum requirement.')
raise ValueError(
f'Specified {version_spec} outdated according to MetPy minimum {metadata_spec}.')

try:
return comparison_operators[comparison](installed_version, specified_version)
except KeyError:
raise ValueError(
"Comparison operator not one of ['==', '=', '!=', '<', '<=', '>', '>=']."
f'Comparison operator {comparison} not one of {list(comparison_operators)}.'
) from None


Expand Down
4 changes: 2 additions & 2 deletions tests/test_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def test_module_version_check():

def test_module_version_check_outdated_spec():
"""Test checking test version specs against package metadata."""
with pytest.raises(ValueError, match='Specified package version '):
with pytest.raises(ValueError, match='Specified numpy'):
version_check('numpy>0.0.0')


Expand All @@ -64,5 +64,5 @@ def test_module_version_check_nonsense():

def test_module_version_check_invalid_comparison():
"""Test invalid operator in version comparison."""
with pytest.raises(ValueError, match='Comparison operator not '):
with pytest.raises(ValueError, match='Comparison operator << '):
version_check('numpy << 36')

0 comments on commit cdcd04d

Please sign in to comment.