Skip to content

Commit 2d75fd9

Browse files
committed
PR Feedback 2
1 parent eade157 commit 2d75fd9

3 files changed

Lines changed: 46 additions & 42 deletions

File tree

sqlmesh/core/console.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3204,10 +3204,12 @@ def update_snapshot_evaluation_progress(
32043204
num_audits_failed: int,
32053205
audit_only: bool = False,
32063206
) -> None:
3207+
view_name, loaded_batches = self.evaluation_batch_progress[snapshot.snapshot_id]
3208+
32073209
if audit_only:
3210+
print(f"Completed Auditing {view_name}")
32083211
return
32093212

3210-
view_name, loaded_batches = self.evaluation_batch_progress[snapshot.snapshot_id]
32113213
total_batches = self.evaluation_model_batch_sizes[snapshot]
32123214

32133215
loaded_batches += 1

tests/core/test_context.py

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from datetime import date, timedelta
66
from tempfile import TemporaryDirectory
77
from unittest.mock import PropertyMock, call, patch
8-
from IPython.utils.capture import capture_output
98

109
import time_machine
1110
import pytest
@@ -2072,42 +2071,3 @@ def test_audit():
20722071
context.plan(no_prompts=True, auto_apply=True)
20732072

20742073
assert context.audit(models=["dummy"], start="2020-01-01", end="2020-01-01") is True
2075-
2076-
2077-
@use_terminal_console
2078-
def test_audits_running_on_metadata_changes(tmp_path: pathlib.Path):
2079-
def setup_senario(model_before: str, model_after: str):
2080-
models_dir = pathlib.Path("models")
2081-
create_temp_file(tmp_path, pathlib.Path(models_dir, "test.sql"), model_before)
2082-
2083-
# Create first snapshot
2084-
context = Context(paths=tmp_path, config=Config())
2085-
context.plan("prod", no_prompts=True, auto_apply=True)
2086-
2087-
# Create second (metadata) snapshot
2088-
create_temp_file(tmp_path, pathlib.Path(models_dir, "test.sql"), model_after)
2089-
context.load()
2090-
2091-
with capture_output() as output:
2092-
with pytest.raises(PlanError):
2093-
context.plan("prod", no_prompts=True, auto_apply=True)
2094-
2095-
assert 'Failed models\n\n "model"' in output.stdout
2096-
2097-
return output
2098-
2099-
# Ensure incorrect audits (bad data, incorrect definition etc) are evaluated immediately
2100-
output = setup_senario(
2101-
"MODEL (name model); SELECT NULL AS col",
2102-
"MODEL (name model, audits (not_null(columns=[col]))); SELECT NULL AS col",
2103-
)
2104-
assert "'not_null' audit error: 1 row failed" in output.stdout
2105-
2106-
output = setup_senario(
2107-
"MODEL (name model); SELECT NULL AS col",
2108-
"MODEL (name model, audits (not_null(columns=[this_col_does_not_exist]))); SELECT NULL AS col",
2109-
)
2110-
assert (
2111-
'Binder Error: Referenced column "this_col_does_not_exist" not found in \nFROM clause!'
2112-
in output.stdout
2113-
)

tests/core/test_integration.py

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
from sqlglot import exp
2020
from sqlglot.expressions import DataType
2121
import re
22+
from IPython.utils.capture import capture_output
23+
2224

2325
from sqlmesh import CustomMaterialization
2426
from sqlmesh.cli.example_project import init_example_project
@@ -62,10 +64,11 @@
6264
SnapshotTableInfo,
6365
)
6466
from sqlmesh.utils.date import TimeLike, now, to_date, to_datetime, to_timestamp
65-
from sqlmesh.utils.errors import NoChangesPlanError, SQLMeshError
67+
from sqlmesh.utils.errors import NoChangesPlanError, SQLMeshError, PlanError
6668
from sqlmesh.utils.pydantic import validate_string
6769
from tests.conftest import DuckDBMetadata, SushiDataValidator
6870
from tests.utils.test_helpers import use_terminal_console
71+
from tests.utils.test_filesystem import create_temp_file
6972

7073
if t.TYPE_CHECKING:
7174
from sqlmesh import QueryOrDF
@@ -5922,3 +5925,42 @@ def setup_scenario():
59225925

59235926
# - Check that the environment record does not exist in the state sync anymore
59245927
assert not ctx.state_sync.get_environment("dev")
5928+
5929+
5930+
@use_terminal_console
5931+
def test_audits_running_on_metadata_changes(tmp_path: Path):
5932+
def setup_senario(model_before: str, model_after: str):
5933+
models_dir = Path("models")
5934+
create_temp_file(tmp_path, models_dir / "test.sql", model_before)
5935+
5936+
# Create first snapshot
5937+
context = Context(paths=tmp_path, config=Config())
5938+
context.plan("prod", no_prompts=True, auto_apply=True)
5939+
5940+
# Create second (metadata) snapshot
5941+
create_temp_file(tmp_path, models_dir / "test.sql", model_after)
5942+
context.load()
5943+
5944+
with capture_output() as output:
5945+
with pytest.raises(PlanError):
5946+
context.plan("prod", no_prompts=True, auto_apply=True)
5947+
5948+
assert 'Failed models\n\n "model"' in output.stdout
5949+
5950+
return output
5951+
5952+
# Ensure incorrect audits (bad data, incorrect definition etc) are evaluated immediately
5953+
output = setup_senario(
5954+
"MODEL (name model); SELECT NULL AS col",
5955+
"MODEL (name model, audits (not_null(columns=[col]))); SELECT NULL AS col",
5956+
)
5957+
assert "'not_null' audit error: 1 row failed" in output.stdout
5958+
5959+
output = setup_senario(
5960+
"MODEL (name model); SELECT NULL AS col",
5961+
"MODEL (name model, audits (not_null(columns=[this_col_does_not_exist]))); SELECT NULL AS col",
5962+
)
5963+
assert (
5964+
'Binder Error: Referenced column "this_col_does_not_exist" not found in \nFROM clause!'
5965+
in output.stdout
5966+
)

0 commit comments

Comments
 (0)