|
1 | | -import datetime |
2 | 1 | import typing as t |
3 | 2 | from collections import Counter |
4 | 3 |
|
|
26 | 25 | SnapshotInfoLike, |
27 | 26 | SnapshotTableInfo, |
28 | 27 | ) |
29 | | -from sqlmesh.utils.date import TimeLike, to_date, to_ds, to_timestamp, yesterday |
| 28 | +from sqlmesh.utils.date import TimeLike, to_date, to_ds, to_timestamp |
| 29 | +from tests.conftest import SushiDataValidator |
30 | 30 |
|
31 | 31 |
|
32 | 32 | @pytest.fixture(autouse=True) |
@@ -655,18 +655,15 @@ def test_multi(mocker): |
655 | 655 |
|
656 | 656 | @pytest.mark.integration |
657 | 657 | @pytest.mark.core_integration |
658 | | -def test_incremental_time_self_reference(mocker: MockerFixture, sushi_context: Context): |
| 658 | +def test_incremental_time_self_reference( |
| 659 | + mocker: MockerFixture, sushi_context: Context, sushi_data_validator: SushiDataValidator |
| 660 | +): |
| 661 | + start_date, end_date = to_date("1 week ago"), to_date("yesterday") |
659 | 662 | df = sushi_context.engine_adapter.fetchdf("SELECT MIN(ds) FROM sushi.customer_revenue_lifetime") |
660 | | - assert df.iloc[0, 0] == to_ds("1 week ago") |
| 663 | + assert df.iloc[0, 0] == to_ds(start_date) |
661 | 664 | df = sushi_context.engine_adapter.fetchdf("SELECT MAX(ds) FROM sushi.customer_revenue_lifetime") |
662 | | - assert df.iloc[0, 0] == to_ds("yesterday") |
663 | | - query_get_date_and_count = "SELECT ds, count(*) AS the_count FROM sushi.customer_revenue_lifetime group by 1 order by 2 desc, 1 desc" |
664 | | - results = sushi_context.engine_adapter.fetchdf(query_get_date_and_count).to_dict() |
665 | | - # Validate that both rows increase over time and all days are present |
666 | | - assert len(results["ds"]) == 7 |
667 | | - assert list(results["ds"].values()) == [ |
668 | | - to_ds(yesterday() - datetime.timedelta(days=x)) for x in range(7) |
669 | | - ] |
| 665 | + assert df.iloc[0, 0] == to_ds(end_date) |
| 666 | + results = sushi_data_validator.validate("sushi.customer_revenue_lifetime", start_date, end_date) |
670 | 667 | plan = sushi_context.plan( |
671 | 668 | restate_models=["sushi.customer_revenue_lifetime", "sushi.customer_revenue_by_day"], |
672 | 669 | no_prompts=True, |
@@ -709,7 +706,9 @@ def test_incremental_time_self_reference(mocker: MockerFixture, sushi_context: C |
709 | 706 | "sushi.customer_revenue_by_day": 1, |
710 | 707 | } |
711 | 708 | # Validate that the results are the same as before the restate |
712 | | - assert results == sushi_context.engine_adapter.fetchdf(query_get_date_and_count).to_dict() |
| 709 | + assert results == sushi_data_validator.validate( |
| 710 | + "sushi.customer_revenue_lifetime", start_date, end_date |
| 711 | + ) |
713 | 712 |
|
714 | 713 |
|
715 | 714 | def initial_add(context: Context, environment: str): |
|
0 commit comments