@@ -226,17 +226,48 @@ def test_horizontal_grid_is_close(cube2_spec: dict, expected: bool):
226226 assert _horizontal_grid_is_close (cube1 , cube2 ) == expected
227227
228228
229- def test_regrid_is_skipped_if_grids_are_the_same ( ):
229+ def test_regrid_is_skipped_if_grids_are_the_same_dim_coord ( mocker ):
230230 """Test that regridding is skipped if the grids are the same."""
231+ mock_get_regridder = mocker .patch (
232+ "esmvalcore.preprocessor._regrid._get_regridder" , autospec = True
233+ )
234+ cube = _make_cube (lat = LAT_SPEC1 , lon = LON_SPEC1 )
235+
236+ expected_same_cube = regrid (cube , target_grid = "10x10" , scheme = "linear" )
237+
238+ mock_get_regridder .assert_not_called ()
239+ np .testing .assert_equal (expected_same_cube .shape , cube .shape )
240+ assert cube .coords ("latitude" , dim_coords = True )
241+ assert cube .coords ("longitude" , dim_coords = True )
242+
243+
244+ def test_regrid_is_skipped_if_grids_are_the_same_aux_coord (mocker ):
245+ """Test that regridding is skipped if the grids are the same."""
246+ mock_get_regridder = mocker .patch (
247+ "esmvalcore.preprocessor._regrid._get_regridder" , autospec = True
248+ )
249+ cube = _make_cube (lat = LAT_SPEC1 , lon = LON_SPEC1 )
250+ lat = cube .coord ("latitude" )
251+ lon = cube .coord ("longitude" )
252+ cube .remove_coord (lat )
253+ cube .remove_coord (lon )
254+ cube .add_aux_coord (lat , 0 )
255+ cube .add_aux_coord (lon , 1 )
256+
257+ expected_same_cube = regrid (cube , target_grid = "10x10" , scheme = "linear" )
258+
259+ mock_get_regridder .assert_not_called ()
260+ np .testing .assert_equal (expected_same_cube .shape , cube .shape )
261+ assert cube .coords ("latitude" , dim_coords = False )
262+ assert cube .coords ("longitude" , dim_coords = False )
263+
264+
265+ def test_regrid_is_not_skipped_if_grids_are_different ():
266+ """Test that regridding is not skipped if the grids are different."""
231267 cube = _make_cube (lat = LAT_SPEC1 , lon = LON_SPEC1 )
232- scheme = "linear"
233268
234- # regridding to the same spec returns the same cube
235- expected_same_cube = regrid (cube , target_grid = "10x10" , scheme = scheme )
236- assert expected_same_cube == cube
269+ expected_different_cube = regrid (cube , target_grid = "5x5" , scheme = "linear" )
237270
238- # regridding to a different spec returns a different cube
239- expected_different_cube = regrid (cube , target_grid = "5x5" , scheme = scheme )
240271 assert expected_different_cube is not cube
241272
242273
0 commit comments