Skip to content

Commit 4fd59ba

Browse files
authored
Chore: attempt to fix parametric kind unit test to fix CI (#3404)
1 parent 1f626e7 commit 4fd59ba

File tree

1 file changed

+12
-37
lines changed

1 file changed

+12
-37
lines changed

tests/core/test_model.py

Lines changed: 12 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4679,7 +4679,7 @@ def model_with_columns(evaluator, **kwargs):
46794679

46804680

46814681
def test_named_variables_python_model(mocker: MockerFixture) -> None:
4682-
model.set_registry({}) # type: ignore
4682+
mocker.patch("sqlmesh.core.model.decorator.model._registry", {})
46834683

46844684
@model(
46854685
"test_named_variables_python_model",
@@ -4714,7 +4714,7 @@ def model_with_named_variables(
47144714

47154715

47164716
def test_named_variables_kw_only_python_model(mocker: MockerFixture) -> None:
4717-
model.set_registry({}) # type: ignore
4717+
mocker.patch("sqlmesh.core.model.decorator.model._registry", {})
47184718

47194719
@model(
47204720
"test_named_variables_python_model",
@@ -5741,8 +5741,8 @@ def test_model_kind_to_expression():
57415741
"metadata_only",
57425742
[True, False],
57435743
)
5744-
def test_macro_func_hash(metadata_only):
5745-
macro.set_registry({}) # type: ignore
5744+
def test_macro_func_hash(mocker: MockerFixture, metadata_only: bool):
5745+
mocker.patch("sqlmesh.core.macros.macro._registry", {})
57465746

57475747
@macro(metadata_only=metadata_only)
57485748
def noop(evaluator) -> None:
@@ -5784,7 +5784,7 @@ def noop(evaluator) -> None:
57845784
assert model.data_hash != new_model.data_hash
57855785
assert model.metadata_hash == new_model.metadata_hash
57865786

5787-
@macro(metadata_only=metadata_only)
5787+
@macro(metadata_only=metadata_only) # type: ignore
57885788
def noop(evaluator) -> None:
57895789
print("noop")
57905790
return None
@@ -6094,14 +6094,11 @@ def test_cluster_with_complex_expression():
60946094
assert [expr.sql("snowflake") for expr in model.clustered_by] == ['(TO_DATE("CLUSTER_COL"))']
60956095

60966096

6097-
def test_parametric_model_kind(tmp_path: Path):
6098-
init_example_project(tmp_path, dialect="duckdb")
6099-
6100-
test_sql_file = tmp_path / "models/test_model.sql"
6101-
test_sql_file.write_text(
6097+
def test_parametric_model_kind():
6098+
parsed_definition = d.parse(
61026099
"""
61036100
MODEL (
6104-
name test_schema.test_model,
6101+
name db.test_schema.test_model,
61056102
kind @IF(@gateway = 'main', VIEW, FULL)
61066103
);
61076104
@@ -6110,30 +6107,8 @@ def test_parametric_model_kind(tmp_path: Path):
61106107
"""
61116108
)
61126109

6113-
db_path = str(tmp_path / "db.db")
6114-
config = Config(
6115-
gateways={
6116-
"main": GatewayConfig(connection=DuckDBConnectionConfig(database=db_path)),
6117-
"other": GatewayConfig(connection=DuckDBConnectionConfig(database=db_path)),
6118-
},
6119-
model_defaults=ModelDefaultsConfig(dialect="duckdb"),
6120-
)
6121-
6122-
context = Context(paths=tmp_path, config=config)
6123-
plan = context.plan(no_prompts=True, auto_apply=True, no_diff=True)
6124-
6125-
assert len(plan.context_diff.new_snapshots) == 4
6126-
assert isinstance(context.get_model("test_schema.test_model").kind, ViewKind)
6127-
6128-
context = Context(paths=tmp_path, config=config, gateway="other")
6129-
plan = context.plan(no_prompts=True, auto_apply=True, no_diff=True)
6130-
diff = plan.context_diff
6131-
6132-
assert len(diff.new_snapshots) == 1
6133-
assert len(diff.modified_snapshots) == 1
6134-
6135-
new_snapshot, old_snapshot = next(iter(diff.modified_snapshots.values()))
6136-
assert isinstance(t.cast(SqlModel, new_snapshot.node).kind, FullKind)
6137-
assert isinstance(t.cast(SqlModel, old_snapshot.node).kind, ViewKind)
6110+
model = load_sql_based_model(parsed_definition, variables={c.GATEWAY: "main"})
6111+
assert isinstance(model.kind, ViewKind)
61386112

6139-
assert isinstance(context.get_model("test_schema.test_model").kind, FullKind)
6113+
model = load_sql_based_model(parsed_definition, variables={c.GATEWAY: "other"})
6114+
assert isinstance(model.kind, FullKind)

0 commit comments

Comments
 (0)