|
15 | 15 | SnapshotFingerprint, |
16 | 16 | ) |
17 | 17 | from sqlmesh.utils.dag import DAG |
18 | | -from sqlmesh.utils.date import now, to_date, to_ds, to_timestamp |
| 18 | +from sqlmesh.utils.date import now, to_date, to_datetime, to_timestamp |
19 | 19 | from sqlmesh.utils.errors import PlanError |
20 | 20 |
|
21 | 21 |
|
@@ -63,8 +63,8 @@ def test_forward_only_dev(make_snapshot, mocker: MockerFixture): |
63 | 63 | ) |
64 | 64 |
|
65 | 65 | expected_start = to_date("2022-01-01") |
66 | | - expected_end = to_date("2022-01-02") |
67 | | - expected_interval_end = to_timestamp(to_date("2022-01-03")) |
| 66 | + expected_end = to_date("2022-01-03") |
| 67 | + expected_interval_end = to_timestamp(to_date("2022-01-04")) |
68 | 68 |
|
69 | 69 | context_diff_mock = mocker.Mock() |
70 | 70 | context_diff_mock.snapshots = {"a": snapshot_a} |
@@ -342,6 +342,12 @@ def test_start_inference(make_snapshot, mocker: MockerFixture): |
342 | 342 | assert plan.missing_intervals[0].snapshot_name == snapshot_a.name |
343 | 343 | assert plan.start == to_timestamp("2022-01-01") |
344 | 344 |
|
| 345 | + # Test inference from existing intervals |
| 346 | + context_diff_mock.snapshots = {"b": snapshot_b} |
| 347 | + plan = Plan(context_diff_mock) |
| 348 | + assert not plan.missing_intervals |
| 349 | + assert plan.start == to_datetime("2022-01-01") |
| 350 | + |
345 | 351 |
|
346 | 352 | def test_auto_categorization(make_snapshot, mocker: MockerFixture): |
347 | 353 | snapshot = make_snapshot(SqlModel(name="a", query=parse_one("select 1, ds"))) |
@@ -394,33 +400,6 @@ def test_auto_categorization_missing_schema_downstream(make_snapshot, mocker: Mo |
394 | 400 | assert updated_snapshot.change_category == SnapshotChangeCategory.BREAKING |
395 | 401 |
|
396 | 402 |
|
397 | | -def test_end_from_missing_instead_of_now(make_snapshot, mocker: MockerFixture): |
398 | | - snapshot_a = make_snapshot( |
399 | | - SqlModel( |
400 | | - name="a", |
401 | | - query=parse_one("select 1, ds"), |
402 | | - kind=IncrementalByTimeRangeKind(time_column="ds"), |
403 | | - ) |
404 | | - ) |
405 | | - |
406 | | - context_diff_mock = mocker.Mock() |
407 | | - context_diff_mock.snapshots = {"a": snapshot_a} |
408 | | - context_diff_mock.added = set() |
409 | | - context_diff_mock.removed_snapshots = set() |
410 | | - context_diff_mock.modified_snapshots = {} |
411 | | - context_diff_mock.new_snapshots = {snapshot_a.snapshot_id: snapshot_a} |
412 | | - |
413 | | - start_mock = mocker.patch("sqlmesh.core.snapshot.definition.earliest_start_date") |
414 | | - start_mock.return_value = to_ds("2022-01-01") |
415 | | - now_mock = mocker.patch("sqlmesh.core.plan.definition.now") |
416 | | - now_mock.return_value = to_ds("2022-01-30") |
417 | | - snapshot_a.add_interval("2022-01-01", "2022-01-05") |
418 | | - |
419 | | - plan = Plan(context_diff_mock, is_dev=True) |
420 | | - assert plan.start == to_timestamp("2022-01-06") |
421 | | - assert plan.end == to_date("2022-01-29") |
422 | | - |
423 | | - |
424 | 403 | def test_broken_references(make_snapshot, mocker: MockerFixture): |
425 | 404 | snapshot_b = make_snapshot(SqlModel(name="b", query=parse_one("select 2, ds FROM a"))) |
426 | 405 | snapshot_b.categorize_as(SnapshotChangeCategory.BREAKING) |
|
0 commit comments