-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Snapshot strategies: newline for subquery (#6780)
* Snapshot strategies: newline for subquery * add changie output * add test for snapshot ending in comment * remove import to be flake8 compliant * add seed import * add newlines for flake8 compliance * typo fix * Fixing up a test, adding a comment or two * removed un-needed test fixtures * removed even more un-needed fixtures, collapsed test to single class * removed errant breakpoint() * Fix a little typo --------- Co-authored-by: Ian Knox <ian.knox@dbtlabs.com> Co-authored-by: Mila Page <67295367+VersusFacit@users.noreply.github.com>
- Loading branch information
1 parent
2971b9a
commit b450a57
Showing
3 changed files
with
45 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
kind: Fixes | ||
body: 'Snapshot strategies: add a newline for subquery' | ||
time: 2023-01-30T23:14:56.131767823+01:00 | ||
custom: | ||
Author: RobbertDM | ||
Issue: "6781" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
tests/functional/simple_snapshot/test_comment_ending_snapshot.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import pytest | ||
from dbt.tests.util import run_dbt | ||
import os | ||
|
||
snapshots_with_comment_at_end__snapshot_sql = """ | ||
{% snapshot snapshot_actual %} | ||
{{ | ||
config( | ||
target_database=var('target_database', database), | ||
target_schema=schema, | ||
unique_key='id', | ||
strategy='check', | ||
check_cols=['email'], | ||
) | ||
}} | ||
select * from {{target.database}}.{{schema}}.seed | ||
-- Test comment to prevent recurrence of https://github.com/dbt-labs/dbt-core/issues/6781 | ||
{% endsnapshot %} | ||
""" | ||
|
||
|
||
class TestSnapshotsWithCommentAtEnd: | ||
@pytest.fixture(scope="class") | ||
def snapshots(self): | ||
return {"snapshot.sql": snapshots_with_comment_at_end__snapshot_sql} | ||
|
||
def test_comment_ending(self, project): | ||
path = os.path.join(project.test_data_dir, "seed_pg.sql") | ||
project.run_sql_file(path) | ||
# N.B. Snapshot is run twice to ensure snapshot_check_all_get_existing_columns is fully run | ||
# (it exits early if the table doesn't already exist) | ||
run_dbt(["snapshot"]) | ||
results = run_dbt(["snapshot"]) | ||
assert len(results) == 1 |