Skip to content

Commit 6bc5523

Browse files
committed
figured out context to complete test
1 parent a56df3d commit 6bc5523

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

sqlmesh/core/linter/rules/builtin.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from __future__ import annotations
44

55
import typing as t
6-
from pathlib import Path
76

87
from ruamel.yaml import YAML
98
from sqlglot.expressions import Star
@@ -139,7 +138,7 @@ def check_model(self, model: Model) -> t.Optional[RuleViolation]:
139138
if isinstance(model, ExternalModel):
140139
return None
141140

142-
test_dir = Path("tests")
141+
test_dir = self.context.path / "tests"
143142
found_test = False
144143

145144
yaml_parser = YAML(typ="safe")
@@ -151,7 +150,6 @@ def check_model(self, model: Model) -> t.Optional[RuleViolation]:
151150
continue
152151

153152
for _, test_config in test_data.items():
154-
print(f"Test_Config: {test_config}")
155153
if test_config.get("model") == model.name:
156154
found_test = True
157155
break

tests/core/linter/test_builtin.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,23 @@ def test_no_missing_unit_tests(tmp_path, copy_to_temp_path):
212212

213213
# Lint the models
214214
lints = context.lint_models(raise_on_error=False)
215-
assert 1 == 1
216-
# assert len(lints) >= 1
217-
# lint = lints[0]
218-
# assert lint.violation_range is None
219-
# print(lints)
215+
216+
# Should have violations for models without tests (most models except customers)
217+
assert len(lints) >= 1
218+
219+
# Check that we get violations for models without tests
220+
violation_messages = [lint.violation_msg for lint in lints]
221+
assert any("is missing unit test(s)" in msg for msg in violation_messages)
222+
223+
# Check that models with existing tests don't have violations
224+
models_with_tests = ["customer_revenue_by_day", "customer_revenue_lifetime", "order_items"]
225+
226+
for model_name in models_with_tests:
227+
model_violations = [
228+
lint
229+
for lint in lints
230+
if model_name in lint.violation_msg and "is missing unit test(s)" in lint.violation_msg
231+
]
232+
assert len(model_violations) == 0, (
233+
f"Model {model_name} should not have a violation since it has a test"
234+
)

0 commit comments

Comments
 (0)