Skip to content

Commit 47ee17d

Browse files
authored
Merge branch 'main' into feature/smarter-unit-tests
2 parents 91b7bef + cc30650 commit 47ee17d

5 files changed

Lines changed: 31 additions & 4 deletions

File tree

‎docs/integrations/dbt.md‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,9 +287,12 @@ If set to `False`, then the snapshot will be skipped and a warning will be logge
287287
Support for this will be added soon.
288288

289289
## Tests
290-
SQLMesh uses dbt tests to perform SQLMesh [audits](../concepts/audits.md) (coming soon).
291290

292-
Add SQLMesh [unit tests](../concepts/tests.md) to a dbt project by placing them in the "tests" directory.
291+
dbt and SQLMesh use the word "test" differently. See [Workflow differences](#workflow-differences-between-sqlmesh-and-dbt) above for an overview.
292+
293+
SQLMesh converts dbt tests (singular and generic `.sql` files in the `tests/` directory) into SQLMesh [audits](../concepts/audits.md). These run against data that already exists in your tables, just like dbt tests.
294+
295+
Add SQLMesh [unit tests](../concepts/tests.md) to a dbt project by placing YAML files named `test*.yaml` or `test*.yml` in the `tests/` directory. Unit tests validate model query logic with predefined inputs and expected outputs; they are separate from dbt's SQL test files.
293296

294297
## Seed column types
295298

‎sqlmesh/core/context.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1339,7 +1339,8 @@ def format(
13391339
): # introduced to satisfy type checker as still want to pull filter out as many targets as possible before loop
13401340
continue
13411341

1342-
with open(target._path, "r+", encoding="utf-8") as file:
1342+
mode = "r" if check else "r+"
1343+
with open(target._path, mode, encoding="utf-8") as file:
13431344
before = file.read()
13441345

13451346
after = self._format(

‎sqlmesh/core/engine_adapter/clickhouse.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
DataObjectType,
1414
EngineRunMode,
1515
SourceQuery,
16+
CommentCreationTable,
1617
CommentCreationView,
1718
InsertOverwriteStrategy,
1819
)
@@ -36,6 +37,7 @@ class ClickhouseEngineAdapter(EngineAdapterWithIndexSupport, LogicalMergeMixin):
3637
SUPPORTS_TRANSACTIONS = False
3738
SUPPORTS_VIEW_SCHEMA = False
3839
SUPPORTS_REPLACE_TABLE = False
40+
COMMENT_CREATION_TABLE = CommentCreationTable.COMMENT_COMMAND_ONLY
3941
COMMENT_CREATION_VIEW = CommentCreationView.COMMENT_COMMAND_ONLY
4042

4143
SCHEMA_DIFFER_KWARGS = {}

‎tests/core/engine_adapter/integration/test_integration_bigquery.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ def test_run_correlation_id_in_job_labels(ctx: TestContext):
490490
cron '@daily',
491491
start '2023-01-07'
492492
);
493-
SELECT 1 AS col, '2023-01-07' AS event_ts
493+
SELECT 1 AS col, CAST('2023-01-07' AS DATE) AS event_ts
494494
"""
495495
)
496496
)

‎tests/core/test_format.py‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import os
12
import pathlib
3+
import stat
24

35
from pytest_mock.plugin import MockerFixture
46
from sqlmesh.core.config import Config
@@ -146,6 +148,25 @@ def test_ignore_formating_files(tmp_path: pathlib.Path):
146148
)
147149

148150

151+
def test_format_check_read_only_files(tmp_path: pathlib.Path, mocker: MockerFixture):
152+
models_dir = pathlib.Path("models")
153+
154+
model_text = "MODEL(name this.model, dialect 'duckdb'); SELECT 1 AS col"
155+
model = create_temp_file(
156+
tmp_path,
157+
pathlib.Path(models_dir, "model.sql"),
158+
model_text,
159+
)
160+
os.chmod(model, stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH)
161+
162+
context = Context(paths=tmp_path, config=Config())
163+
context.console = mocker.Mock()
164+
context.load()
165+
166+
assert not context.format(check=True)
167+
assert model.read_text(encoding="utf-8") == model_text
168+
169+
149170
def test_format_without_state_load(tmp_path: pathlib.Path, mocker: MockerFixture):
150171
mock = mocker.patch(
151172
"sqlmesh.core.state_sync.db.facade.EngineAdapterStateSync.get_versions",

0 commit comments

Comments
 (0)