Debian Codegraph @

tests/test_logging.py

raw
1 # Copyright (c) Meta Platforms, Inc. and affiliates.
2 # SPDX-License-Identifier: LGPL-2.1-or-later
3
4 import logging
5
6 from drgn import Program
7 from tests import TestCase
8
9
10 # Test that our monkey patch to sync the log level between the logging module
11 # and libdrgn works.
12 class TestLogging(TestCase):
13 def test_set_level_before(self):
14 logger = logging.getLogger("drgn")
15 with self.assertLogs(logger, "DEBUG") as cm:
16 prog = Program()
17 prog._log(0, "foo")
18 self.assertIn("DEBUG:drgn:foo", cm.output)
19
20 def test_set_level_after(self):
21 prog = Program()
22 logger = logging.getLogger("drgn")
23 with self.assertLogs(logger, "DEBUG") as cm:
24 prog._log(0, "bar")
25 self.assertIn("DEBUG:drgn:bar", cm.output)