-
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.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
6 changed files
with
89 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: Allow instances of generic data tests to be documented | ||
time: 2024-10-14T21:21:35.767115+01:00 | ||
custom: | ||
Author: aranke | ||
Issue: "2578" |
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
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
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 @@ | ||
models__my_model_sql = """ | ||
with my_cte as ( | ||
select 1 as id, 'blue' as color | ||
union all | ||
select 2 as id, 'green' as red | ||
union all | ||
select 3 as id, 'red' as red | ||
) | ||
select * from my_cte | ||
""" | ||
|
||
models__schema_yml = """ | ||
models: | ||
- name: my_model | ||
columns: | ||
- name: id | ||
tests: | ||
- unique: | ||
description: "id must be unique" | ||
- not_null | ||
- name: color | ||
tests: | ||
- accepted_values: | ||
values: ['blue', 'green', 'red'] | ||
description: "{{ doc('color_accepted_values') }}" | ||
""" | ||
|
||
models__doc_block_md = """ | ||
{% docs color_accepted_values %} | ||
The `color` column must be one of 'blue', 'green', or 'red'. | ||
{% enddocs %} | ||
""" |
32 changes: 32 additions & 0 deletions
32
tests/functional/generic_test_description/test_generic_test_description.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,32 @@ | ||
import pytest | ||
|
||
from dbt.tests.util import get_artifact, run_dbt | ||
from tests.functional.generic_test_description.fixtures import ( | ||
models__doc_block_md, | ||
models__my_model_sql, | ||
models__schema_yml, | ||
) | ||
|
||
|
||
class TestBuiltinGenericTestDescription: | ||
@pytest.fixture(scope="class") | ||
def models(self): | ||
return { | ||
"my_model.sql": models__my_model_sql, | ||
"schema.yml": models__schema_yml, | ||
"doc_block.md": models__doc_block_md, | ||
} | ||
|
||
def test_compile(self, project): | ||
run_dbt(["compile"]) | ||
manifest = get_artifact(project.project_root, "target", "manifest.json") | ||
assert len(manifest["nodes"]) == 4 | ||
|
||
nodes = {node["alias"]: node for node in manifest["nodes"].values()} | ||
|
||
assert nodes["unique_my_model_id"]["description"] == "id must be unique" | ||
assert nodes["not_null_my_model_id"]["description"] == "" | ||
assert ( | ||
nodes["accepted_values_my_model_color__blue__green__red"]["description"] | ||
== "The `color` column must be one of 'blue', 'green', or 'red'." | ||
) |
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