Skip to content

Commit

Permalink
Tidy code from review suggestions
Browse files Browse the repository at this point in the history
Co-authored-by: Jacob Wilkins <46597752+oerc0122@users.noreply.github.com>
  • Loading branch information
ElliottKasoar and oerc0122 authored Apr 4, 2024
1 parent 7367133 commit 7c86ee7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
4 changes: 2 additions & 2 deletions janus_core/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
14 changes: 5 additions & 9 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)

0 comments on commit 7c86ee7

Please sign in to comment.