Skip to content
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

Fix for custom generic tests #211

Merged
merged 4 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions dbt_meshify/dbt_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def models(self) -> Dict[str, ModelNode]:
return self._models

self._models = {
node_name: node
node_name: node # type: ignore
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻

for node_name, node in self.manifest.nodes.items()
if node.resource_type == "model" and isinstance(node, ModelNode)
}
Expand Down Expand Up @@ -328,11 +328,16 @@ def find_jinja_blocks(self) -> Dict[str, JinjaBlock]:
)

for unique_id, macro in self.manifest.macros.items():
block_type = "macro"
name = macro.name
if macro.package_name != self.name:
continue
if "tests/generic/" in macro.path:
block_type = "test"
name = macro.name[5:]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't feel super confident in using this hard-coded path. Would it make sense to use the test directory provided in dbt_project.yml here instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that makes sense to me! will update


blocks[unique_id] = JinjaBlock.from_file(
path=self.path / macro.original_file_path, block_type="macro", name=macro.name
path=self.path / macro.original_file_path, block_type=block_type, name=name
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like that this function has been parameterized 👍🏻 🪨

)

return blocks
Expand Down
1 change: 1 addition & 0 deletions test-projects/split/split_proj/models/marts/__models.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ models:
expression: count_food_items + count_drink_items = count_items
- dbt_utils.expression_is_true:
expression: subtotal_food_items + subtotal_drink_items = subtotal
- custom_generic_test
columns:
- name: order_id
description: The unique key of the orders mart.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{% test custom_generic_test(model) %}
select true where false
{% endtest %}
12 changes: 12 additions & 0 deletions tests/unit/test_jinja_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@
{% endmacro %}
"""

simple_custom_generic_test = """\


{% test my_custom_test(model) %}
select * from {{ model }} where false
{% endtest %}
"""

simple_macro_no_spaces = """\


Expand Down Expand Up @@ -176,3 +184,7 @@ def test_from_file_extracts_content_in_files_with_multiple_blocks(self):
content
== "{% docs potato_name %}\nThe name of the customer's favorite potato dish.\n{% enddocs %}"
)

def test_from_file_extracts_custom_generic_test(self):
range = JinjaBlock.find_block_range(simple_custom_generic_test, "test", "my_custom_test")
assert range == (2, 88)
Loading