Skip to content

Commit bbe1c68

Browse files
author
Rajat Bishnoi
committed
TST: insert 'match' to bare pytest raises in pandas/tests/tseries/offsets/test_offsets.py
1 parent 40b2aa5 commit bbe1c68

File tree

1 file changed

+27
-13
lines changed

1 file changed

+27
-13
lines changed

pandas/tests/tseries/offsets/test_offsets.py

+27-13
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,17 @@ class TestCommon(Base):
266266
def test_immutable(self, offset_types):
267267
# GH#21341 check that __setattr__ raises
268268
offset = self._get_offset(offset_types)
269-
with pytest.raises(AttributeError):
269+
msg = (
270+
"attribute 'normalize' of "
271+
"'pandas._libs.tslibs.offsets.BaseOffset' objects is not writable"
272+
)
273+
with pytest.raises(AttributeError, match=msg):
270274
offset.normalize = True
271-
with pytest.raises(AttributeError):
275+
msg = (
276+
"attribute 'n' of 'pandas._libs.tslibs.offsets.BaseOffset' "
277+
"objects is not writable"
278+
)
279+
with pytest.raises(AttributeError, match=msg):
272280
offset.n = 91
273281

274282
def test_return_type(self, offset_types):
@@ -2328,11 +2336,14 @@ def setup_method(self, method):
23282336
def test_constructor_errors(self):
23292337
from datetime import time as dt_time
23302338

2331-
with pytest.raises(ValueError):
2339+
msg = "time data must be specified only with hour and minute"
2340+
with pytest.raises(ValueError, match=msg):
23322341
CustomBusinessHour(start=dt_time(11, 0, 5))
2333-
with pytest.raises(ValueError):
2342+
msg = "time data must match '%H:%M' format"
2343+
with pytest.raises(ValueError, match=msg):
23342344
CustomBusinessHour(start="AAA")
2335-
with pytest.raises(ValueError):
2345+
msg = "time data must match '%H:%M' format"
2346+
with pytest.raises(ValueError, match=msg):
23362347
CustomBusinessHour(start="14:00:05")
23372348

23382349
def test_different_normalize_equals(self):
@@ -3195,7 +3206,7 @@ def test_repr(self):
31953206
assert repr(Week(n=-2, weekday=0)) == "<-2 * Weeks: weekday=0>"
31963207

31973208
def test_corner(self):
3198-
with pytest.raises(ValueError):
3209+
with pytest.raises(ValueError, match="Day must be"):
31993210
Week(weekday=7)
32003211

32013212
with pytest.raises(ValueError, match="Day must be"):
@@ -4315,7 +4326,8 @@ def test_valid_month_attributes(kwd, month_classes):
43154326
# GH#18226
43164327
cls = month_classes
43174328
# check that we cannot create e.g. MonthEnd(weeks=3)
4318-
with pytest.raises(TypeError):
4329+
msg = rf"__init__\(\) got an unexpected keyword argument '{kwd}'"
4330+
with pytest.raises(TypeError, match=msg):
43194331
cls(**{kwd: 3})
43204332

43214333

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

43444357

43454358
def test_validate_n_error():
4346-
with pytest.raises(TypeError):
4359+
with pytest.raises(TypeError, match="argument must be an integer"):
43474360
DateOffset(n="Doh!")
43484361

4349-
with pytest.raises(TypeError):
4362+
with pytest.raises(TypeError, match="argument must be an integer"):
43504363
MonthBegin(n=timedelta(1))
43514364

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

43554368

43564369
def test_require_integers(offset_types):
43574370
cls = offset_types
4358-
with pytest.raises(ValueError):
4371+
with pytest.raises(ValueError, match="argument must be an integer"):
43594372
cls(n=1.5)
43604373

43614374

43624375
def test_tick_normalize_raises(tick_classes):
43634376
# check that trying to create a Tick object with normalize=True raises
43644377
# GH#21427
43654378
cls = tick_classes
4366-
with pytest.raises(ValueError):
4379+
msg = "Tick offset with `normalize=True` are not allowed."
4380+
with pytest.raises(ValueError, match=msg):
43674381
cls(n=3, normalize=True)
43684382

43694383

0 commit comments

Comments
 (0)