Skip to content

Commit

Permalink
Make wip a Badge
Browse files Browse the repository at this point in the history
  • Loading branch information
jochemvandooren committed May 30, 2024
1 parent f0fd9b5 commit a98c6ee
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 15 deletions.
11 changes: 6 additions & 5 deletions src/dbt_score/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class BadgeConfig:
third: Badge = field(default_factory=lambda: Badge("🥉", 6.0))
second: Badge = field(default_factory=lambda: Badge("🥈", 8.0))
first: Badge = field(default_factory=lambda: Badge("🥇", 10.0))
wip_icon: str = "🚧"
wip: Badge = field(default_factory=lambda: Badge("🚧", 0.0))

@classmethod
def load_from_dict(cls, badge_config: dict[str, Any]) -> "BadgeConfig":
Expand All @@ -42,10 +42,11 @@ def load_from_dict(cls, badge_config: dict[str, Any]) -> "BadgeConfig":
badge_defaults = asdict(default_badge_config.__getattribute__(badge))
badge_defaults.update(badge_options)
options[badge] = Badge(**badge_defaults)
# The wip icon is not a dictionary
# and is not a Badge object
elif badge == "wip_icon":
options[badge] = badge_options

if badge == "wip" and badge_options.get("threshold"):
raise AttributeError(
"wip badge cannot have a threshold configuration."
)
else:
raise AttributeError(
f"Invalid config for badge: {badge}, must be a dictionary."
Expand Down
2 changes: 1 addition & 1 deletion src/dbt_score/scoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,4 @@ def _badge(self, score: float) -> str:
elif score >= self._config.badge_config.third.threshold:
return self._config.badge_config.third.icon
else:
return self._config.badge_config.wip_icon
return self._config.badge_config.wip.icon
13 changes: 9 additions & 4 deletions tests/resources/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@ rule_namespaces = ["foo", "tests"]
disabled_rules = ["foo.foo", "tests.bar"]

[tool.dbt-score.badges]
wip_icon = "🏗️"
third.threshold = 6.0
third.icon = "🥉"
wip.icon = "🏗️"
third.threshold = 6.5
third.icon = "3️⃣"

[tool.dbt-score.badges.second]
threshold = 7.0
threshold = 7.5
icon = "2️⃣"

[tool.dbt-score.badges.first]
threshold = 9.5
icon = "1️⃣"

[tool.dbt-score.rules."foo.bar"]
severity=4
Expand Down
11 changes: 7 additions & 4 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ def test_load_valid_toml_file(valid_config_path):
config.rules_config["tests.rules.example.rule_test_example"].severity
== Severity.CRITICAL
)
assert config.badge_config.third.threshold == 6.0
assert config.badge_config.second.threshold == 7.0
assert config.badge_config.first.threshold == 10.0
assert config.badge_config.wip_icon == "🏗️"
assert config.badge_config.third.threshold == 6.5
assert config.badge_config.second.threshold == 7.5
assert config.badge_config.first.threshold == 9.5
assert config.badge_config.wip.icon == "🏗️"
assert config.badge_config.third.icon == "3️⃣"
assert config.badge_config.second.icon == "2️⃣"
assert config.badge_config.first.icon == "1️⃣"


def test_load_invalid_toml_file(caplog, invalid_config_path):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_scoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,4 @@ def test_scorer_badge(default_config):
assert scorer._badge(10.0) == scorer._config.badge_config.first.icon
assert scorer._badge(8.0) == scorer._config.badge_config.second.icon
assert scorer._badge(7.0) == scorer._config.badge_config.third.icon
assert scorer._badge(1.0) == scorer._config.badge_config.wip_icon
assert scorer._badge(1.0) == scorer._config.badge_config.wip.icon

0 comments on commit a98c6ee

Please sign in to comment.