Skip to content

Fix test suite use of str(exception) #3059

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,9 @@ Bug fixes
By `Maximilian Roos <https://github.com/max-sixty>`_.
- Fixed performance issues with cftime installed (:issue:`3000`)
By `0x0L <https://github.com/0x0L>`_.
- Replace incorrect usages of `message` in pytest assertions
with `match` (:issue:`3011`)
By `Maximilian Roos <https://github.com/max-sixty>`_.
- Add explicit pytest markers, now required by pytest
(:issue:`3032`).
By `Maximilian Roos <https://github.com/max-sixty>`_.
- Test suite fixes for newer versions of pytest (:issue:`3011`, :issue:`3032`).
By `Maximilian Roos <https://github.com/max-sixty>`_
and `Stephan Hoyer <https://github.com/shoyer>`_.

.. _whats-new.0.12.1:

Expand Down
11 changes: 5 additions & 6 deletions xarray/tests/test_dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -3710,15 +3710,14 @@ def test_rolling_properties(da):
assert rolling_obj.obj.get_axis_num('time') == 1

# catching invalid args
with pytest.raises(ValueError) as exception:
with pytest.raises(ValueError, match='exactly one dim/window should'):
da.rolling(time=7, x=2)
assert 'exactly one dim/window should' in str(exception)
with pytest.raises(ValueError) as exception:
with pytest.raises(ValueError, match='window must be > 0'):
da.rolling(time=-2)
assert 'window must be > 0' in str(exception)
with pytest.raises(ValueError) as exception:
with pytest.raises(
ValueError, match='min_periods must be greater than zero'
):
da.rolling(time=2, min_periods=0)
assert 'min_periods must be greater than zero' in str(exception)


@pytest.mark.parametrize('name', ('sum', 'mean', 'std', 'min', 'max',
Expand Down
14 changes: 6 additions & 8 deletions xarray/tests/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -4788,18 +4788,16 @@ def test_coarsen_coords_cftime():

def test_rolling_properties(ds):
# catching invalid args
with pytest.raises(ValueError) as exception:
with pytest.raises(ValueError, match='exactly one dim/window should'):
ds.rolling(time=7, x=2)
assert 'exactly one dim/window should' in str(exception)
with pytest.raises(ValueError) as exception:
with pytest.raises(ValueError, match='window must be > 0'):
ds.rolling(time=-2)
assert 'window must be > 0' in str(exception)
with pytest.raises(ValueError) as exception:
with pytest.raises(
ValueError, match='min_periods must be greater than zero'
):
ds.rolling(time=2, min_periods=0)
assert 'min_periods must be greater than zero' in str(exception)
with pytest.raises(KeyError) as exception:
with pytest.raises(KeyError, match='time2'):
ds.rolling(time2=2)
assert 'time2' in str(exception)


@pytest.mark.parametrize('name',
Expand Down