@@ -266,9 +266,10 @@ class TestCommon(Base):
266
266
def test_immutable (self , offset_types ):
267
267
# GH#21341 check that __setattr__ raises
268
268
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 ):
270
271
offset .normalize = True
271
- with pytest .raises (AttributeError ):
272
+ with pytest .raises (AttributeError , match = msg ):
272
273
offset .n = 91
273
274
274
275
def test_return_type (self , offset_types ):
@@ -2328,11 +2329,14 @@ def setup_method(self, method):
2328
2329
def test_constructor_errors (self ):
2329
2330
from datetime import time as dt_time
2330
2331
2331
- with pytest .raises (ValueError ):
2332
+ msg = "time data must be specified only with hour and minute"
2333
+ with pytest .raises (ValueError , match = msg ):
2332
2334
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 ):
2334
2337
CustomBusinessHour (start = "AAA" )
2335
- with pytest .raises (ValueError ):
2338
+ msg = "time data must match '%H:%M' format"
2339
+ with pytest .raises (ValueError , match = msg ):
2336
2340
CustomBusinessHour (start = "14:00:05" )
2337
2341
2338
2342
def test_different_normalize_equals (self ):
@@ -3195,7 +3199,7 @@ def test_repr(self):
3195
3199
assert repr (Week (n = - 2 , weekday = 0 )) == "<-2 * Weeks: weekday=0>"
3196
3200
3197
3201
def test_corner (self ):
3198
- with pytest .raises (ValueError ):
3202
+ with pytest .raises (ValueError , match = "Day must be" ):
3199
3203
Week (weekday = 7 )
3200
3204
3201
3205
with pytest .raises (ValueError , match = "Day must be" ):
@@ -4315,7 +4319,8 @@ def test_valid_month_attributes(kwd, month_classes):
4315
4319
# GH#18226
4316
4320
cls = month_classes
4317
4321
# 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 ):
4319
4324
cls (** {kwd : 3 })
4320
4325
4321
4326
@@ -4338,32 +4343,34 @@ def test_valid_tick_attributes(kwd, tick_classes):
4338
4343
# GH#18226
4339
4344
cls = tick_classes
4340
4345
# 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 ):
4342
4348
cls (** {kwd : 3 })
4343
4349
4344
4350
4345
4351
def test_validate_n_error ():
4346
- with pytest .raises (TypeError ):
4352
+ with pytest .raises (TypeError , match = "argument must be an integer" ):
4347
4353
DateOffset (n = "Doh!" )
4348
4354
4349
- with pytest .raises (TypeError ):
4355
+ with pytest .raises (TypeError , match = "argument must be an integer" ):
4350
4356
MonthBegin (n = timedelta (1 ))
4351
4357
4352
- with pytest .raises (TypeError ):
4358
+ with pytest .raises (TypeError , match = "argument must be an integer" ):
4353
4359
BDay (n = np .array ([1 , 2 ], dtype = np .int64 ))
4354
4360
4355
4361
4356
4362
def test_require_integers (offset_types ):
4357
4363
cls = offset_types
4358
- with pytest .raises (ValueError ):
4364
+ with pytest .raises (ValueError , match = "argument must be an integer" ):
4359
4365
cls (n = 1.5 )
4360
4366
4361
4367
4362
4368
def test_tick_normalize_raises (tick_classes ):
4363
4369
# check that trying to create a Tick object with normalize=True raises
4364
4370
# GH#21427
4365
4371
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 ):
4367
4374
cls (n = 3 , normalize = True )
4368
4375
4369
4376
0 commit comments