|
1 | 1 | import json |
| 2 | +from pathlib import Path |
2 | 3 |
|
3 | 4 | import pytest |
4 | 5 | from _pytest.monkeypatch import MonkeyPatch |
5 | 6 | from pytest_mock.plugin import MockerFixture |
6 | | -from sqlglot import parse_one |
| 7 | +from sqlglot import exp, parse, parse_one |
7 | 8 |
|
8 | 9 | from sqlmesh.core.macros import macro |
9 | | -from sqlmesh.core.model import Model, SqlModel |
| 10 | +from sqlmesh.core.model import Model, SqlModel, load_model |
10 | 11 | from sqlmesh.core.snapshot import ( |
11 | 12 | Snapshot, |
12 | 13 | SnapshotChangeCategory, |
@@ -275,6 +276,40 @@ def test_fingerprint(model: Model, parent_model: Model): |
275 | 276 | assert new_fingerprint != fingerprint_from_model(model, models={}) |
276 | 277 |
|
277 | 278 |
|
| 279 | +def test_fingerprint_seed_model(): |
| 280 | + expressions = parse( |
| 281 | + """ |
| 282 | + MODEL ( |
| 283 | + name db.seed, |
| 284 | + kind SEED ( |
| 285 | + path '../seeds/waiter_names.csv' |
| 286 | + ) |
| 287 | + ); |
| 288 | + """ |
| 289 | + ) |
| 290 | + |
| 291 | + expected_fingerprint = SnapshotFingerprint( |
| 292 | + data_hash="941582290", |
| 293 | + metadata_hash="2750000337", |
| 294 | + ) |
| 295 | + |
| 296 | + model = load_model(expressions, path=Path("./examples/sushi/models/test_model.sql")) |
| 297 | + actual_fingerprint = fingerprint_from_model(model, models={}) |
| 298 | + assert actual_fingerprint == expected_fingerprint |
| 299 | + |
| 300 | + updated_model = model.copy( |
| 301 | + update={ |
| 302 | + "columns_to_types_": { |
| 303 | + "id": exp.DataType.build("int"), |
| 304 | + "name": exp.DataType.build("text"), |
| 305 | + } |
| 306 | + } |
| 307 | + ) |
| 308 | + updated_actual_fingerprint = fingerprint_from_model(updated_model, models={}) |
| 309 | + assert updated_actual_fingerprint.data_hash != expected_fingerprint.data_hash |
| 310 | + assert updated_actual_fingerprint.metadata_hash == expected_fingerprint.metadata_hash |
| 311 | + |
| 312 | + |
278 | 313 | def test_stamp(model: Model): |
279 | 314 | original_fingerprint = fingerprint_from_model(model, models={}) |
280 | 315 |
|
|
0 commit comments