-
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.
[Round 2] Fix #9005: Allow singular tests to be documented in propert…
…ies.yml (#10792)
- Loading branch information
Showing
11 changed files
with
249 additions
and
16 deletions.
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 singular tests to be documented in properties.yml | ||
time: 2024-09-23T19:07:58.151069+01:00 | ||
custom: | ||
Author: aranke | ||
Issue: "9005" |
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
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
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,38 @@ | ||
tests__my_singular_test_sql = """ | ||
with my_cte as ( | ||
select 1 as id, 'foo' as name | ||
union all | ||
select 2 as id, 'bar' as name | ||
) | ||
select * from my_cte | ||
""" | ||
|
||
tests__schema_yml = """ | ||
data_tests: | ||
- name: my_singular_test | ||
description: "{{ doc('my_singular_test_documentation') }}" | ||
config: | ||
error_if: ">10" | ||
meta: | ||
some_key: some_val | ||
""" | ||
|
||
tests__doc_block_md = """ | ||
{% docs my_singular_test_documentation %} | ||
Some docs from a doc block | ||
{% enddocs %} | ||
""" | ||
|
||
tests__invalid_name_schema_yml = """ | ||
data_tests: | ||
- name: my_double_test | ||
description: documentation, but make it double | ||
""" | ||
|
||
tests__malformed_schema_yml = """ | ||
data_tests: ¬_null | ||
- not_null: | ||
where: some_condition | ||
""" |
65 changes: 65 additions & 0 deletions
65
tests/functional/data_test_patch/test_singular_test_patch.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,65 @@ | ||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
from dbt.tests.util import get_artifact, run_dbt, run_dbt_and_capture | ||
from tests.functional.data_test_patch.fixtures import ( | ||
tests__doc_block_md, | ||
tests__invalid_name_schema_yml, | ||
tests__malformed_schema_yml, | ||
tests__my_singular_test_sql, | ||
tests__schema_yml, | ||
) | ||
|
||
|
||
class TestPatchSingularTest: | ||
@pytest.fixture(scope="class") | ||
def tests(self): | ||
return { | ||
"my_singular_test.sql": tests__my_singular_test_sql, | ||
"schema.yml": tests__schema_yml, | ||
"doc_block.md": tests__doc_block_md, | ||
} | ||
|
||
def test_compile(self, project): | ||
run_dbt(["compile"]) | ||
manifest = get_artifact(project.project_root, "target", "manifest.json") | ||
assert len(manifest["nodes"]) == 1 | ||
|
||
my_singular_test_node = manifest["nodes"]["test.test.my_singular_test"] | ||
assert my_singular_test_node["description"] == "Some docs from a doc block" | ||
assert my_singular_test_node["config"]["error_if"] == ">10" | ||
assert my_singular_test_node["config"]["meta"] == {"some_key": "some_val"} | ||
|
||
|
||
class TestPatchSingularTestInvalidName: | ||
@pytest.fixture(scope="class") | ||
def tests(self): | ||
return { | ||
"my_singular_test.sql": tests__my_singular_test_sql, | ||
"schema_with_invalid_name.yml": tests__invalid_name_schema_yml, | ||
} | ||
|
||
def test_compile(self, project): | ||
_, log_output = run_dbt_and_capture(["compile"]) | ||
|
||
file_path = Path("tests/schema_with_invalid_name.yml") | ||
assert ( | ||
f"Did not find matching node for patch with name 'my_double_test' in the 'data_tests' section of file '{file_path}'" | ||
in log_output | ||
) | ||
|
||
|
||
class TestPatchSingularTestMalformedYaml: | ||
@pytest.fixture(scope="class") | ||
def tests(self): | ||
return { | ||
"my_singular_test.sql": tests__my_singular_test_sql, | ||
"schema.yml": tests__malformed_schema_yml, | ||
} | ||
|
||
def test_compile(self, project): | ||
_, log_output = run_dbt_and_capture(["compile"]) | ||
file_path = Path("tests/schema.yml") | ||
assert f"Unable to parse 'data_tests' section of file '{file_path}'" in log_output | ||
assert "Entry did not contain a name" in log_output |
Oops, something went wrong.