Commit c4ca29c7 authored by Ben Gamari's avatar Ben Gamari 🐢 Committed by Marge Bot

testsuite: Use colors more consistently

parent 92a52aaa
......@@ -23,6 +23,7 @@ from collections import namedtuple
from math import ceil, trunc
from testutil import passed, failBecause, testing_metrics
from term_color import Color, colored
from my_typing import *
......@@ -82,6 +83,15 @@ class MetricChange(Enum):
# The metric decreased.
Decrease = 'Decrease'
def __str__(self):
strings = {
MetricChange.NewMetric: colored(Color.BLUE, "new"),
MetricChange.NoChange: colored(Color.WHITE, "unchanged"),
MetricChange.Increase: colored(Color.RED, "increased"),
MetricChange.Decrease: colored(Color.GREEN, "decreased")
}
return strings[self]
AllowedPerfChange = NamedTuple('AllowedPerfChange',
[('direction', MetricChange),
('metrics', List[str]),
......@@ -562,7 +572,7 @@ def check_stats_change(actual: PerfStat,
# Print errors and create pass/fail object.
result = passed()
if not change_allowed:
error = change.value + ' from ' + baseline.perfStat.test_env + \
error = str(change) + ' from ' + baseline.perfStat.test_env + \
' baseline @ HEAD~' + str(baseline.commitDepth)
print(actual.metric, error + ':')
result = failBecause('stat ' + error, tag='stat')
......
......@@ -335,13 +335,6 @@ def cleanup_and_exit(exitcode):
exit(exitcode)
def tabulate_metrics(metrics: List[PerfMetric]) -> None:
direction_strings = {
MetricChange.NewMetric: colored(Color.BLUE, "new"),
MetricChange.NoChange: colored(Color.WHITE, "unchanged"),
MetricChange.Increase: colored(Color.RED, "increased"),
MetricChange.Decrease: colored(Color.GREEN, "decreased")
}
for metric in sorted(metrics, key=lambda m: (m.stat.test, m.stat.way)):
print("{test:24} {metric:40} {value:15.3f}".format(
test = "{}({})".format(metric.stat.test, metric.stat.way),
......@@ -357,7 +350,7 @@ def tabulate_metrics(metrics: List[PerfMetric]) -> None:
herald = "(baseline @ HEAD~{depth})".format(
depth = metric.baseline.commitDepth),
value = val0,
direction = direction_strings[metric.change],
direction = metric.change,
rel = abs(rel)
))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment