From 642ca4d69cc531f20fcdbe2c8476ac980b48e4ac Mon Sep 17 00:00:00 2001 From: Drew Camron Date: Mon, 13 Nov 2023 20:36:08 -0700 Subject: [PATCH] Shorten name --- src/metpy/testing.py | 2 +- tests/calc/test_indices.py | 4 ++-- tests/calc/test_thermo.py | 9 ++++----- tests/plots/test_declarative.py | 6 +++--- tests/plots/test_skewt.py | 8 ++++---- tests/plots/test_util.py | 6 +++--- tests/test_testing.py | 10 +++++----- 7 files changed, 22 insertions(+), 23 deletions(-) diff --git a/src/metpy/testing.py b/src/metpy/testing.py index 5505dab25ca..10340a3fbf3 100644 --- a/src/metpy/testing.py +++ b/src/metpy/testing.py @@ -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. diff --git a/tests/calc/test_indices.py b/tests/calc/test_indices.py index 3b03979e4a5..77c5f637d1d 100644 --- a/tests/calc/test_indices.py +++ b/tests/calc/test_indices.py @@ -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 @@ -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') diff --git a/tests/calc/test_thermo.py b/tests/calc/test_thermo.py index 42acc3b1779..450fd6229ce 100644 --- a/tests/calc/test_thermo.py +++ b/tests/calc/test_thermo.py @@ -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, @@ -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 @@ -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.""" diff --git a/tests/plots/test_declarative.py b/tests/plots/test_declarative.py index d9e3e5f1411..bacee611cdf 100644 --- a/tests/plots/test_declarative.py +++ b/tests/plots/test_declarative.py @@ -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 @@ -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.""" @@ -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.""" diff --git a/tests/plots/test_skewt.py b/tests/plots/test_skewt.py index e87be2f6ce9..433fa095491 100644 --- a/tests/plots/test_skewt.py +++ b/tests/plots/test_skewt.py @@ -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 @@ -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('') @@ -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)) diff --git a/tests/plots/test_util.py b/tests/plots/test_util.py index b33acd18287..6d77ae33ef9 100644 --- a/tests/plots/test_util.py +++ b/tests/plots/test_util.py @@ -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) @@ -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.""" @@ -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.""" diff --git a/tests/test_testing.py b/tests/test_testing.py index 28987c286a6..bf7a5cf17cd 100644 --- a/tests/test_testing.py +++ b/tests/test_testing.py @@ -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 @@ -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')