From 3f8d6e987c0b28c4da50e4cb4e5d7d50a0518b01 Mon Sep 17 00:00:00 2001 From: Hans Ekkehard Plesser Date: Fri, 1 Mar 2024 14:51:02 +0100 Subject: [PATCH] Automatically adjust column widths in testsuite report --- testsuite/summarize_tests.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/testsuite/summarize_tests.py b/testsuite/summarize_tests.py index de26ecfedd..7eb26426da 100644 --- a/testsuite/summarize_tests.py +++ b/testsuite/summarize_tests.py @@ -77,7 +77,11 @@ def parse_result_file(fname): totals[k] += v cols = ["Tests", "Skipped", "Failures", "Errors", "Time"] - tline = "-" * (len(cols) * 10 + 20) + + col_w = max(len(c) for c in cols) + 2 + first_col_w = max(len(k) for k in results.keys()) + + tline = "-" * (len(cols) * col_w + first_col_w) print() print() @@ -85,24 +89,24 @@ def parse_result_file(fname): print("NEST Testsuite Results") print(tline) - print("{:<20s}".format("Phase"), end="") + print(f"{'Phase':<{first_col_w}s}", end="") for c in cols: - print("{:>10s}".format(c), end="") + print(f"{c:>{col_w}s}", end="") print() print(tline) for pn, pr in results.items(): - print("{:<20s}".format(pn), end="") + print(f"{pn:<{first_col_w}s}", end="") for c in cols: - fstr = "{:10.1f}" if c == "Time" else "{:10d}" - print(fstr.format(pr[c]), end="") + fmt = ".1f" if c == "Time" else "d" + print(f"{pr[c]:{col_w}{fmt}}", end="") print() print(tline) - print("{:<20s}".format("Total"), end="") + print(f"{'Total':<{first_col_w}s}", end="") for c in cols: - fstr = "{:10.1f}" if c == "Time" else "{:10d}" - print(fstr.format(totals[c]), end="") + fmt = ".1f" if c == "Time" else "d" + print(f"{totals[c]:{col_w}{fmt}}", end="") print() print(tline) print()