Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trunner: add formatting to subresult message with newlines #385

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions trunner/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,10 +342,38 @@ def __init__(self, name=None, subname: str = "", msg: str = "", status: Optional
self.set_stage(TestStage.RUN)

def __str__(self) -> str:
out = f"\t{bold(self.subname)}: {self.status}"
tab = " " * 6
out = f"{tab}{bold(self.subname)}: {self.status}"

if self.msg and self.status != Status.OK:
out += ": " + self.msg
shift_len = len(f"{self.subname}: {self.status.name}: ")
msg_lines = self.msg.splitlines()
first_line, *remaining_lines = msg_lines

if shift_len + max(len(line) for line in msg_lines) + len(tab) > 120:
if remaining_lines:
remaining_lines = "\n" + "\n".join(
f"{tab}{tab}{line}"
for line in remaining_lines
)
else:
remaining_lines = ""

if shift_len + len(first_line) + len(tab) > 120:
out += "\n" + f"{tab}{tab}{first_line}"
else:
out += ": " + first_line + remaining_lines
else:
# Make msg with newlines aligned
if remaining_lines:
remaining_lines = "\n" + "\n".join(
f'{tab}{" " * shift_len}{line}'
for line in remaining_lines
)
else:
remaining_lines = ""

out += ": " + first_line + remaining_lines

return out

Expand Down
Loading