@@ -907,11 +907,13 @@ def test_invalid_dataarray_names_raise(self):
907
907
ve = (ValueError , "string must be length 1 or" )
908
908
data = np .random .random ((2 , 2 ))
909
909
da = xr .DataArray (data )
910
- for name , e in zip ([0 , (4 , 5 ), True , "" ], [te , te , te , ve ]):
910
+ for name , ( error , msg ) in zip ([0 , (4 , 5 ), True , "" ], [te , te , te , ve ]):
911
911
ds = Dataset ({name : da })
912
- with raises_regex ( * e ) :
912
+ with pytest . raises ( error ) as excinfo :
913
913
with self .roundtrip (ds ):
914
914
pass
915
+ excinfo .match (msg )
916
+ excinfo .match (repr (name ))
915
917
916
918
def test_encoding_kwarg (self ):
917
919
ds = Dataset ({"x" : ("y" , np .arange (10.0 ))})
@@ -4307,17 +4309,17 @@ def new_dataset_and_coord_attrs():
4307
4309
ds , attrs = new_dataset_and_attrs ()
4308
4310
4309
4311
attrs [123 ] = "test"
4310
- with raises_regex (TypeError , "Invalid name for attr" ):
4312
+ with raises_regex (TypeError , "Invalid name for attr: 123 " ):
4311
4313
ds .to_netcdf ("test.nc" )
4312
4314
4313
4315
ds , attrs = new_dataset_and_attrs ()
4314
4316
attrs [MiscObject ()] = "test"
4315
- with raises_regex (TypeError , "Invalid name for attr" ):
4317
+ with raises_regex (TypeError , "Invalid name for attr: " ):
4316
4318
ds .to_netcdf ("test.nc" )
4317
4319
4318
4320
ds , attrs = new_dataset_and_attrs ()
4319
4321
attrs ["" ] = "test"
4320
- with raises_regex (ValueError , "Invalid name for attr" ):
4322
+ with raises_regex (ValueError , "Invalid name for attr '': " ):
4321
4323
ds .to_netcdf ("test.nc" )
4322
4324
4323
4325
# This one should work
@@ -4328,12 +4330,12 @@ def new_dataset_and_coord_attrs():
4328
4330
4329
4331
ds , attrs = new_dataset_and_attrs ()
4330
4332
attrs ["test" ] = {"a" : 5 }
4331
- with raises_regex (TypeError , "Invalid value for attr" ):
4333
+ with raises_regex (TypeError , "Invalid value for attr 'test' " ):
4332
4334
ds .to_netcdf ("test.nc" )
4333
4335
4334
4336
ds , attrs = new_dataset_and_attrs ()
4335
4337
attrs ["test" ] = MiscObject ()
4336
- with raises_regex (TypeError , "Invalid value for attr" ):
4338
+ with raises_regex (TypeError , "Invalid value for attr 'test' " ):
4337
4339
ds .to_netcdf ("test.nc" )
4338
4340
4339
4341
ds , attrs = new_dataset_and_attrs ()
0 commit comments