summaryrefslogtreecommitdiff
path: root/tests/unit/test_logger.py
diff options
context:
space:
mode:
authorDave Hibberd <hibby@debian.org>2024-02-24 13:47:31 +0000
committerDave Hibberd <hibby@debian.org>2024-02-24 13:47:31 +0000
commit22d82ba3c0d6bd591c135290d88adcc2414ba588 (patch)
tree98dacd9f46560513d2869207b7f13a8ca9294ba2 /tests/unit/test_logger.py
parente5819ceb55106d4b9b8d34d4d4e031b2a895b760 (diff)
parentfc438e6a84402e621877f6c30097442af46f122b (diff)
Update upstream source from tag 'upstream/20240224'
Update to upstream version '20240224' with Debian dir f7af8ad341f9d73e94489b1e0a1b6e721fc7f61d
Diffstat (limited to 'tests/unit/test_logger.py')
-rw-r--r--tests/unit/test_logger.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/unit/test_logger.py b/tests/unit/test_logger.py
new file mode 100644
index 0000000..e4c32a9
--- /dev/null
+++ b/tests/unit/test_logger.py
@@ -0,0 +1,38 @@
+import logging
+
+from chirp import logger
+from tests.unit import base
+
+
+class TestLogger(base.BaseTest):
+ def test_log_history(self):
+ drv_log = logging.getLogger('chirp.drivers.foo')
+ ui_log = logging.getLogger('chirp.wxui.foo')
+ root_log = logging.getLogger()
+
+ root_log.setLevel(logging.DEBUG)
+
+ def log_all():
+ for log in (drv_log, ui_log, root_log):
+ log.debug('debug')
+ log.warning('warning')
+ log.error('error')
+
+ # Log to everything
+ log_all()
+
+ with logger.log_history(logging.WARNING, 'chirp.drivers') as h:
+ log_all()
+ history = h.get_history()
+
+ # We should only have the error,warning messages from drivers
+ # since we started the capture, not before
+ self.assertEqual(2, len(history))
+
+ with logger.log_history(logging.WARNING, 'chirp.drivers') as h:
+ log_all()
+ history = h.get_history()
+
+ # Make sure we only have the captured logs, not any leftover from
+ # the previous run
+ self.assertEqual(2, len(history))