Skip to content

Commit 0933d2b

Browse files
authored
Fix NameError and other issues in gh_parse.py and gh_report.py (#3164)
Noticed, the script fails sometimes with ``` File "/home/runner/work/eng-dev-ecosystem/eng-dev-ecosystem/ext/cli/tools/gh_parse.py", line 109, in parse_file results.setdefault(testname, MISS) ^^^^ NameError: name 'MISS' is not defined ``` This and other issues are found by ruff.
1 parent e1ec91b commit 0933d2b

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

tools/gh_parse.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import sys
77
import json
88
import argparse
9-
import re
109
from collections import Counter
1110
from pathlib import Path
1211

@@ -78,7 +77,7 @@ def parse_file(path, filter):
7877
try:
7978
data = json.loads(line)
8079
except Exception as ex:
81-
print(f"{filename}: {ex}\n{line!r}\n")
80+
print(f"{path}: {ex}\n{line!r}\n")
8281
break
8382
testname = data.get("Test")
8483
if not testname:
@@ -106,7 +105,7 @@ def parse_file(path, filter):
106105
if "panic: " in str(lines):
107106
results.setdefault(testname, PANIC)
108107
else:
109-
results.setdefault(testname, MISS)
108+
results.setdefault(testname, MISSING)
110109

111110
return results, outputs
112111

@@ -272,16 +271,19 @@ def format_table(table, columns=None, markdown=False):
272271
for row in table:
273272
write("| " + " | ".join(str(row.get(col, "")).ljust(w) for col, w in zip(columns, widths)) + " |")
274273
else:
275-
fmt = lambda cells: " ".join(str(cell).ljust(w) for cell, w in zip(cells, widths))
276-
write(fmt(columns))
274+
write(fmt(columns, widths))
277275
for ind, row in enumerate(table):
278-
write(fmt([row.get(col, "") for col in columns]))
276+
write(fmt([row.get(col, "") for col in columns], widths))
279277

280278
write("")
281279

282280
return "\n".join(result)
283281

284282

283+
def fmt(cells, widths):
284+
return " ".join(str(cell).ljust(w) for cell, w in zip(cells, widths))
285+
286+
285287
def wrap_in_details(txt, summary):
286288
return f"<details><summary>{summary}</summary>\n\n{txt}\n\n</details>"
287289

tools/gh_report.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,9 @@ def main():
169169
if args.filter_env:
170170
cmd.extend(["--filter-env", args.filter_env])
171171
if args.output:
172-
cmd.append(f"--output")
172+
cmd.append("--output")
173173
if args.markdown:
174-
cmd.append(f"--markdown")
174+
cmd.append("--markdown")
175175
cmd.append(f"{target_dir}")
176176
run(cmd, shell=True)
177177

0 commit comments

Comments
 (0)