From df3c2cc03477fbc7461cedaf9b1fbb9e346efc64 Mon Sep 17 00:00:00 2001 From: Tony Meyer Date: Fri, 22 Sep 2023 14:10:44 +1200 Subject: [PATCH] Fix type hints. For the model backend stub, we know that the type won't match, but we don't really care. We could make an abc that both the stub and the real class could inherit from, or we could subclass for the stub, but those seem overkill for this specific use case. It seems unlikely that type hints would show any real-life issues here. --- test/test_log.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/test/test_log.py b/test/test_log.py index 805df2749..0d279f9fb 100644 --- a/test/test_log.py +++ b/test/test_log.py @@ -16,6 +16,7 @@ import io import logging +import typing import unittest from unittest.mock import patch @@ -26,15 +27,15 @@ class FakeModelBackend: def __init__(self): - self._calls = [] + self._calls : typing.List[typing.Tuple[str, str]] = [] - def calls(self, clear=False): + def calls(self, clear: bool = False): calls = self._calls if clear: self._calls = [] return calls - def juju_log(self, level, message): + def juju_log(self, level: str, message: str): for line in _ModelBackend.log_split(message): self._calls.append((level, line)) @@ -48,7 +49,7 @@ def tearDown(self): logging.getLogger().handlers.clear() def test_default_logging(self): - ops.log.setup_root_logging(self.backend) + ops.log.setup_root_logging(self.backend) # type: ignore logger = logging.getLogger() self.assertEqual(logger.level, logging.DEBUG) @@ -71,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)) + logger.addHandler(ops.log.JujuLogHandler(self.backend, logging.WARNING)) # type: ignore logger.info('foo') self.assertEqual(self.backend.calls(), []) logger.warning('bar') @@ -80,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) + ops.log.setup_root_logging(self.backend, debug=False) # type: ignore logger = logging.getLogger() logger.debug('debug message') logger.info('info message') @@ -98,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) + ops.log.setup_root_logging(self.backend, debug=True) # type: ignore logger = logging.getLogger() logger.debug('debug message') logger.info('info message') @@ -120,7 +121,7 @@ def test_debug_logging(self): ) def test_reduced_logging(self): - ops.log.setup_root_logging(self.backend) + ops.log.setup_root_logging(self.backend) # type: ignore logger = logging.getLogger() logger.setLevel(logging.WARNING) logger.debug('debug') @@ -132,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) + ops.log.setup_root_logging(self.backend, debug=True) # type: ignore logger = logging.getLogger() logger.debug('l' * MAX_LOG_LINE_LEN)