Skip to content

Commit

Permalink
add generic test to macro_edges
Browse files Browse the repository at this point in the history
  • Loading branch information
emmyoop committed Oct 21, 2021
1 parent 787aef9 commit 31c142c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
7 changes: 5 additions & 2 deletions core/dbt/contracts/graph/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,13 @@ def build_node_edges(nodes: List[ManifestNode]):
return _sort_values(forward_edges), _sort_values(backward_edges)


# Build a map of children of macros
# Build a map of children of macros and generic tests
def build_macro_edges(nodes: List[Any]):
forward_edges: Dict[str, List[str]] = {
n.unique_id: [] for n in nodes if n.unique_id.startswith('macro') or n.depends_on.macros
n.unique_id: [] for n in nodes
if (n.unique_id.startswith('macro') or
n.unique_id.startswith('test') or
n.depends_on.macros)
}
for node in nodes:
for unique_id in node.depends_on.macros:
Expand Down
1 change: 0 additions & 1 deletion core/dbt/contracts/graph/unparsed.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class UnparsedMacro(UnparsedBaseNode, HasSQL):

@dataclass
class UnparsedGenericTest(UnparsedBaseNode, HasSQL):
# TODO: should this be nodeType macro?
resource_type: NodeType = field(metadata={'restrict': [NodeType.Macro]})


Expand Down
11 changes: 6 additions & 5 deletions core/dbt/parser/generic_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from dbt.node_types import NodeType
from dbt.parser.base import BaseParser
from dbt.parser.search import FileBlock
from dbt.utils import MACRO_PREFIX # TODO: should this be macro?
from dbt.utils import MACRO_PREFIX


class GenericTestParser(BaseParser[ParsedGenericTestNode]):
Expand Down Expand Up @@ -47,9 +47,11 @@ def parse_unparsed_generic_test(
try:
blocks: List[jinja.BlockTag] = [
t for t in
jinja.extract_toplevel_blocks(base_node.raw_sql,
allowed_blocks={'test'},
collect_raw_data=False,)
jinja.extract_toplevel_blocks(
base_node.raw_sql,
allowed_blocks={'test'},
collect_raw_data=False,
)
if isinstance(t, jinja.BlockTag)
]
except CompilationException as exc:
Expand Down Expand Up @@ -91,7 +93,6 @@ def parse_file(self, block: FileBlock):
logger.debug("Parsing {}".format(original_file_path))

# this is really only used for error messages

base_node = UnparsedMacro(
path=original_file_path,
original_file_path=original_file_path,
Expand Down

0 comments on commit 31c142c

Please sign in to comment.