@@ -218,42 +218,37 @@ def test_set_input_vars(self, model, in_dataset):
218
218
219
219
def test_update_clocks (self , model ):
220
220
ds = xr .Dataset ()
221
- with pytest .raises (ValueError ) as excinfo :
221
+ with pytest .raises (ValueError , match = "Cannot determine which clock.*" ) :
222
222
ds .xsimlab .update_clocks (model = model , clocks = {})
223
- assert "Cannot determine which clock" in str (excinfo .value )
224
223
225
224
ds = xr .Dataset ()
226
- with pytest .raises (ValueError ) as excinfo :
225
+ with pytest .raises (ValueError , match = "Cannot determine which clock.*" ) :
227
226
ds .xsimlab .update_clocks (
228
227
model = model , clocks = {"clock" : [0 , 1 , 2 ], "out" : [0 , 2 ]}
229
228
)
230
- assert "Cannot determine which clock" in str (excinfo .value )
231
229
232
230
ds = xr .Dataset ()
233
- with pytest .raises (KeyError ) as excinfo :
231
+ with pytest .raises (KeyError , match = "Master clock dimension name.*" ) :
234
232
ds .xsimlab .update_clocks (
235
233
model = model ,
236
234
clocks = {"clock" : [0 , 1 , 2 ]},
237
235
master_clock = "non_existing_clock_dim" ,
238
236
)
239
- assert "Master clock dimension name" in str (excinfo .value )
240
237
241
238
ds = xr .Dataset ()
242
- with pytest .raises (ValueError ) as excinfo :
239
+ with pytest .raises (ValueError , match = "Invalid dimension.*" ) :
243
240
ds .xsimlab .update_clocks (
244
241
model = model ,
245
242
clocks = {"clock" : ("x" , [0 , 1 , 2 ])},
246
243
)
247
- assert "Invalid dimension" in str (excinfo .value )
248
244
249
245
ds = xr .Dataset ()
250
- with pytest .raises (ValueError ) as excinfo :
246
+ with pytest .raises (ValueError , match = ".*not synchronized.*" ) :
251
247
ds .xsimlab .update_clocks (
252
248
model = model ,
253
249
clocks = {"clock" : [0 , 1 , 2 ], "out" : [0 , 0.5 , 2 ]},
254
250
master_clock = "clock" ,
255
251
)
256
- assert "not synchronized" in str (excinfo .value )
257
252
258
253
ds = xr .Dataset ()
259
254
ds = ds .xsimlab .update_clocks (model = model , clocks = {"clock" : [0 , 1 , 2 ]})
@@ -285,6 +280,10 @@ def test_update_clocks(self, model):
285
280
new_ds = ds .xsimlab .update_clocks (model = model , clocks = {"out2" : [0 , 2 ]})
286
281
assert new_ds .xsimlab .master_clock_dim == "clock"
287
282
283
+ new_ds = ds .xsimlab .update_clocks (model = model , clocks = {"clock" : [0 , 2 , 4 ]})
284
+ assert new_ds .xsimlab .master_clock_dim == "clock"
285
+ np .testing .assert_array_equal (new_ds .clock .values , [0 , 2 , 4 ])
286
+
288
287
def test_update_vars (self , model , in_dataset ):
289
288
ds = in_dataset .xsimlab .update_vars (
290
289
model = model ,
0 commit comments