Ejemplo n.º 1
0
 def test_reset_logger(self):
     """Test that reset_logger gives back a standard python logger with defaults."""
     logger_name = str(uuid.uuid4())
     logger = _logger.reset_logger(logger_name)
     self.assertEqual(logger_name, logger.name)
     self.assertEqual(1, len(logger.handlers))
     handler = logger.handlers[0]
     self.assertIsInstance(handler, logging.StreamHandler)
     self.assertEqual(
         '%(levelname)-8s %(asctime)s %(filename)s:%(lineno)s:%(message)s',
         handler.formatter._fmt)
Ejemplo n.º 2
0
 def test_reset_logger(self):
   """Test that reset_logger gives back a standard python logger with defaults."""
   logger_name = str(uuid.uuid4())
   logger = _logger.reset_logger(logger_name)
   self.assertEqual(logger_name, logger.name)
   self.assertEqual(1, len(logger.handlers))
   handler = logger.handlers[0]
   self.assertIsInstance(handler, logging.StreamHandler)
   self.assertEqual(
     '%(levelname)-8s %(asctime)s %(filename)s:%(lineno)s:%(message)s',
     handler.formatter._fmt
   )
Ejemplo n.º 3
0
  def test_reset_logger__with_handler__existing(self):
    """Test that reset_logger deals with provided handlers correctly."""
    existing_handler = logging.NullHandler()
    logger_name = 'test-logger-{}'.format(uuid.uuid4())
    reset_logger = _logger.reset_logger(logger_name, handler=existing_handler)
    self.assertEqual(1, len(reset_logger.handlers))

    handler = reset_logger.handlers[0]
    self.assertIs(existing_handler, handler)
    self.assertEqual(
      '%(levelname)-8s %(asctime)s %(filename)s:%(lineno)s:%(message)s',
      handler.formatter._fmt
    )
Ejemplo n.º 4
0
    def test_reset_logger__with_handler__existing(self):
        """Test that reset_logger deals with provided handlers correctly."""
        existing_handler = logging.NullHandler()
        logger_name = 'test-logger-{}'.format(uuid.uuid4())
        reset_logger = _logger.reset_logger(logger_name,
                                            handler=existing_handler)
        self.assertEqual(1, len(reset_logger.handlers))

        handler = reset_logger.handlers[0]
        self.assertIs(existing_handler, handler)
        self.assertEqual(
            '%(levelname)-8s %(asctime)s %(filename)s:%(lineno)s:%(message)s',
            handler.formatter._fmt)
Ejemplo n.º 5
0
    def test_reset_logger__replaces_handlers(self):
        """Test that reset_logger replaces existing handlers with a StreamHandler."""
        logger_name = 'test-logger-{}'.format(uuid.uuid4())
        logger = logging.getLogger(logger_name)
        logger.handlers = [logging.StreamHandler() for _ in range(10)]

        reset_logger = _logger.reset_logger(logger_name)
        self.assertEqual(1, len(reset_logger.handlers))

        handler = reset_logger.handlers[0]
        self.assertIsInstance(handler, logging.StreamHandler)
        self.assertEqual(
            '%(levelname)-8s %(asctime)s %(filename)s:%(lineno)s:%(message)s',
            handler.formatter._fmt)
Ejemplo n.º 6
0
  def test_reset_logger__replaces_handlers(self):
    """Test that reset_logger replaces existing handlers with a StreamHandler."""
    logger_name = 'test-logger-{}'.format(uuid.uuid4())
    logger = logging.getLogger(logger_name)
    logger.handlers = [logging.StreamHandler() for _ in range(10)]

    reset_logger = _logger.reset_logger(logger_name)
    self.assertEqual(1, len(reset_logger.handlers))

    handler = reset_logger.handlers[0]
    self.assertIsInstance(handler, logging.StreamHandler)
    self.assertEqual(
      '%(levelname)-8s %(asctime)s %(filename)s:%(lineno)s:%(message)s',
      handler.formatter._fmt
    )
Ejemplo n.º 7
0
 def test_reset_logger__with_level(self):
     """Test that reset_logger sets log levels correctly."""
     logger_name = 'test-logger-{}'.format(uuid.uuid4())
     reset_logger = _logger.reset_logger(logger_name, level=logging.DEBUG)
     self.assertEqual(logging.DEBUG, reset_logger.level)
Ejemplo n.º 8
0
 def test_reset_logger__with_level(self):
   """Test that reset_logger sets log levels correctly."""
   logger_name = 'test-logger-{}'.format(uuid.uuid4())
   reset_logger = _logger.reset_logger(logger_name, level=logging.DEBUG)
   self.assertEqual(logging.DEBUG, reset_logger.level)