diff --git a/sqlmesh/core/test/definition.py b/sqlmesh/core/test/definition.py index 00ed93ca6..ae62e9e85 100644 --- a/sqlmesh/core/test/definition.py +++ b/sqlmesh/core/test/definition.py @@ -649,9 +649,7 @@ def runTest(self) -> None: def _execute_model(self) -> pd.DataFrame: """Executes the python model and returns a DataFrame.""" - time_ctx = ( - freeze_time(self._execution_time, tick=False) if self._execution_time else nullcontext() - ) + time_ctx = freeze_time(self._execution_time) if self._execution_time else nullcontext() with patch.dict(self._test_adapter_dialect.generator_class.TRANSFORMS, self._transforms): with t.cast(AbstractContextManager, time_ctx): variables = self.body.get("vars", {}).copy() diff --git a/tests/cli/test_cli.py b/tests/cli/test_cli.py index 52d5abd83..85b4cf087 100644 --- a/tests/cli/test_cli.py +++ b/tests/cli/test_cli.py @@ -14,7 +14,7 @@ from sqlmesh.integrations.dlt import generate_dlt_models from sqlmesh.utils.date import yesterday_ds -FREEZE_TIME = "2023-01-01 00:00:00" +FREEZE_TIME = "2023-01-01 00:00:00 UTC" pytestmark = pytest.mark.slow diff --git a/tests/core/test_context.py b/tests/core/test_context.py index 0c58e7e0f..89ea49e75 100644 --- a/tests/core/test_context.py +++ b/tests/core/test_context.py @@ -850,7 +850,7 @@ def test_plan_default_end(sushi_context_pre_scheduling: Context): @pytest.mark.slow def test_plan_start_ahead_of_end(copy_to_temp_path): path = copy_to_temp_path("examples/sushi") - with time_machine.travel("2024-01-02 00:00:00"): + with time_machine.travel("2024-01-02 00:00:00 UTC"): context = Context(paths=path, gateway="duckdb_persistent") context.plan("prod", no_prompts=True, auto_apply=True) assert all( @@ -858,7 +858,7 @@ def test_plan_start_ahead_of_end(copy_to_temp_path): for i in context.state_sync.max_interval_end_per_model("prod").values() ) context.close() - with time_machine.travel("2024-01-03 00:00:00"): + with time_machine.travel("2024-01-03 00:00:00 UTC"): context = Context(paths=path, gateway="duckdb_persistent") expression = d.parse( """ diff --git a/tests/core/test_integration.py b/tests/core/test_integration.py index 319bdbf84..5e44c59c7 100644 --- a/tests/core/test_integration.py +++ b/tests/core/test_integration.py @@ -75,7 +75,7 @@ def plan_choice(plan_builder: PlanBuilder, choice: SnapshotChangeCategory) -> No plan_builder.set_choice(snapshot, choice) -@time_machine.travel("2023-01-08 15:00:00") +@time_machine.travel("2023-01-08 15:00:00 UTC") @pytest.mark.parametrize( "context_fixture", ["sushi_context", "sushi_no_default_catalog"], @@ -215,7 +215,7 @@ def test_forward_only_plan_with_effective_date(context_fixture: Context, request ] -@time_machine.travel("2023-01-08 15:00:00") +@time_machine.travel("2023-01-08 15:00:00 UTC") def test_forward_only_model_regular_plan(init_and_plan_context: t.Callable): context, plan = init_and_plan_context("examples/sushi") context.apply(plan) @@ -308,7 +308,7 @@ def test_forward_only_model_regular_plan(init_and_plan_context: t.Callable): assert not prod_df["event_date"].tolist() -@time_machine.travel("2023-01-08 15:00:00") +@time_machine.travel("2023-01-08 15:00:00 UTC") def test_forward_only_model_regular_plan_preview_enabled(init_and_plan_context: t.Callable): context, plan = init_and_plan_context("examples/sushi") context.apply(plan) @@ -358,7 +358,7 @@ def test_forward_only_model_regular_plan_preview_enabled(init_and_plan_context: assert dev_df["event_date"].tolist() == [pd.to_datetime("2023-01-07")] -@time_machine.travel("2023-01-08 15:00:00") +@time_machine.travel("2023-01-08 15:00:00 UTC") def test_full_history_restatement_model_regular_plan_preview_enabled( init_and_plan_context: t.Callable, ): @@ -431,7 +431,7 @@ def test_full_history_restatement_model_regular_plan_preview_enabled( context.apply(plan) -@time_machine.travel("2023-01-08 15:00:00") +@time_machine.travel("2023-01-08 15:00:00 UTC") def test_metadata_changed_regular_plan_preview_enabled(init_and_plan_context: t.Callable): context, plan = init_and_plan_context("examples/sushi") context.apply(plan) @@ -459,7 +459,7 @@ def test_metadata_changed_regular_plan_preview_enabled(init_and_plan_context: t. assert not plan.restatements -@time_machine.travel("2023-01-08 15:00:00") +@time_machine.travel("2023-01-08 15:00:00 UTC") def test_hourly_model_with_lookback_no_backfill_in_dev(init_and_plan_context: t.Callable): context, plan = init_and_plan_context("examples/sushi") @@ -551,7 +551,7 @@ def test_parent_cron_after_child(init_and_plan_context: t.Callable): ] -@time_machine.travel("2023-01-08 00:00:00") +@time_machine.travel("2023-01-08 00:00:00 UTC") @pytest.mark.parametrize( "forward_only, expected_intervals", [ @@ -606,7 +606,7 @@ def test_cron_not_aligned_with_day_boundary( "sushi.waiter_revenue_by_day", raise_if_missing=True ) - with time_machine.travel("2023-01-08 00:10:00"): # Past model's cron. + with time_machine.travel("2023-01-08 00:10:00 UTC"): # Past model's cron. plan = context.plan( "dev", select_models=[model.name], no_prompts=True, skip_tests=True, enable_preview=True ) @@ -618,7 +618,7 @@ def test_cron_not_aligned_with_day_boundary( ] -@time_machine.travel("2023-01-08 15:00:00") +@time_machine.travel("2023-01-08 15:00:00 UTC") def test_forward_only_parent_created_in_dev_child_created_in_prod( init_and_plan_context: t.Callable, ): @@ -672,7 +672,7 @@ def test_forward_only_parent_created_in_dev_child_created_in_prod( context.apply(plan) -@time_machine.travel("2023-01-08 15:00:00") +@time_machine.travel("2023-01-08 15:00:00 UTC") def test_plan_set_choice_is_reflected_in_missing_intervals(init_and_plan_context: t.Callable): context, plan = init_and_plan_context("examples/sushi") context.apply(plan) @@ -933,7 +933,7 @@ def test_non_breaking_change_after_forward_only_in_dev( assert prod_df.empty -@time_machine.travel("2023-01-08 15:00:00") +@time_machine.travel("2023-01-08 15:00:00 UTC") def test_indirect_non_breaking_change_after_forward_only_in_dev(init_and_plan_context: t.Callable): context, plan = init_and_plan_context("examples/sushi") context.apply(plan) @@ -1055,7 +1055,7 @@ def test_indirect_non_breaking_change_after_forward_only_in_dev(init_and_plan_co assert not context.plan("prod", no_prompts=True, skip_tests=True).requires_backfill -@time_machine.travel("2023-01-08 15:00:00") +@time_machine.travel("2023-01-08 15:00:00 UTC") def test_forward_only_precedence_over_indirect_non_breaking(init_and_plan_context: t.Callable): context, plan = init_and_plan_context("examples/sushi") context.apply(plan) @@ -1128,14 +1128,14 @@ def test_forward_only_precedence_over_indirect_non_breaking(init_and_plan_contex assert not context.plan("prod", no_prompts=True, skip_tests=True).requires_backfill -@time_machine.travel("2023-01-08 15:00:00") +@time_machine.travel("2023-01-08 15:00:00 UTC") def test_run_with_select_models( init_and_plan_context: t.Callable, ): context, plan = init_and_plan_context("examples/sushi") context.apply(plan) - with time_machine.travel("2023-01-09 00:00:00"): + with time_machine.travel("2023-01-09 00:00:00 UTC"): assert context.run(select_models=["*waiter_revenue_by_day"]) snapshots = context.state_sync.state_sync.get_snapshots(context.snapshots.values()) @@ -1159,7 +1159,7 @@ def test_run_with_select_models( } -@time_machine.travel("2023-01-08 15:00:00") +@time_machine.travel("2023-01-08 15:00:00 UTC") def test_run_with_select_models_no_auto_upstream( init_and_plan_context: t.Callable, ): @@ -1195,7 +1195,7 @@ def test_run_with_select_models_no_auto_upstream( } -@time_machine.travel("2023-01-08 15:00:00") +@time_machine.travel("2023-01-08 15:00:00 UTC") def test_select_models(init_and_plan_context: t.Callable): context, plan = init_and_plan_context("examples/sushi") context.apply(plan) @@ -1273,7 +1273,7 @@ def test_select_models(init_and_plan_context: t.Callable): ) -@time_machine.travel("2023-01-08 15:00:00") +@time_machine.travel("2023-01-08 15:00:00 UTC") def test_select_unchanged_model_for_backfill(init_and_plan_context: t.Callable): context, plan = init_and_plan_context("examples/sushi") context.apply(plan) @@ -1347,14 +1347,14 @@ def test_select_unchanged_model_for_backfill(init_and_plan_context: t.Callable): assert {o.name for o in schema_objects} == {"waiter_revenue_by_day", "top_waiters"} -@time_machine.travel("2023-01-08 15:00:00") +@time_machine.travel("2023-01-08 15:00:00 UTC") def test_max_interval_end_per_model_not_applied_when_end_is_provided( init_and_plan_context: t.Callable, ): context, plan = init_and_plan_context("examples/sushi") context.apply(plan) - with time_machine.travel("2023-01-09 00:00:00"): + with time_machine.travel("2023-01-09 00:00:00 UTC"): context.run() plan = context.plan( @@ -1363,7 +1363,7 @@ def test_max_interval_end_per_model_not_applied_when_end_is_provided( context.apply(plan) -@time_machine.travel("2023-01-08 15:00:00") +@time_machine.travel("2023-01-08 15:00:00 UTC") def test_select_models_for_backfill(init_and_plan_context: t.Callable): context, _ = init_and_plan_context("examples/sushi") @@ -1431,7 +1431,7 @@ def test_select_models_for_backfill(init_and_plan_context: t.Callable): ) -@time_machine.travel("2023-01-08 15:00:00") +@time_machine.travel("2023-01-08 15:00:00 UTC") def test_dbt_select_star_is_directly_modified(sushi_test_dbt_context: Context): context = sushi_test_dbt_context @@ -1476,7 +1476,7 @@ def test_model_attr(sushi_test_dbt_context: Context, assert_exp_eq): ) -@time_machine.travel("2023-01-08 15:00:00") +@time_machine.travel("2023-01-08 15:00:00 UTC") def test_incremental_by_partition(init_and_plan_context: t.Callable): context, plan = init_and_plan_context("examples/sushi") context.apply(plan) @@ -1530,7 +1530,7 @@ def test_incremental_by_partition(init_and_plan_context: t.Callable): ] -@time_machine.travel("2023-01-08 15:00:00") +@time_machine.travel("2023-01-08 15:00:00 UTC") def test_custom_materialization(init_and_plan_context: t.Callable): context, _ = init_and_plan_context("examples/sushi") @@ -1565,7 +1565,7 @@ def insert( assert custom_insert_called -@time_machine.travel("2023-01-08 15:00:00") +@time_machine.travel("2023-01-08 15:00:00 UTC") def test_unaligned_start_snapshot_with_non_deployable_downstream(init_and_plan_context: t.Callable): context, _ = init_and_plan_context("examples/sushi") @@ -1620,7 +1620,7 @@ def test_unaligned_start_snapshot_with_non_deployable_downstream(init_and_plan_c assert snapshot_interval.intervals[0][0] == to_timestamp("2023-01-07") -@time_machine.travel("2023-01-08 15:00:00") +@time_machine.travel("2023-01-08 15:00:00 UTC") def test_restatement_plan_ignores_changes(init_and_plan_context: t.Callable): context, plan = init_and_plan_context("examples/sushi") context.apply(plan) @@ -1651,7 +1651,7 @@ def test_restatement_plan_ignores_changes(init_and_plan_context: t.Callable): context.apply(plan) -@time_machine.travel("2023-01-08 15:00:00") +@time_machine.travel("2023-01-08 15:00:00 UTC") def test_plan_against_expired_environment(init_and_plan_context: t.Callable): context, plan = init_and_plan_context("examples/sushi") context.apply(plan) @@ -1682,7 +1682,7 @@ def test_plan_against_expired_environment(init_and_plan_context: t.Callable): context.apply(plan) -@time_machine.travel("2023-01-08 15:00:00") +@time_machine.travel("2023-01-08 15:00:00 UTC") def test_new_forward_only_model_concurrent_versions(init_and_plan_context: t.Callable): context, plan = init_and_plan_context("examples/sushi") context.apply(plan) @@ -1774,7 +1774,7 @@ def test_new_forward_only_model_concurrent_versions(init_and_plan_context: t.Cal assert df.to_dict() == {"ds": {0: "2023-01-07"}, "b": {0: None}} -@time_machine.travel("2023-01-08 15:00:00") +@time_machine.travel("2023-01-08 15:00:00 UTC") def test_new_forward_only_model_same_dev_environment(init_and_plan_context: t.Callable): context, plan = init_and_plan_context("examples/sushi") context.apply(plan) @@ -1877,7 +1877,7 @@ def test_plan_twice_with_star_macro_yields_no_diff(tmp_path: Path): assert not new_plan.new_snapshots -@time_machine.travel("2023-01-08 15:00:00") +@time_machine.travel("2023-01-08 15:00:00 UTC") def test_create_environment_no_changes_with_selector(init_and_plan_context: t.Callable): context, plan = init_and_plan_context("examples/sushi") context.apply(plan) @@ -1893,7 +1893,7 @@ def test_create_environment_no_changes_with_selector(init_and_plan_context: t.Ca assert {o.name for o in schema_objects} == {"top_waiters"} -@time_machine.travel("2023-01-08 15:00:00") +@time_machine.travel("2023-01-08 15:00:00 UTC") def test_empty_bacfkill(init_and_plan_context: t.Callable): context, _ = init_and_plan_context("examples/sushi") diff --git a/tests/core/test_plan.py b/tests/core/test_plan.py index 7af46e3ba..dbccb998b 100644 --- a/tests/core/test_plan.py +++ b/tests/core/test_plan.py @@ -1,6 +1,6 @@ import logging import typing as t -from datetime import datetime, timedelta +from datetime import timedelta from unittest.mock import patch import pytest @@ -727,7 +727,7 @@ def test_missing_intervals_lookback(make_snapshot, mocker: MockerFixture): @pytest.mark.slow -@time_machine.travel(datetime.now(), tick=False) +@time_machine.travel(now(), tick=False) def test_restate_models(sushi_context_pre_scheduling: Context): plan = sushi_context_pre_scheduling.plan( restate_models=["sushi.waiter_revenue_by_day", "tag:expensive"], no_prompts=True @@ -781,7 +781,7 @@ def test_restate_models(sushi_context_pre_scheduling: Context): @pytest.mark.slow -@time_machine.travel(datetime.now(), tick=False) +@time_machine.travel(now(), tick=False) def test_restate_models_with_existing_missing_intervals(sushi_context: Context): yesterday_ts = to_timestamp(yesterday_ds()) diff --git a/tests/dbt/test_integration.py b/tests/dbt/test_integration.py index 9cc8d7de4..452be016d 100644 --- a/tests/dbt/test_integration.py +++ b/tests/dbt/test_integration.py @@ -289,7 +289,7 @@ def _init_test( adapter.create_schema("sushi") if test_type.is_sqlmesh_runtime: self._replace_source_table(adapter, []) - with time_machine.travel("2019-12-31 00:00:00"): + with time_machine.travel("2019-12-31 00:00:00 UTC"): context.plan("prod", auto_apply=True, no_prompts=True) # type: ignore return run, adapter, context diff --git a/tests/integrations/github/cicd/test_integration.py b/tests/integrations/github/cicd/test_integration.py index 3b96b0ee6..65d35d717 100644 --- a/tests/integrations/github/cicd/test_integration.py +++ b/tests/integrations/github/cicd/test_integration.py @@ -52,7 +52,7 @@ def get_columns( return controller._context.engine_adapter.columns(table) -@time_machine.travel("2023-01-01 15:00:00") +@time_machine.travel("2023-01-01 15:00:00 UTC") def test_merge_pr_has_non_breaking_change( github_client, make_controller, @@ -248,7 +248,7 @@ def test_merge_pr_has_non_breaking_change( ) -@time_machine.travel("2023-01-01 15:00:00") +@time_machine.travel("2023-01-01 15:00:00 UTC") def test_merge_pr_has_non_breaking_change_diff_start( github_client, make_controller, @@ -447,7 +447,7 @@ def test_merge_pr_has_non_breaking_change_diff_start( ) -@time_machine.travel("2023-01-01 15:00:00") +@time_machine.travel("2023-01-01 15:00:00 UTC") def test_merge_pr_has_non_breaking_change_no_categorization( github_client, make_controller, @@ -757,7 +757,7 @@ def test_merge_pr_has_no_changes( ) -@time_machine.travel("2023-01-01 15:00:00") +@time_machine.travel("2023-01-01 15:00:00 UTC") def test_no_merge_since_no_deploy_signal( github_client, make_controller, @@ -938,7 +938,7 @@ def test_no_merge_since_no_deploy_signal( ) -@time_machine.travel("2023-01-01 15:00:00") +@time_machine.travel("2023-01-01 15:00:00 UTC") def test_no_merge_since_no_deploy_signal_no_approvers_defined( github_client, make_controller, @@ -1098,7 +1098,7 @@ def test_no_merge_since_no_deploy_signal_no_approvers_defined( ) -@time_machine.travel("2023-01-01 15:00:00") +@time_machine.travel("2023-01-01 15:00:00 UTC") def test_deploy_comment_pre_categorized( github_client, make_controller, @@ -1285,7 +1285,7 @@ def test_deploy_comment_pre_categorized( ) -@time_machine.travel("2023-01-01 15:00:00") +@time_machine.travel("2023-01-01 15:00:00 UTC") def test_error_msg_when_applying_plan_with_bug( github_client, make_controller, @@ -1438,7 +1438,7 @@ def test_error_msg_when_applying_plan_with_bug( ) -@time_machine.travel("2023-01-01 15:00:00") +@time_machine.travel("2023-01-01 15:00:00 UTC") def test_overlapping_changes_models( github_client, make_controller, @@ -1644,7 +1644,7 @@ def test_overlapping_changes_models( ) -@time_machine.travel("2023-01-01 15:00:00") +@time_machine.travel("2023-01-01 15:00:00 UTC") def test_pr_delete_model( github_client, make_controller, diff --git a/tests/integrations/jupyter/example_outputs.ipynb b/tests/integrations/jupyter/example_outputs.ipynb index bbb20274e..cfe3aa245 100644 --- a/tests/integrations/jupyter/example_outputs.ipynb +++ b/tests/integrations/jupyter/example_outputs.ipynb @@ -25,7 +25,7 @@ "metadata": {}, "outputs": [], "source": [ - "freezer = time_machine.travel(\"2032-01-01 00:00:00\")\n", + "freezer = time_machine.travel(\"2032-01-01 00:00:00 UTC\")\n", "freezer.start()" ] }, @@ -51,7 +51,7 @@ " prev_parent_stem = parent.stem\n", "else:\n", " raise RuntimeError(\"Couldn't find root dir\")\n", - " \n", + "\n", "EXAMPLE_SUSHI_DIR = pathlib.Path(root_dir) / \"examples\" / \"sushi\"\n", "str(EXAMPLE_SUSHI_DIR)" ] diff --git a/tests/integrations/jupyter/test_magics.py b/tests/integrations/jupyter/test_magics.py index 8690e38f7..90421dafa 100644 --- a/tests/integrations/jupyter/test_magics.py +++ b/tests/integrations/jupyter/test_magics.py @@ -23,7 +23,7 @@ SUCCESS_STYLE = "color: #008000; text-decoration-color: #008000" NEUTRAL_STYLE = "color: #008080; text-decoration-color: #008080" RICH_PRE_STYLE = "white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace" -FREEZE_TIME = "2023-01-01 00:00:00" +FREEZE_TIME = "2023-01-01 00:00:00 UTC" pytestmark = pytest.mark.jupyter @@ -313,7 +313,7 @@ def test_plan( @pytest.mark.slow -@time_machine.travel("2023-01-03 00:00:00") +@time_machine.travel("2023-01-03 00:00:00 UTC") def test_run_dag( notebook, loaded_sushi_context, convert_all_html_output_to_text, get_all_html_output ):