-
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.
migrate test_jinja_static from unittest
- Loading branch information
1 parent
ff096d7
commit 8591dd4
Showing
1 changed file
with
39 additions
and
29 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 |
---|---|---|
@@ -1,44 +1,54 @@ | ||
import unittest | ||
import pytest | ||
|
||
from dbt.clients.jinja_static import statically_extract_macro_calls | ||
from dbt.context.base import generate_base_context | ||
|
||
|
||
class MacroCalls(unittest.TestCase): | ||
def setUp(self): | ||
self.macro_strings = [ | ||
@pytest.mark.parametrize( | ||
"macro_string,expected_possible_macro_calls", | ||
[ | ||
( | ||
"{% macro parent_macro() %} {% do return(nested_macro()) %} {% endmacro %}", | ||
"{% macro lr_macro() %} {{ return(load_result('relations').table) }} {% endmacro %}", | ||
"{% macro get_snapshot_unique_id() -%} {{ return(adapter.dispatch('get_snapshot_unique_id')()) }} {%- endmacro %}", | ||
"{% macro get_columns_in_query(select_sql) -%} {{ return(adapter.dispatch('get_columns_in_query')(select_sql)) }} {% endmacro %}", | ||
"""{% macro test_mutually_exclusive_ranges(model) %} | ||
with base as ( | ||
select {{ get_snapshot_unique_id() }} as dbt_unique_id, | ||
* | ||
from {{ model }} ) | ||
{% endmacro %}""", | ||
"{% macro test_my_test(model) %} select {{ current_timestamp_backcompat() }} {% endmacro %}", | ||
"{% macro some_test(model) -%} {{ return(adapter.dispatch('test_some_kind4', 'foo_utils4')) }} {%- endmacro %}", | ||
"{% macro some_test(model) -%} {{ return(adapter.dispatch('test_some_kind5', macro_namespace = 'foo_utils5')) }} {%- endmacro %}", | ||
] | ||
|
||
self.possible_macro_calls = [ | ||
["nested_macro"], | ||
), | ||
( | ||
"{% macro lr_macro() %} {{ return(load_result('relations').table) }} {% endmacro %}", | ||
["load_result"], | ||
), | ||
( | ||
"{% macro get_snapshot_unique_id() -%} {{ return(adapter.dispatch('get_snapshot_unique_id')()) }} {%- endmacro %}", | ||
["get_snapshot_unique_id"], | ||
), | ||
( | ||
"{% macro get_columns_in_query(select_sql) -%} {{ return(adapter.dispatch('get_columns_in_query')(select_sql)) }} {% endmacro %}", | ||
["get_columns_in_query"], | ||
), | ||
( | ||
"""{% macro test_mutually_exclusive_ranges(model) %} | ||
with base as ( | ||
select {{ get_snapshot_unique_id() }} as dbt_unique_id, | ||
* | ||
from {{ model }} ) | ||
{% endmacro %}""", | ||
["get_snapshot_unique_id"], | ||
), | ||
( | ||
"{% macro test_my_test(model) %} select {{ current_timestamp_backcompat() }} {% endmacro %}", | ||
["current_timestamp_backcompat"], | ||
), | ||
( | ||
"{% macro some_test(model) -%} {{ return(adapter.dispatch('test_some_kind4', 'foo_utils4')) }} {%- endmacro %}", | ||
["test_some_kind4", "foo_utils4.test_some_kind4"], | ||
), | ||
( | ||
"{% macro some_test(model) -%} {{ return(adapter.dispatch('test_some_kind5', macro_namespace = 'foo_utils5')) }} {%- endmacro %}", | ||
["test_some_kind5", "foo_utils5.test_some_kind5"], | ||
] | ||
|
||
def test_macro_calls(self): | ||
cli_vars = {"local_utils_dispatch_list": ["foo_utils4"]} | ||
ctx = generate_base_context(cli_vars) | ||
), | ||
], | ||
) | ||
def test_extract_macro_calls(self, macro_string, expected_possible_macro_calls): | ||
cli_vars = {"local_utils_dispatch_list": ["foo_utils4"]} | ||
ctx = generate_base_context(cli_vars) | ||
|
||
index = 0 | ||
for macro_string in self.macro_strings: | ||
possible_macro_calls = statically_extract_macro_calls(macro_string, ctx) | ||
self.assertEqual(self.possible_macro_calls[index], possible_macro_calls) | ||
index += 1 | ||
possible_macro_calls = statically_extract_macro_calls(macro_string, ctx) | ||
assert possible_macro_calls == expected_possible_macro_calls |