def _create_node_context( self, node: NonSourceCompiledNode, manifest: Manifest, extra_context: Dict[str, Any], ) -> Dict[str, Any]: context = generate_runtime_model(node, self.config, manifest) context.update(extra_context) if isinstance(node, CompiledSchemaTestNode): # for test nodes, add a special keyword args value to the context jinja.add_rendered_test_kwargs(context, node) return context
def render_with_context( self, node: ParsedSchemaTestNode, config: ContextConfigType, ) -> None: """Given the parsed node and a ContextConfigType to use during parsing, collect all the refs that might be squirreled away in the test arguments. This includes the implicit "model" argument. """ # make a base context that doesn't have the magic kwargs field context = self._context_for(node, config) # update it with the rendered test kwargs (which collects any refs) add_rendered_test_kwargs(context, node, capture_macros=True) # the parsed node is not rendered in the native context. get_rendered(node.raw_sql, context, node, capture_macros=True)
def render_test_update(self, node, config, builder): macro_unique_id = self.macro_resolver.get_macro_id( node.package_name, 'test_' + builder.name) # Add the depends_on here so we can limit the macros added # to the context in rendering processing node.depends_on.add_macro(macro_unique_id) if (macro_unique_id in ['macro.dbt.test_not_null', 'macro.dbt.test_unique']): self.update_parsed_node(node, config) if builder.severity() is not None: node.unrendered_config['severity'] = builder.severity() node.config['severity'] = builder.severity() if builder.enabled() is not None: node.config['enabled'] = builder.enabled() # source node tests are processed at patch_source time if isinstance(builder.target, UnpatchedSourceDefinition): sources = [builder.target.fqn[-2], builder.target.fqn[-1]] node.sources.append(sources) else: # all other nodes node.refs.append([builder.target.name]) else: try: # make a base context that doesn't have the magic kwargs field context = generate_test_context( node, self.root_project, self.manifest, config, self.macro_resolver, ) # update with rendered test kwargs (which collects any refs) add_rendered_test_kwargs(context, node, capture_macros=True) # the parsed node is not rendered in the native context. get_rendered(node.raw_sql, context, node, capture_macros=True) self.update_parsed_node(node, config) except ValidationError as exc: # we got a ValidationError - probably bad types in config() msg = validator_error_message(exc) raise CompilationException(msg, node=node) from exc