コード例 #1
0
 def test_create_logger(self, module):
     """Tests that the create_logger function returns a logger with the
     default configuration set for an SF logger"""
     logger = create_logger(module.__name__)
     assert logger.level == logging.INFO
     assert logging_handler_defined(logger)
     assert logger.handlers[0] == default_handler
コード例 #2
0
    def test_logging_handler_defined(self, module):
        """Tests that the logging_handler_defined function works correctly in
        the following cases:

        1. When a custom logger was just created and by default has no level
           handler
        2. Adding a handler to the root logger affects the custom logger
        3. When propagation is set to False, only the handlers of the custom
        logger are checked"""
        logger = logging.getLogger(module.__name__)
        assert not logging_handler_defined(logger)

        handler = logging.StreamHandler()
        logging.root.addHandler(handler)
        assert logging_handler_defined(logger)

        logger.propagate = False
        assert not logging_handler_defined(logger)
コード例 #3
0
    def test_custom_logger_before_sf_logger_with_higher_level(self, module):
        """Tests that a custom logger created before an SF logger will define
        the level for logging as expected and the SF logger does not overwrite
        the user configuration.

        The logic of the test goes as follows:
        1. Manually setting the level for logging for DEBUG level
        2. Creating an SF logger with level WARNING, that is higher than DEBUG
        3. Checking that the SF logger did not affect the handlers defined or
           the effective level of the logger
        """
        custom_level = logging.DEBUG
        sf_level = logging.WARNING

        logger = logging.getLogger()
        logging.basicConfig(level=custom_level)

        _ = create_logger(module.__name__, level=sf_level)

        assert logging_handler_defined(logger)
        assert logger.getEffectiveLevel() == custom_level