Skip to content

Commit

Permalink
chore: nits and PEP8 style
Browse files Browse the repository at this point in the history
Signed-off-by: Niccolò Fei <[email protected]>
  • Loading branch information
NiccoloFei committed Jun 3, 2024
1 parent 1efaaef commit e5c482b
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions summarize_test_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def track_time_taken(test_results, test_times, suite_times):
if duration < test_times["min"][name]:
test_times["min"][name] = duration

# track suite time.
# Track test suite timings.
# For each platform-matrix branch, track the earliest start and the latest end
platform = test_results["platform"]
if platform not in suite_times["start_time"]:
Expand Down Expand Up @@ -261,7 +261,7 @@ def count_bucketed_by_code(test_results, by_failing_code):
name = test_results["name"]
if test_results["error"] == "" or test_results["state"] == "ignoreFailed":
return
# it does not make sense to show failing code that is outside of the test
# it does not make sense to show failing code that is outside the test,
# so we skip special failures
if not is_normal_failure(test_results):
return
Expand Down Expand Up @@ -493,13 +493,13 @@ def compile_overview(summary):


def metric_name(metric):
metric_name = {
metric_type = {
"by_test": "Tests",
"by_k8s": "Kubernetes versions",
"by_postgres": "Postgres versions",
"by_platform": "Platforms",
}
return metric_name[metric]
return metric_type[metric]


def compute_systematic_failures_on_metric(summary, metric, embed=True):
Expand All @@ -510,7 +510,7 @@ def compute_systematic_failures_on_metric(summary, metric, embed=True):
The `embed` argument controls the output. If True (default) it computes the full list
of alerts for the metric. If False, it will cap at 2 rows with alerts, so as not to
to flood the chatops client.
flood the ChatOps client.
"""
output = ""
has_systematic_failure_in_metric = False
Expand Down Expand Up @@ -587,7 +587,7 @@ def format_alerts(summary, embed=True, file_out=None):
def compute_semaphore(success_percent, embed=True):
"""create a semaphore light summarizing the success percent.
If set to `embed`, an emoji will be used. Else, a textual representation
of a slackmoji is used.
of a Slack emoji is used.
"""
if embed:
if success_percent >= 95:
Expand Down Expand Up @@ -617,7 +617,8 @@ def compute_thermometer_on_metric(summary, metric, embed=True):
runs = summary[metric]["total"][bucket]
success_percent = (1 - failures / runs) * 100
color = compute_semaphore(success_percent, embed)
output += f"- {color} - {bucket}: {round(success_percent,1)}% success.\t({failures} out of {runs} tests failed)\n"
output += f"- {color} - {bucket}: {round(success_percent, 1)}% success.\t"
output += f"({failures} out of {runs} tests failed)\n"
output += f"\n"
return output

Expand Down Expand Up @@ -787,7 +788,7 @@ def format_by_code(summary, structure, file_out=None):

for bucket in sorted_by_code:
tests = ", ".join(summary["by_code"]["tests"][bucket].keys())
# replace newlines and pipes to avoid interference with markdown tables
# replace newlines and pipes to avoid interference with Markdown tables
errors = (
summary["by_code"]["errors"][bucket]
.replace("\n", "<br />")
Expand Down Expand Up @@ -1121,8 +1122,8 @@ def format_short_test_summary(summary, file_out=None):
format_test_summary(test_summary, file_out=f)
if args.limit:
print("with GITHUB_STEP_SUMMARY limit", args.limit)
bytes = os.stat(os.getenv("GITHUB_STEP_SUMMARY")).st_size
if bytes > args.limit:
summary_bytes = os.stat(os.getenv("GITHUB_STEP_SUMMARY")).st_size
if summary_bytes > args.limit:
# we re-open the STEP_SUMMARY with "w" to wipe out previous content
with open(os.getenv("GITHUB_STEP_SUMMARY"), "w") as f:
format_short_test_summary(test_summary, file_out=f)
Expand Down

0 comments on commit e5c482b

Please sign in to comment.