Skip to content

TST: insert 'match' to bare pytest raises in pandas/tests/tseries/off… #36865

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
Oct 11, 2020
Merged
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
33 changes: 20 additions & 13 deletions pandas/tests/tseries/offsets/test_offsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,10 @@ class TestCommon(Base):
def test_immutable(self, offset_types):
# GH#21341 check that __setattr__ raises
offset = self._get_offset(offset_types)
with pytest.raises(AttributeError):
msg = "objects is not writable|DateOffset objects are immutable"
with pytest.raises(AttributeError, match=msg):
offset.normalize = True
with pytest.raises(AttributeError):
with pytest.raises(AttributeError, match=msg):
offset.n = 91

def test_return_type(self, offset_types):
Expand Down Expand Up @@ -2328,11 +2329,14 @@ def setup_method(self, method):
def test_constructor_errors(self):
from datetime import time as dt_time

with pytest.raises(ValueError):
msg = "time data must be specified only with hour and minute"
with pytest.raises(ValueError, match=msg):
CustomBusinessHour(start=dt_time(11, 0, 5))
with pytest.raises(ValueError):
msg = "time data must match '%H:%M' format"
with pytest.raises(ValueError, match=msg):
CustomBusinessHour(start="AAA")
with pytest.raises(ValueError):
msg = "time data must match '%H:%M' format"
with pytest.raises(ValueError, match=msg):
CustomBusinessHour(start="14:00:05")

def test_different_normalize_equals(self):
Expand Down Expand Up @@ -3195,7 +3199,7 @@ def test_repr(self):
assert repr(Week(n=-2, weekday=0)) == "<-2 * Weeks: weekday=0>"

def test_corner(self):
with pytest.raises(ValueError):
with pytest.raises(ValueError, match="Day must be"):
Week(weekday=7)

with pytest.raises(ValueError, match="Day must be"):
Expand Down Expand Up @@ -4315,7 +4319,8 @@ def test_valid_month_attributes(kwd, month_classes):
# GH#18226
cls = month_classes
# check that we cannot create e.g. MonthEnd(weeks=3)
with pytest.raises(TypeError):
msg = rf"__init__\(\) got an unexpected keyword argument '{kwd}'"
with pytest.raises(TypeError, match=msg):
cls(**{kwd: 3})


Expand All @@ -4338,32 +4343,34 @@ def test_valid_tick_attributes(kwd, tick_classes):
# GH#18226
cls = tick_classes
# check that we cannot create e.g. Hour(weeks=3)
with pytest.raises(TypeError):
msg = rf"__init__\(\) got an unexpected keyword argument '{kwd}'"
with pytest.raises(TypeError, match=msg):
cls(**{kwd: 3})


def test_validate_n_error():
with pytest.raises(TypeError):
with pytest.raises(TypeError, match="argument must be an integer"):
DateOffset(n="Doh!")

with pytest.raises(TypeError):
with pytest.raises(TypeError, match="argument must be an integer"):
MonthBegin(n=timedelta(1))

with pytest.raises(TypeError):
with pytest.raises(TypeError, match="argument must be an integer"):
BDay(n=np.array([1, 2], dtype=np.int64))


def test_require_integers(offset_types):
cls = offset_types
with pytest.raises(ValueError):
with pytest.raises(ValueError, match="argument must be an integer"):
cls(n=1.5)


def test_tick_normalize_raises(tick_classes):
# check that trying to create a Tick object with normalize=True raises
# GH#21427
cls = tick_classes
with pytest.raises(ValueError):
msg = "Tick offset with `normalize=True` are not allowed."
with pytest.raises(ValueError, match=msg):
cls(n=3, normalize=True)


Expand Down