|
13 | 13 | from sqlglot.errors import ParseError |
14 | 14 | from sqlglot.schema import MappingSchema |
15 | 15 | from sqlmesh.cli.example_project import init_example_project, ProjectTemplate |
16 | | -from sqlmesh.core.model.kind import TimeColumn |
| 16 | +from sqlmesh.core.model.kind import TimeColumn, ModelKindName |
17 | 17 |
|
18 | 18 | from sqlmesh import CustomMaterialization, CustomKind |
19 | 19 | from pydantic import model_validator |
@@ -2156,23 +2156,6 @@ def my_model(context): |
2156 | 2156 | path=Path("."), |
2157 | 2157 | ) |
2158 | 2158 |
|
2159 | | - @model("kind_view", kind="view", columns={'"COL"': "int"}) |
2160 | | - def kind_view(context): |
2161 | | - pass |
2162 | | - |
2163 | | - # error if kind = view |
2164 | | - with pytest.raises( |
2165 | | - SQLMeshError, match=r".*Cannot create Python model.*doesnt support Python models" |
2166 | | - ): |
2167 | | - python_model = ( |
2168 | | - model.get_registry()["kind_view"] |
2169 | | - .model( |
2170 | | - module_path=Path("."), |
2171 | | - path=Path("."), |
2172 | | - ) |
2173 | | - .validate_definition() |
2174 | | - ) |
2175 | | - |
2176 | 2159 | @model("kind_dict_badname", kind=dict(name="test"), columns={'"COL"': "int"}) |
2177 | 2160 | def my_model_1(context): |
2178 | 2161 | pass |
@@ -2246,6 +2229,29 @@ def b_model(context): |
2246 | 2229 | ) |
2247 | 2230 |
|
2248 | 2231 |
|
| 2232 | +def test_python_model_unsupported_kind() -> None: |
| 2233 | + kinds = { |
| 2234 | + "seed": {"name": ModelKindName.SEED, "path": "."}, |
| 2235 | + "view": {"name": ModelKindName.VIEW}, |
| 2236 | + "managed": {"name": ModelKindName.MANAGED}, |
| 2237 | + "embedded": {"name": ModelKindName.EMBEDDED}, |
| 2238 | + } |
| 2239 | + |
| 2240 | + for kindname in kinds: |
| 2241 | + |
| 2242 | + @model(f"kind_{kindname}", kind=kinds[kindname], columns={'"COL"': "int"}) |
| 2243 | + def the_kind(context): |
| 2244 | + pass |
| 2245 | + |
| 2246 | + with pytest.raises( |
| 2247 | + SQLMeshError, match=r".*Cannot create Python model.*doesn't support Python models" |
| 2248 | + ): |
| 2249 | + model.get_registry()[f"kind_{kindname}"].model( |
| 2250 | + module_path=Path("."), |
| 2251 | + path=Path("."), |
| 2252 | + ).validate_definition() |
| 2253 | + |
| 2254 | + |
2249 | 2255 | def test_star_expansion(assert_exp_eq) -> None: |
2250 | 2256 | context = Context(config=Config()) |
2251 | 2257 |
|
@@ -6853,7 +6859,7 @@ def execute( |
6853 | 6859 |
|
6854 | 6860 | with pytest.raises( |
6855 | 6861 | SQLMeshError, |
6856 | | - match=r".*Cannot create Python model.*the 'MANAGED' kind doesnt support Python models", |
| 6862 | + match=r".*Cannot create Python model.*the 'MANAGED' kind doesn't support Python models", |
6857 | 6863 | ): |
6858 | 6864 | model.get_registry()["test_managed_python_model"].model( |
6859 | 6865 | module_path=Path("."), |
|
0 commit comments