-
Notifications
You must be signed in to change notification settings - Fork 374
Expand file tree
/
Copy pathtest_plan_evaluator.py
More file actions
84 lines (71 loc) · 2.93 KB
/
test_plan_evaluator.py
File metadata and controls
84 lines (71 loc) · 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import pytest
from pytest_mock.plugin import MockerFixture
from sqlglot import parse_one
from sqlmesh.core.context import Context
from sqlmesh.core.model import FullKind, SqlModel, ViewKind
from sqlmesh.core.plan import (
BuiltInPlanEvaluator,
Plan,
PlanBuilder,
stages as plan_stages,
)
from sqlmesh.core.snapshot import SnapshotChangeCategory
@pytest.fixture
def sushi_plan(sushi_context: Context, mocker: MockerFixture) -> Plan:
mock_prompt = mocker.Mock()
mock_prompt.ask.return_value = "2022-01-01"
mocker.patch("sqlmesh.core.console.Prompt", mock_prompt)
return PlanBuilder(
sushi_context._context_diff("dev"),
is_dev=True,
include_unmodified=True,
).build()
@pytest.mark.slow
def test_builtin_evaluator_push(sushi_context: Context, make_snapshot):
new_model = SqlModel(
name="sushi.new_test_model",
kind=FullKind(),
owner="jen",
cron="@daily",
start="2020-01-01",
query=parse_one("SELECT 1::INT AS one"),
default_catalog="memory",
)
new_view_model = SqlModel(
name="sushi.new_test_view_model",
kind=ViewKind(),
owner="jen",
start="2020-01-01",
query=parse_one("SELECT 1::INT AS one FROM sushi.new_test_model, sushi.waiters"),
default_catalog="memory",
)
sushi_context.upsert_model(new_model)
sushi_context.upsert_model(new_view_model)
new_model_snapshot = sushi_context.get_snapshot(new_model, raise_if_missing=True)
new_view_model_snapshot = sushi_context.get_snapshot(new_view_model, raise_if_missing=True)
new_model_snapshot.categorize_as(SnapshotChangeCategory.BREAKING)
new_view_model_snapshot.categorize_as(SnapshotChangeCategory.BREAKING)
plan = PlanBuilder(sushi_context._context_diff("prod")).build()
evaluator = BuiltInPlanEvaluator(
sushi_context.state_sync,
sushi_context.snapshot_evaluator,
sushi_context.create_scheduler,
sushi_context.default_catalog,
console=sushi_context.console,
)
evaluatable_plan = plan.to_evaluatable()
stages = plan_stages.build_plan_stages(
evaluatable_plan, sushi_context.state_sync, sushi_context.default_catalog
)
assert isinstance(stages[1], plan_stages.CreateSnapshotRecordsStage)
evaluator.visit_create_snapshot_records_stage(stages[1], evaluatable_plan)
assert isinstance(stages[2], plan_stages.PhysicalLayerSchemaCreationStage)
evaluator.visit_physical_layer_schema_creation_stage(stages[2], evaluatable_plan)
assert isinstance(stages[3], plan_stages.BackfillStage)
evaluator.visit_backfill_stage(stages[3], evaluatable_plan)
assert (
len(sushi_context.state_sync.get_snapshots([new_model_snapshot, new_view_model_snapshot]))
== 2
)
assert sushi_context.engine_adapter.table_exists(new_model_snapshot.table_name())
assert sushi_context.engine_adapter.table_exists(new_view_model_snapshot.table_name())