From 8272a02dc5d29b0597db787adaf541469cfc1efa Mon Sep 17 00:00:00 2001 From: Ryan May Date: Tue, 6 Oct 2020 23:26:07 -0600 Subject: [PATCH] TST: Add some tests for warnings in xarray handling --- tests/test_xarray.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/test_xarray.py b/tests/test_xarray.py index 162a80268ed..0ef261b2b31 100644 --- a/tests/test_xarray.py +++ b/tests/test_xarray.py @@ -248,6 +248,30 @@ def test_missing_grid_mapping_var(caplog): assert 'Could not find' in caplog.text +def test_parsecf_crs(): + """Test calling `parse_cf` with the metpy_crs variable.""" + ds = xr.Dataset({'metpy_crs': xr.DataArray(1)}) + + with pytest.warns(UserWarning, match='Attempting to parse metpy_crs'): + ds.metpy.parse_cf('metpy_crs') + + +def test_parsecf_existing_scalar_crs(): + """Test calling `parse_cf` on a variable with an existing scalar metpy_crs coordinate.""" + ds = xr.Dataset({'data': xr.DataArray(1, coords=dict(metpy_crs=1))}) + + with pytest.warns(UserWarning, match='metpy_crs already present'): + ds.metpy.parse_cf('data') + + +def test_parsecf_existing_vector_crs(): + """Test calling `parse_cf` on a variable with an existing vector metpy_crs coordinate.""" + ds = xr.Dataset({'data': xr.DataArray(1, dims=('metpy_crs',), coords=(np.ones(3),))}) + + with pytest.warns(UserWarning, match='metpy_crs already present'): + ds.metpy.parse_cf('data') + + def test_preprocess_and_wrap_only_preprocessing(): """Test xarray preprocessing and wrapping decorator for only preprocessing.""" data = xr.DataArray(np.ones(3), attrs={'units': 'km'})