Skip to content

Commit 25fdcb2

Browse files
authored
Improve formatting in gh_parse.py (#3742)
## Changes - In the table with test names, do not include full action name. We have it included in environment table, so that double serves as agenda. - Use consistent column order in env table - Reorder action columns from most interesting to least interesting, because the order is important for summary icon. ## Why Noticed it does not look good with long action names like "RECOVERED": #3740 See Before/After: #3742 (comment)
1 parent 228a202 commit 25fdcb2

File tree

1 file changed

+38
-7
lines changed

1 file changed

+38
-7
lines changed

tools/gh_parse.py

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@
3434
KNOWN_FAILURE = "🟨\u200bKNOWN"
3535
RECOVERED = "💚\u200bRECOVERED"
3636

37-
INTERESTING_ACTIONS = (FAIL, BUG, FLAKY, PANIC, MISSING, KNOWN_FAILURE, RECOVERED)
37+
# The order is important - in case of ambiguity, earlier one gets preference.
38+
# For examples, each environment gets a summary icon which is earliest action in this list among all tests.
39+
INTERESTING_ACTIONS = (PANIC, BUG, FAIL, KNOWN_FAILURE, MISSING, FLAKY, RECOVERED)
3840
ACTIONS_WITH_ICON = INTERESTING_ACTIONS + (PASS, SKIP)
3941

4042
ACTION_MESSAGES = {
@@ -408,6 +410,7 @@ def is_bug(test_results):
408410
per_env_stats.setdefault(env, Counter()).update(stats)
409411

410412
table = []
413+
columns = {" ", "Env"}
411414
for env, stats in sorted(per_env_stats.items()):
412415
status = "??"
413416
for action in ACTIONS_WITH_ICON:
@@ -422,7 +425,16 @@ def is_bug(test_results):
422425
**stats,
423426
}
424427
)
425-
print(format_table(table, markdown=markdown))
428+
columns.update(stats)
429+
430+
def key(column):
431+
try:
432+
return (ACTIONS_WITH_ICON.index(column), "")
433+
except:
434+
return (-1, str(column))
435+
436+
columns = sorted(columns, key=key)
437+
print(format_table(table, markdown=markdown, columns=columns))
426438

427439
interesting_envs = set()
428440
for env, stats in per_env_stats.items():
@@ -439,7 +451,7 @@ def is_bug(test_results):
439451
for env, counts in items.items():
440452
for action in INTERESTING_ACTIONS:
441453
if action in counts:
442-
per_testkey_result.setdefault(env, action)
454+
per_testkey_result.setdefault(env, short_action(action))
443455
break
444456

445457
# Once we know test is interesting, complete the row
@@ -449,7 +461,7 @@ def is_bug(test_results):
449461
continue
450462
for action in (PASS, SKIP):
451463
if action in counts:
452-
per_testkey_result.setdefault(env, action)
464+
per_testkey_result.setdefault(env, short_action(action))
453465
break
454466

455467
if not per_testkey_result:
@@ -493,6 +505,15 @@ def is_bug(test_results):
493505
print()
494506

495507

508+
# For test table, use shorter version of action.
509+
# We have full action name in env table, so that is used as agenda.
510+
def short_action(action):
511+
if len(action) >= 4 and action[1] == "\u200b":
512+
# include first non-emoji letter in case emoji rendering is broken
513+
return action[:3]
514+
return action
515+
516+
496517
def format_table(table, columns=None, markdown=False):
497518
"""
498519
Pretty-print a list-of-dicts as an aligned text table.
@@ -526,12 +547,12 @@ def format_table(table, columns=None, markdown=False):
526547

527548
if markdown:
528549
# Header
529-
write("| " + " | ".join(str(col).ljust(w) for col, w in zip(columns, widths)) + " |")
550+
write("| " + " | ".join(autojust(str(col), w) for col, w in zip(columns, widths)) + " |")
530551
# Separator
531552
write("| " + " | ".join("-" * w for w in widths) + " |")
532553
# Data rows
533554
for row in table:
534-
write("| " + " | ".join(str(row.get(col, "")).ljust(w) for col, w in zip(columns, widths)) + " |")
555+
write("| " + " | ".join(autojust(row.get(col, ""), w) for col, w in zip(columns, widths)) + " |")
535556
else:
536557
write(fmt(columns, widths))
537558
for ind, row in enumerate(table):
@@ -543,7 +564,17 @@ def format_table(table, columns=None, markdown=False):
543564

544565

545566
def fmt(cells, widths):
546-
return " ".join(str(cell).ljust(w) for cell, w in zip(cells, widths))
567+
return " ".join(autojust(cell, w) for cell, w in zip(cells, widths))
568+
569+
570+
def autojust(value, width):
571+
# Note, this has no effect on how markdown is rendered, only relevant for terminal output
572+
value = str(value)
573+
if value.isdigit():
574+
return value.center(width)
575+
if len(value) <= 3: # short action name
576+
return value.center(width)
577+
return value.ljust(width)
547578

548579

549580
def wrap_in_details(txt, summary):

0 commit comments

Comments
 (0)