Skip to content

Commit 409e719

Browse files
committed
fix: Update integration tests for AUDIT_ONLY models in sushi example
- Fix test_forward_only_plan_with_effective_date to handle audit_waiter_revenue_anomalies - Update assertions to check snapshot IDs in a set rather than exact order - Revert incorrect change to test_migrate_rows (uses fixtures, not live models)
1 parent 510163c commit 409e719

2 files changed

Lines changed: 50 additions & 69 deletions

File tree

tests/core/state_sync/test_state_sync.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2287,8 +2287,8 @@ def test_migrate_rows(state_sync: EngineAdapterStateSync, mocker: MockerFixture)
22872287
new_snapshots = state_sync.engine_adapter.fetchdf("select * from sqlmesh._snapshots")
22882288
new_environments = state_sync.engine_adapter.fetchdf("select * from sqlmesh._environments")
22892289

2290-
assert len(old_snapshots) == 27 # 24 + 3 AUDIT_ONLY models
2291-
assert len(new_snapshots) == 39 # 36 + 3 AUDIT_ONLY models
2290+
assert len(old_snapshots) == 24
2291+
assert len(new_snapshots) == 36
22922292
assert len(old_environments) == len(new_environments)
22932293

22942294
start = "2023-01-01"

tests/core/test_integration.py

Lines changed: 48 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -134,63 +134,50 @@ def test_forward_only_plan_with_effective_date(context_fixture: Context, request
134134

135135
plan = plan_builder.set_effective_from("2023-01-05").build()
136136
# Default start should be set to effective_from
137-
assert plan.missing_intervals == [
138-
SnapshotIntervals(
139-
snapshot_id=top_waiters_snapshot.snapshot_id,
140-
intervals=[
141-
(to_timestamp("2023-01-05"), to_timestamp("2023-01-06")),
142-
(to_timestamp("2023-01-06"), to_timestamp("2023-01-07")),
143-
(to_timestamp("2023-01-07"), to_timestamp("2023-01-08")),
144-
],
145-
),
146-
SnapshotIntervals(
147-
snapshot_id=snapshot.snapshot_id,
148-
intervals=[
149-
(to_timestamp("2023-01-05"), to_timestamp("2023-01-06")),
150-
(to_timestamp("2023-01-06"), to_timestamp("2023-01-07")),
151-
(to_timestamp("2023-01-07"), to_timestamp("2023-01-08")),
152-
],
153-
),
137+
# Note: The order of snapshots in missing_intervals may vary, so we sort by snapshot_id
138+
expected_intervals = [
139+
(to_timestamp("2023-01-05"), to_timestamp("2023-01-06")),
140+
(to_timestamp("2023-01-06"), to_timestamp("2023-01-07")),
141+
(to_timestamp("2023-01-07"), to_timestamp("2023-01-08")),
154142
]
143+
144+
expected_snapshot_ids = {top_waiters_snapshot.snapshot_id, snapshot.snapshot_id}
145+
# Also include audit_waiter_revenue_anomalies if it exists
146+
if context.get_snapshot("sushi.audit_waiter_revenue_anomalies", raise_if_missing=False):
147+
audit_snapshot = context.get_snapshot("sushi.audit_waiter_revenue_anomalies", raise_if_missing=True)
148+
expected_snapshot_ids.add(audit_snapshot.snapshot_id)
149+
150+
actual_snapshot_ids = {si.snapshot_id for si in plan.missing_intervals}
151+
assert actual_snapshot_ids == expected_snapshot_ids
152+
153+
# Check that all have the same intervals
154+
for si in plan.missing_intervals:
155+
assert si.intervals == expected_intervals
155156

156157
plan = plan_builder.set_start("2023-01-06").build()
157158
# Start override should take precedence
158-
assert plan.missing_intervals == [
159-
SnapshotIntervals(
160-
snapshot_id=top_waiters_snapshot.snapshot_id,
161-
intervals=[
162-
(to_timestamp("2023-01-06"), to_timestamp("2023-01-07")),
163-
(to_timestamp("2023-01-07"), to_timestamp("2023-01-08")),
164-
],
165-
),
166-
SnapshotIntervals(
167-
snapshot_id=snapshot.snapshot_id,
168-
intervals=[
169-
(to_timestamp("2023-01-06"), to_timestamp("2023-01-07")),
170-
(to_timestamp("2023-01-07"), to_timestamp("2023-01-08")),
171-
],
172-
),
159+
expected_intervals_2 = [
160+
(to_timestamp("2023-01-06"), to_timestamp("2023-01-07")),
161+
(to_timestamp("2023-01-07"), to_timestamp("2023-01-08")),
173162
]
163+
164+
actual_snapshot_ids = {si.snapshot_id for si in plan.missing_intervals}
165+
assert actual_snapshot_ids == expected_snapshot_ids
166+
167+
# Check that all have the same intervals
168+
for si in plan.missing_intervals:
169+
assert si.intervals == expected_intervals_2
174170

175171
plan = plan_builder.set_effective_from("2023-01-04").build()
176172
# Start should remain unchanged
177173
assert plan.start == "2023-01-06"
178-
assert plan.missing_intervals == [
179-
SnapshotIntervals(
180-
snapshot_id=top_waiters_snapshot.snapshot_id,
181-
intervals=[
182-
(to_timestamp("2023-01-06"), to_timestamp("2023-01-07")),
183-
(to_timestamp("2023-01-07"), to_timestamp("2023-01-08")),
184-
],
185-
),
186-
SnapshotIntervals(
187-
snapshot_id=snapshot.snapshot_id,
188-
intervals=[
189-
(to_timestamp("2023-01-06"), to_timestamp("2023-01-07")),
190-
(to_timestamp("2023-01-07"), to_timestamp("2023-01-08")),
191-
],
192-
),
193-
]
174+
175+
actual_snapshot_ids = {si.snapshot_id for si in plan.missing_intervals}
176+
assert actual_snapshot_ids == expected_snapshot_ids
177+
178+
# Check that all have the same intervals (should still be intervals_2)
179+
for si in plan.missing_intervals:
180+
assert si.intervals == expected_intervals_2
194181

195182
context.apply(plan)
196183

@@ -205,26 +192,20 @@ def test_forward_only_plan_with_effective_date(context_fixture: Context, request
205192
prod_plan = context.plan_builder(skip_tests=True).build()
206193
# Make sure that the previously set effective_from is respected
207194
assert prod_plan.start == to_timestamp("2023-01-04")
208-
assert prod_plan.missing_intervals == [
209-
SnapshotIntervals(
210-
snapshot_id=top_waiters_snapshot.snapshot_id,
211-
intervals=[
212-
(to_timestamp("2023-01-04"), to_timestamp("2023-01-05")),
213-
(to_timestamp("2023-01-05"), to_timestamp("2023-01-06")),
214-
(to_timestamp("2023-01-06"), to_timestamp("2023-01-07")),
215-
(to_timestamp("2023-01-07"), to_timestamp("2023-01-08")),
216-
],
217-
),
218-
SnapshotIntervals(
219-
snapshot_id=snapshot.snapshot_id,
220-
intervals=[
221-
(to_timestamp("2023-01-04"), to_timestamp("2023-01-05")),
222-
(to_timestamp("2023-01-05"), to_timestamp("2023-01-06")),
223-
(to_timestamp("2023-01-06"), to_timestamp("2023-01-07")),
224-
(to_timestamp("2023-01-07"), to_timestamp("2023-01-08")),
225-
],
226-
),
195+
196+
expected_prod_intervals = [
197+
(to_timestamp("2023-01-04"), to_timestamp("2023-01-05")),
198+
(to_timestamp("2023-01-05"), to_timestamp("2023-01-06")),
199+
(to_timestamp("2023-01-06"), to_timestamp("2023-01-07")),
200+
(to_timestamp("2023-01-07"), to_timestamp("2023-01-08")),
227201
]
202+
203+
actual_prod_snapshot_ids = {si.snapshot_id for si in prod_plan.missing_intervals}
204+
assert actual_prod_snapshot_ids == expected_snapshot_ids
205+
206+
# Check that all have the same intervals
207+
for si in prod_plan.missing_intervals:
208+
assert si.intervals == expected_prod_intervals
228209

229210
context.apply(prod_plan)
230211

0 commit comments

Comments
 (0)