Skip to content

Commit

Permalink
Shorten name
Browse files Browse the repository at this point in the history
  • Loading branch information
dcamron committed Nov 14, 2023
1 parent 2e91e15 commit 642ca4d
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/metpy/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from .units import units


def module_version_check(version_spec):
def version_check(version_spec):
"""Return comparison between the active module and a requested version number.
Will also validate specification against package metadata to alert if spec is irrelevant.
Expand Down
4 changes: 2 additions & 2 deletions tests/calc/test_indices.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
mean_pressure_weighted, precipitable_water, significant_tornado,
supercell_composite, weighted_continuous_average)
from metpy.testing import (assert_almost_equal, assert_array_almost_equal, get_upper_air_data,
module_version_check)
version_check)
from metpy.units import concatenate, units


Expand Down Expand Up @@ -131,7 +131,7 @@ def test_weighted_continuous_average():
assert_almost_equal(v, 6.900543760612305 * units('m/s'), 7)


@pytest.mark.xfail(condition=module_version_check('pint<0.21'), reason='hgrecco/pint#1593')
@pytest.mark.xfail(condition=version_check('pint<0.21'), reason='hgrecco/pint#1593')
def test_weighted_continuous_average_temperature():
"""Test pressure-weighted mean temperature function with vertical interpolation."""
data = get_upper_air_data(datetime(2016, 5, 22, 0), 'DDC')
Expand Down
9 changes: 4 additions & 5 deletions tests/calc/test_thermo.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
import warnings

import numpy as np
import packaging.version
import pytest
import scipy
import xarray as xr

from metpy.calc import (brunt_vaisala_frequency, brunt_vaisala_frequency_squared,
Expand Down Expand Up @@ -39,7 +37,8 @@
virtual_temperature, virtual_temperature_from_dewpoint,
wet_bulb_temperature)
from metpy.calc.thermo import _find_append_zero_crossings
from metpy.testing import assert_almost_equal, assert_array_almost_equal, assert_nan, module_version_check
from metpy.testing import (assert_almost_equal, assert_array_almost_equal, assert_nan,
version_check)
from metpy.units import is_quantity, masked_array, units


Expand Down Expand Up @@ -201,9 +200,9 @@ def test_moist_lapse_starting_points(start, direction):
@pytest.mark.xfail(platform.machine() == 'aarch64',
reason='ValueError is not raised on aarch64')
@pytest.mark.xfail(platform.machine() == 'arm64', reason='ValueError is not raised on Mac M2')
@pytest.mark.xfail((sys.platform == 'win32') & module_version_check('scipy<1.11.3'),
@pytest.mark.xfail((sys.platform == 'win32') & version_check('scipy<1.11.3'),
reason='solve_ivp() does not error on Windows + SciPy < 1.11.3')
@pytest.mark.xfail(module_version_check('scipy<1.7'),
@pytest.mark.xfail(version_check('scipy<1.7'),
reason='solve_ivp() does not error on Scipy < 1.7')
def test_moist_lapse_failure():
"""Test moist_lapse under conditions that cause the ODE solver to fail."""
Expand Down
6 changes: 3 additions & 3 deletions tests/plots/test_declarative.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from metpy.io.metar import parse_metar_file
from metpy.plots import (ArrowPlot, BarbPlot, ContourPlot, FilledContourPlot, ImagePlot,
MapPanel, PanelContainer, PlotGeometry, PlotObs, RasterPlot)
from metpy.testing import module_version_check, needs_cartopy
from metpy.testing import needs_cartopy, version_check
from metpy.units import units


Expand Down Expand Up @@ -336,7 +336,7 @@ def test_declarative_contour_cam():

@pytest.mark.mpl_image_compare(
remove_text=True,
tolerance=3.71 if module_version_check('matplotlib<3.8') else 0.74)
tolerance=3.71 if version_check('matplotlib<3.8') else 0.74)
@needs_cartopy
def test_declarative_contour_options():
"""Test making a contour plot."""
Expand Down Expand Up @@ -431,7 +431,7 @@ def test_declarative_additional_layers_plot_options():

@pytest.mark.mpl_image_compare(
remove_text=True,
tolerance=2.74 if module_version_check('matplotlib<3.8') else 1.91)
tolerance=2.74 if version_check('matplotlib<3.8') else 1.91)
@needs_cartopy
def test_declarative_contour_convert_units():
"""Test making a contour plot."""
Expand Down
8 changes: 4 additions & 4 deletions tests/plots/test_skewt.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import pytest

from metpy.plots import Hodograph, SkewT
from metpy.testing import module_version_check
from metpy.testing import version_check
from metpy.units import units


Expand Down Expand Up @@ -156,9 +156,9 @@ def test_skewt_units():

# On Matplotlib <= 3.6, ax[hv]line() doesn't trigger unit labels
assert skew.ax.get_xlabel() == (
'degree_Celsius' if module_version_check('matplotlib==3.7.0') else '')
'degree_Celsius' if version_check('matplotlib==3.7.0') else '')
assert skew.ax.get_ylabel() == (
'hectopascal' if module_version_check('matplotlib==3.7.0') else '')
'hectopascal' if version_check('matplotlib==3.7.0') else '')

# Clear them for the image test
skew.ax.set_xlabel('')
Expand Down Expand Up @@ -321,7 +321,7 @@ def test_hodograph_api():


@pytest.mark.mpl_image_compare(
remove_text=True, tolerance=0.6 if module_version_check('matplotlib==3.5') else 0.)
remove_text=True, tolerance=0.6 if version_check('matplotlib==3.5') else 0.)
def test_hodograph_units():
"""Test passing quantities to Hodograph."""
fig = plt.figure(figsize=(9, 9))
Expand Down
6 changes: 3 additions & 3 deletions tests/plots/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import xarray as xr

from metpy.plots import add_metpy_logo, add_timestamp, add_unidata_logo, convert_gempak_color
from metpy.testing import get_test_data, module_version_check
from metpy.testing import get_test_data, version_check


@pytest.mark.mpl_image_compare(tolerance=2.638, remove_text=True)
Expand Down Expand Up @@ -92,7 +92,7 @@ def test_add_logo_invalid_size():


@pytest.mark.mpl_image_compare(
tolerance=1.072 if module_version_check('matplotlib<3.5') else 0,
tolerance=1.072 if version_check('matplotlib<3.5') else 0,
remove_text=True)
def test_gempak_color_image_compare():
"""Test creating a plot with all the GEMPAK colors."""
Expand All @@ -113,7 +113,7 @@ def test_gempak_color_image_compare():


@pytest.mark.mpl_image_compare(
tolerance=1.215 if module_version_check('matplotlib<3.5') else 0,
tolerance=1.215 if version_check('matplotlib<3.5') else 0,
remove_text=True)
def test_gempak_color_xw_image_compare():
"""Test creating a plot with all the GEMPAK colors using xw style."""
Expand Down
10 changes: 5 additions & 5 deletions tests/test_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from metpy.deprecation import MetpyDeprecationWarning
from metpy.testing import (assert_array_almost_equal, check_and_drop_units,
check_and_silence_deprecation, module_version_check)
check_and_silence_deprecation, version_check)


# Test #1183: numpy.testing.assert_array* ignores any masked value, so work-around
Expand Down Expand Up @@ -47,22 +47,22 @@ def test_check_and_drop_units_with_dataarray():
def test_module_version_check():
"""Test parsing and version comparison of installed package."""
numpy_version = np.__version__
assert module_version_check(f'numpy >={numpy_version}')
assert version_check(f'numpy >={numpy_version}')


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


def test_module_version_check_nonsense():
"""Test failed pattern match of package specification."""
with pytest.raises(ValueError, match='No valid version '):
module_version_check('thousands of birds picking packages')
version_check('thousands of birds picking packages')


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

0 comments on commit 642ca4d

Please sign in to comment.