Пример #1
0
    def test_log_error(self):
        """Test log error."""
        logger = mock.MagicMock()
        self.mock.get_logger.return_value = logger

        statement_line = inspect.currentframe().f_lineno + 1
        logs.emit(logging.ERROR,
                  'msg',
                  exc_info='ex',
                  target='bot',
                  test='yes')

        logger.log.assert_called_once_with(
            logging.ERROR,
            'msg',
            exc_info='ex',
            extra={
                'extras': {
                    'target': 'bot',
                    'test': 'yes'
                },
                'location': {
                    'path': os.path.abspath(__file__).rstrip('c'),
                    'line': statement_line,
                    'method': 'test_log_error'
                }
            })
Пример #2
0
 def test_no_logger(self):
     """Test no logger."""
     self.mock.get_logger.return_value = None
     logs.emit(logging.INFO, 'message')