-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support descriptions on tests #3302
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,7 +46,8 @@ def documentable(cls) -> List['NodeType']: | |
cls.Source, | ||
cls.Macro, | ||
cls.Analysis, | ||
cls.Exposure | ||
cls.Exposure, | ||
cls.Test | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Confirmed that both types of tests (generic + bespoke) can use |
||
] | ||
|
||
def pluralize(self) -> str: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,7 +32,7 @@ | |
Manifest, Disabled, MacroManifest, ManifestStateCheck | ||
) | ||
from dbt.contracts.graph.parsed import ( | ||
ParsedSourceDefinition, ParsedNode, ParsedMacro, ColumnInfo, ParsedExposure | ||
ParsedSchemaTestNode, ParsedSourceDefinition, ParsedMacro, ColumnInfo, ParsedExposure | ||
) | ||
from dbt.contracts.util import Writable | ||
from dbt.exceptions import ( | ||
|
@@ -693,12 +693,6 @@ def _get_node_column(node, column_name): | |
return column | ||
|
||
|
||
DocsContextCallback = Callable[ | ||
[Union[ParsedNode, ParsedSourceDefinition]], | ||
Dict[str, Any] | ||
] | ||
|
||
|
||
# node and column descriptions | ||
def _process_docs_for_node( | ||
context: Dict[str, Any], | ||
|
@@ -749,12 +743,42 @@ def _process_docs_for_exposure( | |
# exposures: exposure descriptions | ||
def process_docs(manifest: Manifest, config: RuntimeConfig): | ||
for node in manifest.nodes.values(): | ||
ctx = generate_runtime_docs( | ||
config, | ||
node, | ||
manifest, | ||
config.project_name, | ||
) | ||
if isinstance(node, ParsedSchemaTestNode): | ||
# Idealing we should be able to put the test kwargs in the context, | ||
# but kwargs have already been processed at this point | ||
# ex: 'model' --> "{{ ref('model') }}" | ||
Comment on lines
+747
to
+749
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to clarify my understanding: The "test_metadata": {
"name": "accepted_values",
"kwargs": {
"values": [
"usd"
],
"column_name": "currency_code",
"model": "{{ ref('stg_ticket_tailor__orders') }}"
},
"namespace": null
}, In order to include |
||
ctx = generate_runtime_docs( | ||
config, | ||
node, | ||
manifest, | ||
config.project_name, | ||
) | ||
|
||
model = [] | ||
|
||
if len(node.refs): | ||
model = node.refs[0] | ||
elif len(node.sources): | ||
model = node.sources[0] | ||
|
||
if len(model) == 1: | ||
target_model_name = model[0] | ||
elif len(model) == 2: | ||
_, target_model_name = model | ||
else: | ||
raise dbt.exceptions.InternalException( | ||
f'Refs and sources should always be 1 or 2 arguments - got {len(model)}' | ||
) | ||
|
||
ctx['column_name'] = node.column_name | ||
ctx['model'] = target_model_name | ||
Comment on lines
+757
to
+774
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. blah hardcoded values set directly on the context, I tried to avoid this without success There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This means that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ohh I see your comment above. Okay, that makes sense! |
||
else: | ||
ctx = generate_runtime_docs( | ||
config, | ||
node, | ||
manifest, | ||
config.project_name, | ||
) | ||
_process_docs_for_node(ctx, node) | ||
for source in manifest.sources.values(): | ||
ctx = generate_runtime_docs( | ||
|
@@ -856,7 +880,6 @@ def _process_refs_for_node( | |
node, target_model_name, target_model_package, | ||
disabled=(isinstance(target_model, Disabled)) | ||
) | ||
|
||
continue | ||
|
||
target_model_id = target_model.unique_id | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
version: 2 | ||
|
||
models: | ||
- name: table_copy | ||
description: "A copy of the table" | ||
columns: | ||
- name: id | ||
description: "The ID" | ||
tests: | ||
- not_null | ||
- unique | ||
- name: first_name | ||
description: "The user's first name" | ||
- name: ip_address | ||
description: "The user's IP address" | ||
tests: | ||
- unique | ||
- name: updated_at | ||
description: "The update time of the user" | ||
- name: email | ||
description: "The user's email address" | ||
- name: favorite_color | ||
description: "The user's favorite color" | ||
- name: fav_number | ||
description: "The user's favorite number" | ||
|
||
tests: | ||
- name: not_null | ||
description: "test not null description for column {{ column_name }} on model {{ model }}" | ||
- name: unique | ||
description: "test unique description for column {{ column_name }} on model {{ model }}" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
{{ | ||
config( | ||
materialized='table' | ||
) | ||
}} | ||
|
||
select * from {{ this.schema }}.seed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is new/diverging behavior! Previously, a patch can only be applied once to a single node. The new behavior allows patches to be applied to multiple nodes to support applying the same patch to multiple instances of the same generic test.