From 61d6d4505a8b62e805943ded178db972f710c80c Mon Sep 17 00:00:00 2001 From: Matthieu Caneill Date: Thu, 8 Aug 2024 11:29:45 +0200 Subject: [PATCH] Add "pass" property for models and project --- src/dbt_score/formatters/json_formatter.py | 7 ++++++- tests/formatters/test_json_formatter.py | 5 ++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/dbt_score/formatters/json_formatter.py b/src/dbt_score/formatters/json_formatter.py index 53f41ec..9e6f8b3 100644 --- a/src/dbt_score/formatters/json_formatter.py +++ b/src/dbt_score/formatters/json_formatter.py @@ -7,6 +7,7 @@ "model_foo": { "score": 5.0, "badge": "🥈", + "pass": true, "results": { "rule1": { "result": "OK", @@ -23,6 +24,7 @@ "model_bar": { "score": 0.0, "badge": "🥉", + "pass": false, "results": { "rule1": { "result": "ERR", @@ -33,7 +35,8 @@ }, "project": { "score": 2.5, - "badge": "🥉" + "badge": "🥉", + "pass": false } } """ @@ -65,6 +68,7 @@ def model_evaluated( self._model_results[model.name] = { "score": score.value, "badge": score.badge, + "pass": score.value >= self._config.fail_any_model_under, "results": {}, } for rule, result in results.items(): @@ -93,6 +97,7 @@ def project_evaluated(self, score: Score) -> None: self._project_results = { "score": score.value, "badge": score.badge, + "pass": score.value >= self._config.fail_project_under, } document = { "models": self._model_results, diff --git a/tests/formatters/test_json_formatter.py b/tests/formatters/test_json_formatter.py index 2ec055b..696d746 100644 --- a/tests/formatters/test_json_formatter.py +++ b/tests/formatters/test_json_formatter.py @@ -26,6 +26,7 @@ def test_json_formatter( formatter.model_evaluated(model1, results, Score(10.0, "🥇")) formatter.project_evaluated(Score(10.0, "🥇")) stdout = capsys.readouterr().out + print() assert ( stdout == """{ @@ -33,6 +34,7 @@ def test_json_formatter( "model1": { "score": 10.0, "badge": "🥇", + "pass": true, "results": { "tests.conftest.rule_severity_low": { "result": "OK", @@ -54,7 +56,8 @@ def test_json_formatter( }, "project": { "score": 10.0, - "badge": "🥇" + "badge": "🥇", + "pass": true } } """