def test_nofix(self): """Check that the same cube is returned if no fix is available.""" with mock.patch( 'esmvalcore.cmor._fixes.fix.Fix.get_fixes', return_value=[]): cube_returned = fix_data(self.cube, 'short_name', 'project', 'model') self.assertTrue(cube_returned is self.cube) self.assertTrue(cube_returned is not self.fixed_cube)
def test_fix(self): """Check that the returned fix is applied.""" with mock.patch( 'esmvalcore.cmor._fixes.fix.Fix.get_fixes', return_value=[self.mock_fix]): cube_returned = fix_data(self.cube, 'short_name', 'project', 'model') self.assertTrue(cube_returned is not self.cube) self.assertTrue(cube_returned is self.fixed_cube)
def test_cmor_checker_called(self): """Check that the cmor check is done""" checker = mock.Mock() checker.return_value = mock.Mock() with mock.patch( 'esmvalcore.cmor._fixes.fix.Fix.get_fixes', return_value=[]): with mock.patch( 'esmvalcore.cmor.fix._get_cmor_checker', return_value=checker) as get_mock: fix_data(self.cube, 'short_name', 'project', 'model', 'cmor_table', 'mip', 'frequency') get_mock.assert_called_once_with( automatic_fixes=True, fail_on_error=False, frequency='frequency', mip='mip', short_name='short_name', table='cmor_table') checker.assert_called_once_with(self.cube) checker.return_value.check_data.assert_called_once_with()
def test_cmor_checker_called(self): """Check that the cmor check is done.""" checker = Mock() checker.return_value = Mock() with patch('esmvalcore.cmor._fixes.fix.Fix.get_fixes', return_value=[]): with patch('esmvalcore.cmor.fix._get_cmor_checker', return_value=checker) as get_mock: fix_data(self.cube, 'short_name', 'CMIP6', 'model', 'mip', 'frequency') get_mock.assert_called_once_with( table='CMIP6', automatic_fixes=True, check_level=CheckLevels.DEFAULT, fail_on_error=False, frequency='frequency', mip='mip', short_name='short_name', ) checker.assert_called_once_with(self.cube) checker.return_value.check_data.assert_called_once_with()
def run_fix_data(cube: iris.cube.Cube, variable: typing.Dict, **kwargs) -> iris.cube.Cube: short_name = variable["short_name"] project = variable["project"] dataset = variable["dataset"] mip = variable["mip"] cubes = fix_data(cube, short_name=short_name, project=project, dataset=dataset, mip=mip) return cubes
def _load_fx(fx_info, check_level): """Load and CMOR-check fx variables.""" fx_cubes = iris.cube.CubeList() for fx_file in fx_info['filename']: loaded_cube = load(fx_file, callback=concatenate_callback) short_name = fx_info['short_name'] project = fx_info['project'] dataset = fx_info['dataset'] mip = fx_info['mip'] freq = fx_info['frequency'] loaded_cube = fix_metadata(loaded_cube, short_name=short_name, project=project, dataset=dataset, mip=mip, frequency=freq, check_level=check_level) fx_cubes.append(loaded_cube[0]) fx_cube = concatenate(fx_cubes) fx_cube = cmor_check_metadata(fx_cube, cmor_table=project, mip=mip, short_name=short_name, frequency=freq, check_level=check_level) fx_cube = fix_data(fx_cube, short_name=short_name, project=project, dataset=dataset, mip=mip, frequency=freq, check_level=check_level) fx_cube = cmor_check_data(fx_cube, cmor_table=project, mip=mip, short_name=fx_cube.var_name, frequency=freq, check_level=check_level) return fx_cube
def test_nofix(self): """Check that the same cube is returned if no fix is available.""" self.check_data.side_effect = lambda: self.cube with patch('esmvalcore.cmor._fixes.fix.Fix.get_fixes', return_value=[]): with patch('esmvalcore.cmor.fix._get_cmor_checker', return_value=self.checker): cube_returned = fix_data( self.cube, short_name='short_name', project='CMIP6', dataset='model', mip='mip', ) self.checker.assert_called_once_with(self.cube) self.check_data.assert_called_once_with() assert cube_returned is self.cube assert cube_returned is not self.intermediate_cube assert cube_returned is not self.fixed_cube