From 5949943028d31c68e721b6579d19e70d31e11574 Mon Sep 17 00:00:00 2001 From: ElliottKasoar <45317199+ElliottKasoar@users.noreply.github.com> Date: Thu, 4 Apr 2024 11:43:50 +0100 Subject: [PATCH] Tidy code from review suggestions Co-authored-by: Jacob Wilkins <46597752+oerc0122@users.noreply.github.com> --- janus_core/log.py | 4 ++-- tests/utils.py | 14 +++++--------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/janus_core/log.py b/janus_core/log.py index e560fef3..846c2339 100644 --- a/janus_core/log.py +++ b/janus_core/log.py @@ -18,7 +18,7 @@ class YamlFormatter(logging.Formatter): # numpydoc ignore=PR02 datefmt : Optional[str] A format string in the given style for the date/time portion of the logged output. Default is taken from logging.Formatter.formatTime(). - style : Literal['%'] | Literal['{'] | Literal['$'] + style : Literal['%', '{', '$'] Determines how the format string will be merged with its data. Can be one of '%', '{' or '$'. Default is '%'. validate : bool @@ -79,7 +79,7 @@ def format(self, record: logging.LogRecord) -> str: # Convert new lines into yaml list msg = record.msg record.msg = "\n" + "\n".join( - [f' - "{line.strip()}"' for line in msg.split("\n") if line.strip()], + f' - "{line.strip()}"' for line in msg.split("\n") if line.strip() ) return super().format(record) diff --git a/tests/utils.py b/tests/utils.py index a0ce2bbc..42135f29 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -36,9 +36,9 @@ def read_atoms(path: Path) -> Union[Atoms, None]: def check_log_contents( - log_path: PathLike, - includes: Optional[MaybeSequence[str]] = None, - excludes: Optional[MaybeSequence[str]] = None, + log_path: PathLike, *, + includes: MaybeSequence[str] = (), + excludes: MaybeSequence[str] = (), ) -> None: """ Check messages are present or not within a yaml-formatted log file. @@ -62,9 +62,5 @@ def check_log_contents( # Nested join as log["message"] may be a list messages = "".join("".join(log["message"]) for log in logs) - if includes: - for msg in includes: - assert msg in messages - if excludes: - for msg in excludes: - assert msg not in messages + assert all(inc in messages for inc in includes) + assert all(exc not in messages for exc in excludes)