From cb05ffa5e02d4f9b3879ae6ddb83147824cee1e9 Mon Sep 17 00:00:00 2001 From: Jaime Silvela Date: Thu, 6 Jun 2024 11:56:30 +0200 Subject: [PATCH] chore: improve the temperature cutoff levels (#13) Signed-off-by: Jaime Silvela --- summarize_test_results.py | 35 ++++++++++++++++++++++------------- test_summary.py | 22 +++++++++++++++++++--- 2 files changed, 41 insertions(+), 16 deletions(-) diff --git a/summarize_test_results.py b/summarize_test_results.py index 2a1bc4a..21edfd6 100644 --- a/summarize_test_results.py +++ b/summarize_test_results.py @@ -589,20 +589,29 @@ def compute_semaphore(success_percent, embed=True): If set to `embed`, an emoji will be used. Else, a textual representation of a Slack emoji is used. """ - if embed: - if success_percent >= 95: - return "🟢" - elif success_percent >= 60: - return "🟡" - else: - return "🔴" + levels = { + "good": { + "emoji": "🟢", + "text": ":large_green_circle:", + }, + "average": { + "emoji": "🟡", + "text": ":large_yellow_circle:", + }, + "bad": { + "emoji": "🔴", + "text": ":red_circle:", + }, + } + form = "emoji" + if not embed: + form = "text" + if success_percent >= 99: + return levels["good"][form] + elif success_percent >= 95: + return levels["average"][form] else: - if success_percent >= 95: - return ":large_green_circle:" - elif success_percent >= 60: - return ":large_yellow_circle:" - else: - return ":red_circle:" + return levels["bad"][form] def compute_thermometer_on_metric(summary, metric, embed=True): diff --git a/test_summary.py b/test_summary.py index 128dbd3..5ad5f2e 100644 --- a/test_summary.py +++ b/test_summary.py @@ -69,19 +69,35 @@ def test_compute_summary(self): def test_compute_thermometer(self): self.maxDiff = None - thermometer = summarize_test_results.compute_thermometer_on_metric(self.summary, "by_platform") + thermometer = summarize_test_results.compute_thermometer_on_metric( + self.summary, "by_platform" + ) self.assertEqual( thermometer, "Platforms thermometer:\n\n" - "- 🟡 - local: 66.7% success.\t(1 out of 3 tests failed)\n\n" + "- 🔴 - local: 66.7% success.\t(1 out of 3 tests failed)\n\n", + ) + + thermometerPlaintext = summarize_test_results.compute_thermometer_on_metric( + self.summary, "by_platform", False + ) + + self.assertEqual( + thermometerPlaintext, + "Platforms thermometer:\n\n" + "- :red_circle: - local: 66.7% success.\t(1 out of 3 tests failed)\n\n", ) def test_compute_systematic_failures(self): self.maxDiff = None for metric in ["by_test", "by_k8s", "by_postgres", "by_platform"]: - has_alerts, out = summarize_test_results.compute_systematic_failures_on_metric(self.summary, metric) + has_alerts, out = ( + summarize_test_results.compute_systematic_failures_on_metric( + self.summary, metric + ) + ) self.assertEqual(has_alerts, False) self.assertEqual(out, "")