Skip to content

Commit

Permalink
add custom generic test and jinja handling logic
Browse files Browse the repository at this point in the history
  • Loading branch information
dave-connors-3 committed May 29, 2024
1 parent c6ae767 commit 684a8ca
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
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
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:]

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
)

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() %}
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)

0 comments on commit 684a8ca

Please sign in to comment.