@@ -266,9 +266,17 @@ 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 = (
270
+ "attribute 'normalize' of "
271
+ "'pandas._libs.tslibs.offsets.BaseOffset' objects is not writable"
272
+ )
273
+ with pytest .raises (AttributeError , match = msg ):
270
274
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 ):
272
280
offset .n = 91
273
281
274
282
def test_return_type (self , offset_types ):
@@ -2328,11 +2336,14 @@ def setup_method(self, method):
2328
2336
def test_constructor_errors (self ):
2329
2337
from datetime import time as dt_time
2330
2338
2331
- with pytest .raises (ValueError ):
2339
+ msg = "time data must be specified only with hour and minute"
2340
+ with pytest .raises (ValueError , match = msg ):
2332
2341
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 ):
2334
2344
CustomBusinessHour (start = "AAA" )
2335
- with pytest .raises (ValueError ):
2345
+ msg = "time data must match '%H:%M' format"
2346
+ with pytest .raises (ValueError , match = msg ):
2336
2347
CustomBusinessHour (start = "14:00:05" )
2337
2348
2338
2349
def test_different_normalize_equals (self ):
@@ -3195,7 +3206,7 @@ def test_repr(self):
3195
3206
assert repr (Week (n = - 2 , weekday = 0 )) == "<-2 * Weeks: weekday=0>"
3196
3207
3197
3208
def test_corner (self ):
3198
- with pytest .raises (ValueError ):
3209
+ with pytest .raises (ValueError , match = "Day must be" ):
3199
3210
Week (weekday = 7 )
3200
3211
3201
3212
with pytest .raises (ValueError , match = "Day must be" ):
@@ -4315,7 +4326,8 @@ def test_valid_month_attributes(kwd, month_classes):
4315
4326
# GH#18226
4316
4327
cls = month_classes
4317
4328
# 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 ):
4319
4331
cls (** {kwd : 3 })
4320
4332
4321
4333
@@ -4338,32 +4350,34 @@ def test_valid_tick_attributes(kwd, tick_classes):
4338
4350
# GH#18226
4339
4351
cls = tick_classes
4340
4352
# check that we cannot create e.g. Hour(weeks=3)
4341
- with pytest .raises (TypeError ):
4353
+ msg = f"__init__\\ (\\ ) got an unexpected keyword argument '{ kwd } '"
4354
+ with pytest .raises (TypeError , match = msg ):
4342
4355
cls (** {kwd : 3 })
4343
4356
4344
4357
4345
4358
def test_validate_n_error ():
4346
- with pytest .raises (TypeError ):
4359
+ with pytest .raises (TypeError , match = "argument must be an integer" ):
4347
4360
DateOffset (n = "Doh!" )
4348
4361
4349
- with pytest .raises (TypeError ):
4362
+ with pytest .raises (TypeError , match = "argument must be an integer" ):
4350
4363
MonthBegin (n = timedelta (1 ))
4351
4364
4352
- with pytest .raises (TypeError ):
4365
+ with pytest .raises (TypeError , match = "argument must be an integer" ):
4353
4366
BDay (n = np .array ([1 , 2 ], dtype = np .int64 ))
4354
4367
4355
4368
4356
4369
def test_require_integers (offset_types ):
4357
4370
cls = offset_types
4358
- with pytest .raises (ValueError ):
4371
+ with pytest .raises (ValueError , match = "argument must be an integer" ):
4359
4372
cls (n = 1.5 )
4360
4373
4361
4374
4362
4375
def test_tick_normalize_raises (tick_classes ):
4363
4376
# check that trying to create a Tick object with normalize=True raises
4364
4377
# GH#21427
4365
4378
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 ):
4367
4381
cls (n = 3 , normalize = True )
4368
4382
4369
4383
0 commit comments