コード例 #1
0
ファイル: test_logging.py プロジェクト: urutva/mbed-tools
 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.")
コード例 #2
0
ファイル: test_logging.py プロジェクト: urutva/mbed-tools
 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.")
コード例 #3
0
ファイル: main.py プロジェクト: urutva/mbed-tools
    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)
コード例 #4
0
 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)