Skip to content

Commit

Permalink
TST: Add some tests for warnings in xarray handling
Browse files Browse the repository at this point in the history
  • Loading branch information
dopplershift committed Oct 7, 2020
1 parent 588784c commit 8272a02
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tests/test_xarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'})
Expand Down

0 comments on commit 8272a02

Please sign in to comment.