From fa605255cae0c53b166be0b5ed29f046aff33c47 Mon Sep 17 00:00:00 2001 From: Tony Meyer Date: Fri, 22 Sep 2023 17:19:53 +1200 Subject: [PATCH] test: add type hints to test_log tests (#1009) * Fix type hints. * Subclass the real model with the fake one so that the types easily match. --- pyproject.toml | 1 + test/test_log.py | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index f523c1ec0..c7c210455 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -29,6 +29,7 @@ docstring-convention = "google" [tool.pyright] include = ["ops/*.py", "ops/_private/*.py", + "test/test_log.py", "test/test_infra.py", ] pythonVersion = "3.8" # check no python > 3.8 features are used diff --git a/test/test_log.py b/test/test_log.py index 805df2749..97b735ae6 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 @@ -23,18 +24,18 @@ from ops.model import MAX_LOG_LINE_LEN, _ModelBackend -class FakeModelBackend: +class FakeModelBackend(_ModelBackend): 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))