|
14 | 14 | from sqlglot import ParseError, exp, parse_one, Dialect |
15 | 15 | from sqlglot.errors import SchemaError |
16 | 16 |
|
17 | | -from sqlmesh.core.config.gateway import GatewayConfig |
18 | 17 | import sqlmesh.core.constants |
| 18 | +from sqlmesh.cli.example_project import init_example_project |
19 | 19 | from sqlmesh.core import dialect as d, constants as c |
20 | 20 | from sqlmesh.core.config import ( |
| 21 | + load_configs, |
| 22 | + AutoCategorizationMode, |
| 23 | + CategorizerConfig, |
21 | 24 | Config, |
22 | 25 | DuckDBConnectionConfig, |
23 | 26 | EnvironmentSuffixTarget, |
| 27 | + GatewayConfig, |
| 28 | + LinterConfig, |
24 | 29 | ModelDefaultsConfig, |
| 30 | + PlanConfig, |
25 | 31 | SnowflakeConnectionConfig, |
26 | | - LinterConfig, |
27 | | - load_configs, |
28 | 32 | ) |
29 | 33 | from sqlmesh.core.context import Context |
30 | 34 | from sqlmesh.core.console import create_console, get_console |
@@ -2071,3 +2075,40 @@ def test_audit(): |
2071 | 2075 | context.plan(no_prompts=True, auto_apply=True) |
2072 | 2076 |
|
2073 | 2077 | assert context.audit(models=["dummy"], start="2020-01-01", end="2020-01-01") is True |
| 2078 | + |
| 2079 | + |
| 2080 | +def test_prompt_if_uncategorized_snapshot(mocker: MockerFixture, tmp_path: Path) -> None: |
| 2081 | + init_example_project(tmp_path, dialect="duckdb") |
| 2082 | + |
| 2083 | + config = Config( |
| 2084 | + model_defaults=ModelDefaultsConfig(dialect="duckdb"), |
| 2085 | + plan=PlanConfig( |
| 2086 | + auto_categorize_changes=CategorizerConfig( |
| 2087 | + external=AutoCategorizationMode.OFF, |
| 2088 | + python=AutoCategorizationMode.OFF, |
| 2089 | + sql=AutoCategorizationMode.OFF, |
| 2090 | + seed=AutoCategorizationMode.OFF, |
| 2091 | + ), |
| 2092 | + ), |
| 2093 | + ) |
| 2094 | + context = Context(paths=tmp_path, config=config) |
| 2095 | + context.plan(no_prompts=True, auto_apply=True) |
| 2096 | + |
| 2097 | + incremental_model = context.get_model("sqlmesh_example.incremental_model") |
| 2098 | + incremental_model_query = incremental_model.render_query() |
| 2099 | + new_incremental_model_query = t.cast(exp.Select, incremental_model_query).select("1 AS z") |
| 2100 | + context.upsert_model("sqlmesh_example.incremental_model", query=new_incremental_model_query) |
| 2101 | + |
| 2102 | + mock_console = mocker.Mock() |
| 2103 | + spy_plan = mocker.spy(mock_console, "plan") |
| 2104 | + context.console = mock_console |
| 2105 | + |
| 2106 | + context.plan() |
| 2107 | + |
| 2108 | + calls = spy_plan.mock_calls |
| 2109 | + assert len(calls) == 1 |
| 2110 | + |
| 2111 | + # Show that the presence of uncategorized snapshots forces no_prompts to |
| 2112 | + # False instead of respecting the default plan config value, which is True |
| 2113 | + assert calls[0].kwargs["no_prompts"] == False |
| 2114 | + assert context.config.plan.no_prompts == True |
0 commit comments