Skip to content

Commit

Permalink
Subclass the real model with the fake one so that the types easily ma…
Browse files Browse the repository at this point in the history
…tch.
  • Loading branch information
tonyandrewmeyer committed Sep 22, 2023
1 parent 9a510c3 commit 09802ea
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions test/test_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from ops.model import MAX_LOG_LINE_LEN, _ModelBackend


class FakeModelBackend:
class FakeModelBackend((_ModelBackend)):

def __init__(self):
self._calls : typing.List[typing.Tuple[str, str]] = []
Expand All @@ -49,7 +49,7 @@ def tearDown(self):
logging.getLogger().handlers.clear()

def test_default_logging(self):
ops.log.setup_root_logging(self.backend) # type: ignore
ops.log.setup_root_logging(self.backend)

logger = logging.getLogger()
self.assertEqual(logger.level, logging.DEBUG)
Expand All @@ -72,7 +72,7 @@ def test_default_logging(self):
def test_handler_filtering(self):
logger = logging.getLogger()
logger.setLevel(logging.INFO)
logger.addHandler(ops.log.JujuLogHandler(self.backend, logging.WARNING)) # type: ignore
logger.addHandler(ops.log.JujuLogHandler(self.backend, logging.WARNING))
logger.info('foo')
self.assertEqual(self.backend.calls(), [])
logger.warning('bar')
Expand All @@ -81,7 +81,7 @@ def test_handler_filtering(self):
def test_no_stderr_without_debug(self):
buffer = io.StringIO()
with patch('sys.stderr', buffer):
ops.log.setup_root_logging(self.backend, debug=False) # type: ignore
ops.log.setup_root_logging(self.backend, debug=False)
logger = logging.getLogger()
logger.debug('debug message')
logger.info('info message')
Expand All @@ -99,7 +99,7 @@ def test_no_stderr_without_debug(self):
def test_debug_logging(self):
buffer = io.StringIO()
with patch('sys.stderr', buffer):
ops.log.setup_root_logging(self.backend, debug=True) # type: ignore
ops.log.setup_root_logging(self.backend, debug=True)
logger = logging.getLogger()
logger.debug('debug message')
logger.info('info message')
Expand All @@ -121,7 +121,7 @@ def test_debug_logging(self):
)

def test_reduced_logging(self):
ops.log.setup_root_logging(self.backend) # type: ignore
ops.log.setup_root_logging(self.backend)
logger = logging.getLogger()
logger.setLevel(logging.WARNING)
logger.debug('debug')
Expand All @@ -133,7 +133,7 @@ def test_long_string_logging(self):
buffer = io.StringIO()

with patch('sys.stderr', buffer):
ops.log.setup_root_logging(self.backend, debug=True) # type: ignore
ops.log.setup_root_logging(self.backend, debug=True)
logger = logging.getLogger()
logger.debug('l' * MAX_LOG_LINE_LEN)

Expand Down

0 comments on commit 09802ea

Please sign in to comment.