chirp/tests/unit/test_logger.py
Dan Smith fe90410c2a Capture and show driver messages during load
This makes us capture and display any warning or error log messages
that the driver emits while we're loading it (but no other times).
While this is sort of a hack, it provides a conduit for the driver's
sanity-checking routines to communicate concerns to the UI user, such
as un-parse-able CSV lines, etc. Actual failures to parse the image
should of course still raise an exception to stop the process.

Fixes: #11093
2024-01-29 18:30:42 -08:00

38 lines
1.1 KiB
Python

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))