Skip to content

Commit 5da8a11

Browse files
authored
Chore: Add integration test for the plan explantation mode (#4657)
1 parent 2a4f549 commit 5da8a11

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

tests/core/test_integration.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import pandas as pd # noqa: TID253
1313
import pytest
1414
from pathlib import Path
15+
from sqlmesh.core.console import set_console, get_console, TerminalConsole
1516
from sqlmesh.core.config.naming import NameInferenceConfig
1617
from sqlmesh.utils.concurrency import NodeExecutionFailedError
1718
import time_machine
@@ -4330,6 +4331,49 @@ def test_indirect_non_breaking_view_is_updated_with_new_table_references(
43304331
assert row_num > 0
43314332

43324333

4334+
@time_machine.travel("2023-01-08 15:00:00 UTC")
4335+
def test_plan_explain(init_and_plan_context: t.Callable):
4336+
old_console = get_console()
4337+
set_console(TerminalConsole())
4338+
4339+
context, plan = init_and_plan_context("examples/sushi")
4340+
context.apply(plan)
4341+
4342+
waiter_revenue_by_day_model = context.get_model("sushi.waiter_revenue_by_day")
4343+
waiter_revenue_by_day_model = add_projection_to_model(
4344+
t.cast(SqlModel, waiter_revenue_by_day_model)
4345+
)
4346+
context.upsert_model(waiter_revenue_by_day_model)
4347+
4348+
waiter_revenue_by_day_snapshot = context.get_snapshot(waiter_revenue_by_day_model.name)
4349+
top_waiters_snapshot = context.get_snapshot("sushi.top_waiters")
4350+
4351+
common_kwargs = dict(skip_tests=True, no_prompts=True, explain=True)
4352+
4353+
# For now just making sure the plan doesn't error
4354+
context.plan("dev", **common_kwargs)
4355+
context.plan("dev", **common_kwargs, skip_backfill=True)
4356+
context.plan("dev", **common_kwargs, empty_backfill=True)
4357+
context.plan("dev", **common_kwargs, forward_only=True, enable_preview=True)
4358+
context.plan("prod", **common_kwargs)
4359+
context.plan("prod", **common_kwargs, forward_only=True)
4360+
context.plan("prod", **common_kwargs, restate_models=[waiter_revenue_by_day_model.name])
4361+
4362+
set_console(old_console)
4363+
4364+
# Make sure that the now changes were actually applied
4365+
for target_env in ("dev", "prod"):
4366+
plan = context.plan_builder(target_env, skip_tests=True).build()
4367+
assert plan.has_changes
4368+
assert plan.missing_intervals
4369+
assert plan.directly_modified == {waiter_revenue_by_day_snapshot.snapshot_id}
4370+
assert len(plan.new_snapshots) == 2
4371+
assert {s.snapshot_id for s in plan.new_snapshots} == {
4372+
waiter_revenue_by_day_snapshot.snapshot_id,
4373+
top_waiters_snapshot.snapshot_id,
4374+
}
4375+
4376+
43334377
@time_machine.travel("2023-01-08 15:00:00 UTC")
43344378
def test_dbt_requirements(sushi_dbt_context: Context):
43354379
assert set(sushi_dbt_context.requirements) == {"dbt-core", "dbt-duckdb"}

0 commit comments

Comments
 (0)