def test_no_exception_raised(self): mock_logger = mock.Mock(spec_set=logging.Logger) with MbedToolsHandler(mock_logger, traceback=False): pass self.assertFalse( mock_logger.error.called, "Error should not be logger when an exception is not raised.")
def test_other_exceptions(self): mock_logger = mock.Mock(spec_set=logging.Logger) with self.assertRaises(ValueError): with MbedToolsHandler(mock_logger, traceback=False): raise ValueError(self.exception_string) self.assertFalse( mock_logger.error.called, "Error should not be logger when a tools error is not raised.")
def invoke(self, context: click.Context) -> None: """Invoke the command group. Args: context: The current click context. """ # Use the context manager to ensure tools exceptions (expected behaviour) are shown as messages to the user, # but all other exceptions (unexpected behaviour) are shown as errors. with MbedToolsHandler(LOGGER, context.params["traceback"]): super().invoke(context)
def test_tools_error_with_traceback(self): mock_logger = mock.Mock(spec_set=logging.Logger) with MbedToolsHandler(mock_logger, traceback=True): raise ToolsError(self.exception_string) mock_logger.error.assert_called_once_with(self.expected_log_message, exc_info=True)