1010from tests .materializations .conftest import to_sql_calls , MockedEngineAdapterMaker
1111from sqlmesh .core .engine_adapter .trino import TrinoEngineAdapter
1212from sqlmesh .utils .errors import ConfigError
13- from pydantic import ValidationError
1413from sqlmesh .utils .date import to_timestamp , now
1514from sqlmesh .core .macros import RuntimeStage
1615
2120def make_model () -> ModelMaker :
2221 def _make (properties : t .Union [str , t .List [str ]], dialect : t .Optional [str ] = None ) -> Model :
2322 if isinstance (properties , list ):
24- properties = ",\n " .join (properties ) + ","
23+ properties = ",\n " .join (properties )
2524
25+ properties_sql = f"materialization_properties ({ properties } )," if properties else ""
2626 dialect_sql = f"dialect { dialect } ," if dialect else ""
2727
2828 expressions = d .parse (f"""
2929 MODEL (
3030 name test.model,
3131 kind CUSTOM (
3232 materialization 'non_idempotent_incremental_by_time_range',
33- { properties }
33+ { properties_sql }
3434 batch_size 1,
3535 batch_concurrency 1
3636 ),
@@ -48,7 +48,7 @@ def _make(properties: t.Union[str, t.List[str]], dialect: t.Optional[str] = None
4848
4949def test_kind (make_model : ModelMaker ):
5050 # basic usage
51- model = make_model (["time_column ds" , "primary_key (id, ds)" ])
51+ model = make_model (["time_column = ds" , "primary_key = (id, ds)" ])
5252 assert isinstance (model .kind , NonIdempotentIncrementalByTimeRangeKind )
5353
5454 assert model .kind .time_column .column == exp .to_column ("ds" , quoted = True )
@@ -58,22 +58,22 @@ def test_kind(make_model: ModelMaker):
5858 ]
5959
6060 # required fields
61- with pytest .raises (ValidationError , match = r"time_column\n.*Field required " ):
61+ with pytest .raises (ConfigError , match = r"Invalid time_column " ):
6262 model = make_model ([])
6363
64- with pytest .raises (ValidationError , match = r"primary_key\n.*Field required " ):
65- model = make_model (["time_column ds" ])
64+ with pytest .raises (ConfigError , match = r"` primary_key` must be specified " ):
65+ model = make_model (["time_column = ds" ])
6666
6767 with pytest .raises (ConfigError , match = r"`primary_key` must be specified" ):
68- model = make_model (["time_column ds" , "primary_key ()" ])
68+ model = make_model (["time_column = ds" , "primary_key = ()" ])
6969
7070 # primary_key cant be the same as time_column
7171 with pytest .raises (ConfigError , match = r"primary_key` cannot be just the time_column" ):
72- model = make_model (["time_column ds" , "primary_key ds" ])
72+ model = make_model (["time_column = ds" , "primary_key = ds" ])
7373
7474
7575def test_insert (make_model : ModelMaker , make_mocked_engine_adapter : MockedEngineAdapterMaker ):
76- model : Model = make_model (["time_column ds" , "primary_key name" ], dialect = "trino" )
76+ model : Model = make_model (["time_column = ds" , "primary_key = name" ], dialect = "trino" )
7777 adapter = make_mocked_engine_adapter (TrinoEngineAdapter )
7878 strategy = NonIdempotentIncrementalByTimeRangeMaterialization (adapter )
7979
@@ -117,7 +117,7 @@ def test_insert(make_model: ModelMaker, make_mocked_engine_adapter: MockedEngine
117117
118118
119119def test_append (make_model : ModelMaker , make_mocked_engine_adapter : MockedEngineAdapterMaker ):
120- model : Model = make_model (["time_column ds" , "primary_key name" ], dialect = "trino" )
120+ model : Model = make_model (["time_column = ds" , "primary_key = name" ], dialect = "trino" )
121121 adapter = make_mocked_engine_adapter (TrinoEngineAdapter )
122122 strategy = NonIdempotentIncrementalByTimeRangeMaterialization (adapter )
123123
0 commit comments