def _check_fails_in_metadata(self, automatic_fixes=False, frequency=None): checker = CMORCheck(self.cube, self.var_info, automatic_fixes=automatic_fixes, frequency=frequency) with self.assertRaises(CMORCheckError): checker.check_metadata()
def test_warning_fail_on_error(self): """Test report warning function with fail_on_error.""" checker = CMORCheck(self.cube, self.var_info, fail_on_error=True) with self.assertLogs(level='WARNING') as cm: checker.report_warning('New error: {}', 'something failed') self.assertEqual(cm.output, [ 'WARNING:esmvalcore.cmor.check:New error: something failed', ])
def _check_warnings_on_metadata(self, automatic_fixes=False, check_level=CheckLevels.DEFAULT): checker = CMORCheck( self.cube, self.var_info, automatic_fixes=automatic_fixes, check_level=check_level ) checker.check_metadata() self.assertTrue(checker.has_warnings())
def test_warning_fail_on_error(self): """Test report warning function with fail_on_error""" checker = CMORCheck(self.cube, self.var_info, fail_on_error=True) stdout = sys.stdout sys.stdout = StringIO() checker.report_warning('New error: {}', 'something failed') output = sys.stdout.getvalue().strip() sys.stdout = stdout self.assertEqual(output, 'WARNING: New error: something failed')
def _check_fails_in_metadata(self, automatic_fixes=False, frequency=None, check_level=CheckLevels.DEFAULT): checker = CMORCheck( self.cube, self.var_info, automatic_fixes=automatic_fixes, frequency=frequency, check_level=check_level) with self.assertRaises(CMORCheckError): checker.check_metadata()
def test_non_requested(self): """ Warning if requested values are not present. Check issue a warning if a values requested for a coordinate are not correct in the metadata step """ coord = self.cube.coord('air_pressure') values = np.linspace(0, 40, len(coord.points)) self._update_coordinate_values(self.cube, coord, values) checker = CMORCheck(self.cube, self.var_info) checker.check_metadata() self.assertTrue(checker.has_warnings())
def checker(cube): return CMORCheck( cube, self.var_info, automatic_fixes=automatic_fixes, frequency=frequency, check_level=check_level)
def test_fail_on_error(self): """Test exception is raised if fail_on_error is activated.""" checker = CMORCheck(self.cube, self.var_info, fail_on_error=True) with self.assertRaises(CMORCheckError): checker.report_critical('New error: {}', 'something failed')
def _check_warnings_on_data(self): checker = CMORCheck(self.cube, self.var_info) checker.check_metadata() checker.check_data() self.assertTrue(checker.has_warnings())
def _check_fails_on_data(self): checker = CMORCheck(self.cube, self.var_info) checker.check_metadata() with self.assertRaises(CMORCheckError): checker.check_data()
def test_report_error(self): """Test report error function.""" checker = CMORCheck(self.cube, self.var_info) self.assertFalse(checker.has_errors()) checker.report_critical('New error: {}', 'something failed') self.assertTrue(checker.has_errors())
def _check_debug_messages_on_metadata(self, automatic_fixes=False): checker = CMORCheck(self.cube, self.var_info, automatic_fixes=automatic_fixes) checker.check_metadata() self.assertTrue(checker.has_debug_messages())
def test_report_debug_message(self): """"Test report debug message function""" checker = CMORCheck(self.cube, self.var_info) self.assertFalse(checker.has_debug_messages()) checker.report_debug_message('New debug message') self.assertTrue(checker.has_debug_messages())
def test_report_warning(self): """Test report warning function""" checker = CMORCheck(self.cube, self.var_info) self.assertFalse(checker.has_errors()) checker.report_warning('New error: {}', 'something failed') self.assertTrue(checker.has_warnings())
def _check_debug_messages_on_metadata(self): checker = CMORCheck(self.cube, self.var_info) checker.check_metadata() self.assertTrue(checker.has_debug_messages())