コード例 #1
0
ファイル: test_context.py プロジェクト: chrisp-data/all_data
def test_macro_namespace(config, manifest_fx):
    mn = macros.MacroNamespaceBuilder('root', 'search', MacroStack(),
                                      ['dbt_postgres', 'dbt'])

    dbt_macro = mock_macro('some_macro', 'dbt')
    # same namespace, same name, different pkg!
    pg_macro = mock_macro('some_macro', 'dbt_postgres')
    # same name, different package
    package_macro = mock_macro('some_macro', 'root')

    all_macros = itertools.chain(manifest_fx.macros.values(),
                                 [dbt_macro, pg_macro, package_macro])

    namespace = mn.build_namespace(all_macros, {})
    dct = dict(namespace)
    for result in [dct, namespace]:
        assert 'dbt' in result
        assert 'root' in result
        assert 'some_macro' in result
        assert 'dbt_postgres' not in result
        # tests __len__
        assert len(result) == 5
        # tests __iter__
        assert set(result) == {
            'dbt', 'root', 'some_macro', 'macro_a', 'macro_b'
        }
        assert len(result['dbt']) == 1
        # from the regular manifest + some_macro
        assert len(result['root']) == 3
        assert result['dbt']['some_macro'].macro is pg_macro
        assert result['root']['some_macro'].macro is package_macro
        assert result['some_macro'].macro is package_macro
コード例 #2
0
 def __init__(
     self,
     config: AdapterRequiredConfig,
     manifest: Manifest,
     search_package: str,
 ) -> None:
     super().__init__(config)
     self.manifest = manifest
     self.search_package = search_package
     self.macro_stack = MacroStack()
コード例 #3
0
ファイル: test_context.py プロジェクト: chrisp-data/all_data
def test_macro_namespace_duplicates(config, manifest_fx):
    mn = macros.MacroNamespaceBuilder('root', 'search', MacroStack(),
                                      ['dbt_postgres', 'dbt'])
    mn.add_macros(manifest_fx.macros.values(), {})

    # same pkg, same name: error
    with pytest.raises(dbt.exceptions.CompilationException):
        mn.add_macro(mock_macro('macro_a', 'root'), {})

    # different pkg, same name: no error
    mn.add_macros(mock_macro('macro_a', 'dbt'), {})
コード例 #4
0
def test_macro_namespace(config, manifest):
    mn = configured.MacroNamespace('root', 'search', MacroStack())
    mn.add_macros(manifest.macros.values(), {})

    # same pkg, same name
    with pytest.raises(dbt.exceptions.CompilationException):
        mn.add_macros(manifest.macros.values(), {})

    mn.add_macro(mock_macro('some_macro', 'dbt'), {})

    # same namespace, same name (different pkg!)
    with pytest.raises(dbt.exceptions.CompilationException):
        mn.add_macro(mock_macro('some_macro', 'dbt_postgres'), {})
コード例 #5
0
ファイル: manifest.py プロジェクト: abhinav-spoj1996/fivetran
 def __init__(
     self,
     config: AdapterRequiredConfig,
     manifest: Manifest,
     search_package: str,
 ) -> None:
     super().__init__(config)
     self.manifest = manifest
     self.search_package = search_package
     self.macro_stack = MacroStack()
     builder = self._get_namespace_builder()
     self.namespace = builder.build_namespace(
         self.manifest.macros.values(),
         self._ctx,
     )
コード例 #6
0
ファイル: manifest.py プロジェクト: chrisp-data/all_data
 def __init__(
     self,
     config: AdapterRequiredConfig,
     manifest: Manifest,
     search_package: str,
 ) -> None:
     super().__init__(config)
     self.manifest = manifest
     # this is the package of the node for which this context was built
     self.search_package = search_package
     self.macro_stack = MacroStack()
     # This namespace is used by the BaseDatabaseWrapper in jinja rendering.
     # The namespace is passed to it when it's constructed. It expects
     # to be able to do: namespace.get_from_package(..)
     self.namespace = self._build_namespace()
コード例 #7
0
 def __init__(
     self,
     model,
     config: RuntimeConfig,
     manifest: Manifest,
     provider: Provider,
     context_config: Optional[ContextConfig],
     macro_resolver: MacroResolver,
 ) -> None:
     # this must be before super init so that macro_resolver exists for
     # build_namespace
     self.macro_resolver = macro_resolver
     self.thread_ctx = MacroStack()
     super().__init__(model, config, manifest, provider, context_config)
     self._build_test_namespace
コード例 #8
0
ファイル: providers.py プロジェクト: chrisp-data/all_data
 def __init__(
     self,
     model,
     config: RuntimeConfig,
     manifest: Manifest,
     provider: Provider,
     context_config: Optional[ContextConfig],
     macro_resolver: MacroResolver,
 ) -> None:
     # this must be before super init so that macro_resolver exists for
     # build_namespace
     self.macro_resolver = macro_resolver
     self.thread_ctx = MacroStack()
     super().__init__(model, config, manifest, provider, context_config)
     self._build_test_namespace()
     # We need to rebuild this because it's already been built by
     # the ProviderContext with the wrong namespace.
     self.db_wrapper = self.provider.DatabaseWrapper(
         self.adapter, self.namespace)