def test_raise_duplicate_macros_same_package(): macro_1 = MockMacro(package='dbt', name='some_macro') macro_2 = MockMacro(package='dbt', name='some_macro') with pytest.raises(CompilationException) as exc: raise_duplicate_macro_name( node_1=macro_1, node_2=macro_2, namespace='dbt', ) assert 'some_macro' in str(exc.value) assert 'namespace "dbt"' in str(exc.value) assert "are both in" not in str(exc.value)
def _add_macro_to( self, package_namespaces: Dict[str, MacroNamespace], macro: ParsedMacro, ): if macro.package_name in package_namespaces: namespace = package_namespaces[macro.package_name] else: namespace = {} package_namespaces[macro.package_name] = namespace if macro.name in namespace: raise_duplicate_macro_name(macro, macro, macro.package_name) package_namespaces[macro.package_name][macro.name] = macro
def test_raise_duplicate_macros_different_package(): macro_1 = MockMacro(package='dbt', name='some_macro') macro_2 = MockMacro(package='dbt-myadapter', name='some_macro') with pytest.raises(CompilationException) as exc: raise_duplicate_macro_name( node_1=macro_1, node_2=macro_2, namespace='dbt', ) assert 'dbt-myadapter' in str(exc.value) assert 'some_macro' in str(exc.value) assert 'namespace "dbt"' in str(exc.value) assert '("dbt" and "dbt-myadapter" are both in the "dbt" namespace)' in str( exc.value)
def _add_macro_to( self, hierarchy: Dict[str, FlatNamespace], macro: ParsedMacro, macro_func: MacroGenerator, ): if macro.package_name in hierarchy: namespace = hierarchy[macro.package_name] else: namespace = {} hierarchy[macro.package_name] = namespace if macro.name in namespace: raise_duplicate_macro_name(macro_func.macro, macro, macro.package_name) hierarchy[macro.package_name][macro.name] = macro_func
def add_macro(self, macro: ParsedMacro, ctx: Dict[str, Any]): macro_name: str = macro.name macro_func: MacroGenerator = MacroGenerator(macro, ctx, self.node, self.thread_ctx) # put plugin macros into the root namespace if macro.package_name in PACKAGES: namespace: str = GLOBAL_PROJECT_NAME else: namespace = macro.package_name if namespace not in self.packages: value: Dict[str, MacroGenerator] = {} self.packages[namespace] = value if macro_name in self.packages[namespace]: raise_duplicate_macro_name(macro_func.macro, macro, namespace) self.packages[namespace][macro_name] = macro_func if namespace == self.search_package: self.locals[macro_name] = macro_func elif namespace in {self.root_package, GLOBAL_PROJECT_NAME}: self.globals[macro_name] = macro_func