123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- """Tests for dulwich.log_utils."""
- import logging
- from dulwich.log_utils import (
- _DULWICH_LOGGER,
- _NULL_HANDLER,
- _NullHandler,
- default_logging_config,
- getLogger,
- remove_null_handler,
- )
- from . import TestCase
- class LogUtilsTests(TestCase):
- """Tests for log_utils."""
- def setUp(self):
- super().setUp()
-
- self.original_handlers = list(_DULWICH_LOGGER.handlers)
- def tearDown(self):
-
- _DULWICH_LOGGER.handlers = self.original_handlers
- super().tearDown()
- def test_null_handler(self):
- """Test the _NullHandler class."""
- handler = _NullHandler()
-
- record = logging.LogRecord(
- name="test",
- level=logging.INFO,
- pathname="test_log_utils.py",
- lineno=1,
- msg="Test message",
- args=(),
- exc_info=None,
- )
-
- handler.emit(record)
- def test_get_logger(self):
- """Test the getLogger function."""
-
- logger = getLogger("dulwich.test")
- self.assertIsInstance(logger, logging.Logger)
- self.assertEqual(logger.name, "dulwich.test")
- def test_remove_null_handler(self):
- """Test removing the null handler."""
-
- if _NULL_HANDLER not in _DULWICH_LOGGER.handlers:
- _DULWICH_LOGGER.addHandler(_NULL_HANDLER)
-
- remove_null_handler()
-
- self.assertNotIn(_NULL_HANDLER, _DULWICH_LOGGER.handlers)
- def test_default_logging_config(self):
- """Test the default logging configuration."""
-
- default_logging_config()
-
- self.assertNotIn(_NULL_HANDLER, _DULWICH_LOGGER.handlers)
-
- root_logger = logging.getLogger()
- self.assertTrue(root_logger.handlers)
-
- root_logger.handlers = []
|