Skip to content

Commit

Permalink
Remove non-default rules
Browse files Browse the repository at this point in the history
  • Loading branch information
jochemvandooren committed Mar 20, 2024
1 parent 2bf66c5 commit 8256171
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 102 deletions.
97 changes: 0 additions & 97 deletions src/dbt_score/rules/example_rules.py

This file was deleted.

28 changes: 28 additions & 0 deletions src/dbt_score/rules/rules.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""All general rules."""

from dbt_score.models import Model
from dbt_score.rule import RuleViolation, rule


@rule()
def has_description(model: Model) -> RuleViolation | None:
"""A model should have a description."""
if not model.description:
return RuleViolation(message="Model lacks a description.")

return None


@rule()
def columns_have_description(model: Model) -> RuleViolation | None:
"""All columns of a model should have a description."""
invalid_column_names = [
column.name for column in model.columns if not column.description
]
if invalid_column_names:
return RuleViolation(
message=f"The following columns lack a description: "
f"{', '.join(invalid_column_names)}."
)

return None
10 changes: 7 additions & 3 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ def test_manifest(read_text, raw_manifest):
"""Test loading a manifest."""
with patch("dbt_score.models.json.loads", return_value=raw_manifest):
loader = ManifestLoader(Path("manifest.json"))
assert len(loader.models) == len([node for node in
raw_manifest["nodes"].values()
if node["resource_type"] == "model"])
assert len(loader.models) == len(
[
node
for node in raw_manifest["nodes"].values()
if node["resource_type"] == "model"
]
)
assert loader.models[0].tests[0].name == "test2"
assert loader.models[0].columns[0].tests[0].name == "test1"
7 changes: 5 additions & 2 deletions tests/test_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ def assertions(rule_instance):
assert rule_instance.severity == Severity.MEDIUM
assert rule_instance.description == "Description of the rule."
assert rule_instance.evaluate(model1) == RuleViolation(
message="Model1 is a violation.")
message="Model1 is a violation."
)
assert rule_instance.evaluate(model2) is None

assertions(decorator_rule_instance)
Expand All @@ -25,6 +26,7 @@ def assertions(rule_instance):
def test_missing_description_rule_class():
"""Test missing description in rule class."""
with pytest.raises(TypeError):

class BadRule(Rule):
"""Bad example rule."""

Expand All @@ -35,12 +37,13 @@ def evaluate(self, model: Model) -> RuleViolation | None:

def test_missing_evaluate_rule_class(model1):
"""Test missing evaluate implementation in rule class."""

class BadRule(Rule):
"""Bad example rule."""

description = "Description of the rule."

rule = BadRule()

with pytest.raises(NotImplementedError):
rule.evaluate(model1)

0 comments on commit 8256171

Please sign in to comment.