Skip to content

Commit ed6b7ef

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

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

pandas/tests/tseries/offsets/test_offsets.py

+20-13
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,10 @@ 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 = "objects is not writable|DateOffset objects are immutable"
270+
with pytest.raises(AttributeError, match=msg):
270271
offset.normalize = True
271-
with pytest.raises(AttributeError):
272+
with pytest.raises(AttributeError, match=msg):
272273
offset.n = 91
273274

274275
def test_return_type(self, offset_types):
@@ -2328,11 +2329,14 @@ def setup_method(self, method):
23282329
def test_constructor_errors(self):
23292330
from datetime import time as dt_time
23302331

2331-
with pytest.raises(ValueError):
2332+
msg = "time data must be specified only with hour and minute"
2333+
with pytest.raises(ValueError, match=msg):
23322334
CustomBusinessHour(start=dt_time(11, 0, 5))
2333-
with pytest.raises(ValueError):
2335+
msg = "time data must match '%H:%M' format"
2336+
with pytest.raises(ValueError, match=msg):
23342337
CustomBusinessHour(start="AAA")
2335-
with pytest.raises(ValueError):
2338+
msg = "time data must match '%H:%M' format"
2339+
with pytest.raises(ValueError, match=msg):
23362340
CustomBusinessHour(start="14:00:05")
23372341

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

31973201
def test_corner(self):
3198-
with pytest.raises(ValueError):
3202+
with pytest.raises(ValueError, match="Day must be"):
31993203
Week(weekday=7)
32003204

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

43214326

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

43444350

43454351
def test_validate_n_error():
4346-
with pytest.raises(TypeError):
4352+
with pytest.raises(TypeError, match="argument must be an integer"):
43474353
DateOffset(n="Doh!")
43484354

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

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

43554361

43564362
def test_require_integers(offset_types):
43574363
cls = offset_types
4358-
with pytest.raises(ValueError):
4364+
with pytest.raises(ValueError, match="argument must be an integer"):
43594365
cls(n=1.5)
43604366

43614367

43624368
def test_tick_normalize_raises(tick_classes):
43634369
# check that trying to create a Tick object with normalize=True raises
43644370
# GH#21427
43654371
cls = tick_classes
4366-
with pytest.raises(ValueError):
4372+
msg = "Tick offset with `normalize=True` are not allowed."
4373+
with pytest.raises(ValueError, match=msg):
43674374
cls(n=3, normalize=True)
43684375

43694376

0 commit comments

Comments
 (0)