Пример #1
0
    def test_should_set_default_log_level_if_no_log_level_given(self, mock_formatter_class, mock_sys_log_handler_class):

        mock_handler = Mock()
        mock_sys_log_handler_class.return_value = mock_handler

        create_sys_log_handler(123)

        mock_handler.setLevel.assert_called_with(SYS_LOG_LEVEL)
    def test_should_set_default_log_level_if_no_log_level_given(
            self, mock_formatter_class, mock_sys_log_handler_class):

        mock_handler = Mock()
        mock_sys_log_handler_class.return_value = mock_handler

        create_sys_log_handler(123)

        mock_handler.setLevel.assert_called_with(SYS_LOG_LEVEL)
    def test_should_initialze_syslog_handler_with_default_address_and_facility(
            self, mock_formatter_class, mock_sys_log_handler_class):

        mock_formatter = Mock()
        mock_formatter_class.return_value = mock_formatter
        mock_handler = Mock()
        mock_sys_log_handler_class.return_value = mock_handler

        create_sys_log_handler(123)

        mock_sys_log_handler_class.assert_called_with(
            address='/dev/log', facility=SysLogHandler.LOG_USER)
Пример #4
0
    def test_should_initialze_syslog_handler_with_default_address_and_facility(
        self, mock_formatter_class, mock_sys_log_handler_class
    ):

        mock_formatter = Mock()
        mock_formatter_class.return_value = mock_formatter
        mock_handler = Mock()
        mock_sys_log_handler_class.return_value = mock_handler

        create_sys_log_handler(123)

        mock_sys_log_handler_class.assert_called_with(address="/dev/log", facility=SysLogHandler.LOG_USER)
    def test_should_initialze_formatter_using_the_revision_number_in_the_format(
            self, mock_formatter_class, mock_sys_log_handler_class):

        mock_formatter = Mock()
        mock_formatter_class.return_value = mock_formatter
        mock_handler = Mock()
        mock_sys_log_handler_class.return_value = mock_handler

        create_sys_log_handler(123)

        mock_formatter_class.assert_called_with(
            'config_rpm_maker[123]: [%(levelname)5s] %(message)s')
        mock_handler.setFormatter.assert_called_with(mock_formatter)
Пример #6
0
    def test_should_initialze_formatter_using_the_revision_number_in_the_format(
        self, mock_formatter_class, mock_sys_log_handler_class
    ):

        mock_formatter = Mock()
        mock_formatter_class.return_value = mock_formatter
        mock_handler = Mock()
        mock_sys_log_handler_class.return_value = mock_handler

        create_sys_log_handler(123)

        mock_formatter_class.assert_called_with("config_rpm_maker[123]: [%(levelname)5s] %(message)s")
        mock_handler.setFormatter.assert_called_with(mock_formatter)
Пример #7
0
    def test_should_return_created_console_handler(self, mock_formatter_class, mock_sys_log_handler_class):

        mock_handler = Mock()
        mock_sys_log_handler_class.return_value = mock_handler

        actual_handler = create_sys_log_handler(123)

        self.assertEqual(mock_handler, actual_handler)
Пример #8
0
def initialize_logging_to_syslog(arguments, revision):
    """ Initializes the logging to syslog and appends the syslog handler to
        the root logger if not omitted by the --no-syslog option """

    if not arguments[OPTION_NO_SYSLOG]:
        sys_log_handler = create_sys_log_handler(revision)
        LOGGER.addHandler(sys_log_handler)
        LOGGER.info("Logging to syslog on level %s", getLevelName(sys_log_handler.level))
Пример #9
0
def initialize_logging_to_syslog(arguments, revision):
    """ Initializes the logging to syslog and appends the syslog handler to
        the root logger if not omitted by the --no-syslog option """

    if not arguments[OPTION_NO_SYSLOG]:
        sys_log_handler = create_sys_log_handler(revision)
        LOGGER.addHandler(sys_log_handler)
        LOGGER.info("Logging to syslog on level %s",
                    getLevelName(sys_log_handler.level))
    def test_should_return_created_console_handler(self, mock_formatter_class,
                                                   mock_sys_log_handler_class):

        mock_handler = Mock()
        mock_sys_log_handler_class.return_value = mock_handler

        actual_handler = create_sys_log_handler(123)

        self.assertEqual(mock_handler, actual_handler)