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 all 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
15 changes: 13 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,22 @@ def find_jinja_blocks(self) -> Dict[str, JinjaBlock]:
)

for unique_id, macro in self.manifest.macros.items():
block_type = "macro"
name = macro.name
top_level_folder = macro.path.split("/")[0]

if macro.package_name != self.name:
continue
if (
top_level_folder in self.project.test_paths
if self.project.test_paths
else ["tests"]
Comment on lines +338 to +340
Copy link
Collaborator

Choose a reason for hiding this comment

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

Beautiful logic 🪨

):
block_type = "test"
name = macro.name[5:]

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