File: test_logger.py

package info (click to toggle)
chirp 1%3A20251108-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 18,728 kB
  • sloc: python: 156,369; ansic: 296; sh: 219; xml: 24; makefile: 19
file content (38 lines) | stat: -rw-r--r-- 1,133 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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))