Skip to content

Commit 5f882a3

Browse files
committed
[run-qemu][print_test_summary] change script to generate logs and later
write them This makes just easier to separate the file operations from the generation of the content, and therefore, easier to test. Signed-off-by: Manu Bretelle <[email protected]>
1 parent 475c7f1 commit 5f882a3

File tree

1 file changed

+33
-27
lines changed

1 file changed

+33
-27
lines changed

run-qemu/print_test_summary.py

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import argparse
1111
import json
1212

13+
from typing import Tuple
14+
1315

1416
def parse_args():
1517
parser = argparse.ArgumentParser()
@@ -47,18 +49,10 @@ def markdown_summary(json_summary: json):
4749
- :x: Failed: {json_summary['failed']}"""
4850

4951

50-
def console_summary(json_summary: json):
52+
def log_summary(json_summary: json):
5153
return f"Success: {json_summary['success']}/{json_summary['success_subtest']}, Skipped: {json_summary['skipped']}, Failed: {json_summary['failed']}"
5254

5355

54-
def log_gh_summary(file, text: str):
55-
print(text, file=file)
56-
57-
58-
def log_console(text: str):
59-
print(text)
60-
61-
6256
def group(text: str, title: str = "", error: bool = False) -> str:
6357
if error and title:
6458
title = f"\033[1;31mError:\033[0m {title}"
@@ -76,6 +70,33 @@ def test_error_console_log(test_error: str, test_message: str) -> str:
7670
return error_msg
7771

7872

73+
def build_summaries(json_summary) -> Tuple[str, str]:
74+
gh_summary = ["# Tests summary"]
75+
gh_summary.append(markdown_summary(json_summary))
76+
77+
console_summary = [notice(log_summary(json_summary))]
78+
79+
for test in json_summary["results"]:
80+
test_name = test["name"]
81+
test_number = test["number"]
82+
if test["failed"]:
83+
test_log = f"#{test_number} {test_name}"
84+
gh_summary.append(test_log)
85+
console_summary.append(test_error_console_log(test_log, test["message"]))
86+
87+
for subtest in test["subtests"]:
88+
if subtest["failed"]:
89+
subtest_log = (
90+
f"#{test_number}/{subtest['number']} {test_name}/{subtest['name']}"
91+
)
92+
gh_summary.append(subtest_log)
93+
console_summary.append(
94+
test_error_console_log(subtest_log, subtest["message"])
95+
)
96+
97+
return "\n".join(gh_summary), "\n".join(console_summary)
98+
99+
79100
if __name__ == "__main__":
80101
args = parse_args()
81102
step_open_mode = "a" if args.append else "w"
@@ -84,22 +105,7 @@ def test_error_console_log(test_error: str, test_message: str) -> str:
84105
with open(args.json_summary, "r") as f:
85106
json_summary = json.load(f)
86107

108+
gh_summary, console_summary = build_summaries(json_summary)
87109
with open(args.step_summary, step_open_mode) as f:
88-
log_gh_summary(f, "# Tests summary")
89-
log_gh_summary(f, markdown_summary(json_summary))
90-
91-
log_console(notice(console_summary(json_summary)))
92-
93-
for test in json_summary["results"]:
94-
test_name = test["name"]
95-
test_number = test["number"]
96-
if test["failed"]:
97-
test_log = f"#{test_number} {test_name}"
98-
log_gh_summary(f, test_log)
99-
log_console(test_error_console_log(test_log, test["message"]))
100-
101-
for subtest in test["subtests"]:
102-
if subtest["failed"]:
103-
subtest_log = f"#{test_number}/{subtest['number']} {test_name}/{subtest['name']}"
104-
log_gh_summary(f, subtest_log)
105-
log_console(test_error_console_log(subtest_log, subtest["message"]))
110+
print(gh_summary, file=f)
111+
print(console_summary)

0 commit comments

Comments
 (0)