22from contextlib import contextmanager
33from os import getcwd , path , remove
44from pathlib import Path
5+ from shutil import rmtree
56from click import ClickException
67import pytest
78from click .testing import CliRunner
@@ -801,6 +802,93 @@ def test_dlt_pipeline_errors(runner, tmp_path):
801802 assert "Error: Could not attach to pipeline" in result .output
802803
803804
805+ @time_machine .travel (FREEZE_TIME )
806+ def test_dlt_filesystem_pipeline (tmp_path ):
807+ import dlt
808+
809+ root_dir = path .abspath (getcwd ())
810+ storage_path = root_dir + "/temp_storage"
811+ if path .exists (storage_path ):
812+ rmtree (storage_path )
813+
814+ filesystem_pipeline = dlt .pipeline (
815+ pipeline_name = "filesystem_pipeline" ,
816+ destination = dlt .destinations .filesystem ("file://" + storage_path ),
817+ )
818+ info = filesystem_pipeline .run ([{"item_id" : 1 }], table_name = "equipment" )
819+ assert not info .has_failed_jobs
820+
821+ init_example_project (tmp_path , "athena" , ProjectTemplate .DLT , "filesystem_pipeline" )
822+
823+ # Validate generated sqlmesh config and models
824+ config_path = tmp_path / "config.yaml"
825+ equipment_model_path = tmp_path / "models/incremental_equipment.sql"
826+ dlt_loads_model_path = tmp_path / "models/incremental__dlt_loads.sql"
827+
828+ assert config_path .exists ()
829+ assert equipment_model_path .exists ()
830+ assert dlt_loads_model_path .exists ()
831+
832+ expected_incremental_model = """MODEL (
833+ name filesystem_pipeline_dataset_sqlmesh.incremental_equipment,
834+ kind INCREMENTAL_BY_TIME_RANGE (
835+ time_column _dlt_load_time,
836+ ),
837+ );
838+
839+ SELECT
840+ CAST(c.item_id AS BIGINT) AS item_id,
841+ CAST(c._dlt_load_id AS VARCHAR) AS _dlt_load_id,
842+ CAST(c._dlt_id AS VARCHAR) AS _dlt_id,
843+ TO_TIMESTAMP(CAST(c._dlt_load_id AS DOUBLE)) as _dlt_load_time
844+ FROM
845+ filesystem_pipeline_dataset.equipment as c
846+ WHERE
847+ TO_TIMESTAMP(CAST(c._dlt_load_id AS DOUBLE)) BETWEEN @start_ds AND @end_ds
848+ """
849+
850+ with open (equipment_model_path ) as file :
851+ incremental_model = file .read ()
852+
853+ assert incremental_model == expected_incremental_model
854+
855+ expected_config = (
856+ "gateways:\n "
857+ " athena:\n "
858+ " connection:\n "
859+ " # For more information on configuring the connection to your execution engine, visit:\n "
860+ " # https://sqlmesh.readthedocs.io/en/stable/reference/configuration/#connections\n "
861+ " # https://sqlmesh.readthedocs.io/en/stable/integrations/engines/athena/#connection-options\n "
862+ " type: athena\n "
863+ " # concurrent_tasks: 4\n "
864+ " # register_comments: False\n "
865+ " # pre_ping: False\n "
866+ " # pretty_sql: False\n "
867+ " # aws_access_key_id: \n "
868+ " # aws_secret_access_key: \n "
869+ " # role_arn: \n "
870+ " # role_session_name: \n "
871+ " # region_name: \n "
872+ " # work_group: \n "
873+ " # s3_staging_dir: \n "
874+ " # schema_name: \n "
875+ " # catalog_name: \n "
876+ " # s3_warehouse_location: \n \n \n "
877+ "default_gateway: athena\n \n "
878+ "model_defaults:\n "
879+ " dialect: athena\n "
880+ f" start: { yesterday_ds ()} \n "
881+ )
882+
883+ with open (config_path ) as file :
884+ config = file .read ()
885+
886+ assert config == expected_config
887+
888+ if path .exists (storage_path ):
889+ rmtree (storage_path )
890+
891+
804892@time_machine .travel (FREEZE_TIME )
805893def test_plan_dlt (runner , tmp_path ):
806894 from dlt .common .pipeline import get_dlt_pipelines_dir
@@ -1039,7 +1127,7 @@ def test_environments(runner, tmp_path):
10391127 ],
10401128 )
10411129 assert result .exit_code == 0
1042- assert result . output == f"Number of SQLMesh environments are: 1\n dev - { ttl } \n "
1130+ assert f"Number of SQLMesh environments are: 1\n dev - { ttl } \n " in result . output
10431131
10441132 # # create dev2 environment from dev environment
10451133 # # Input: `y` to apply and virtual update
@@ -1070,7 +1158,7 @@ def test_environments(runner, tmp_path):
10701158 ],
10711159 )
10721160 assert result .exit_code == 0
1073- assert result . output == f"Number of SQLMesh environments are: 2\n dev - { ttl } \n dev2 - { ttl } \n "
1161+ assert f"Number of SQLMesh environments are: 2\n dev - { ttl } \n dev2 - { ttl } \n " in result . output
10741162
10751163 # Example project models have start dates, so there are no date prompts
10761164 # for the `prod` environment.
@@ -1088,6 +1176,6 @@ def test_environments(runner, tmp_path):
10881176 )
10891177 assert result .exit_code == 0
10901178 assert (
1091- result . output
1092- == f"Number of SQLMesh environments are: 3 \n dev - { ttl } \n dev2 - { ttl } \n prod - No Expiry \n "
1179+ f"Number of SQLMesh environments are: 3 \n dev - { ttl } \n dev2 - { ttl } \n prod - No Expiry \n "
1180+ in result . output
10931181 )
0 commit comments