Skip to content

Commit

Permalink
add more package materialization + deprecation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MichelleArk committed Apr 18, 2024
1 parent c47e094 commit 018252e
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 6 deletions.
24 changes: 24 additions & 0 deletions tests/functional/materializations/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,21 @@
{%- endmaterialization -%}
"""

custom_materialization_dep__dbt_project_yml = """
name: custom_materialization_default
macro-paths: ['macros']
"""

custom_materialization_sql = """
{% materialization custom_materialization, default %}
{%- set target_relation = this.incorporate(type='table') %}
{% call statement('main') -%}
select 1 as column1
{%- endcall %}
{{ return({'relations': [target_relation]}) }}
{% endmaterialization %}
"""


@pytest.fixture(scope="class")
def override_view_adapter_pass_dep(project_root):
Expand Down Expand Up @@ -368,3 +383,12 @@ def override_view_return_no_relation(project_root):
},
}
write_project_files(project_root, "override-view-return-no-relation", files)


@pytest.fixture(scope="class")
def custom_materialization_dep(project_root):
files = {
"dbt_project.yml": custom_materialization_dep__dbt_project_yml,
"macros": {"custom_materialization.sql": custom_materialization_sql},
}
write_project_files(project_root, "custom-materialization-dep", files)
74 changes: 68 additions & 6 deletions tests/functional/materializations/test_custom_materialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,99 @@
"""


models_custom_materialization__model_sql = """
{{ config(materialized='custom_materialization') }}
select 1 as id
"""


@pytest.fixture(scope="class")
def models():
return {"model.sql": models__model_sql}


@pytest.fixture(scope="class")
def set_up_deprecations():
deprecations.reset_deprecations()
assert deprecations.active_deprecations == set()


class TestOverrideAdapterDependency:
# make sure that if there's a dependency with an adapter-specific
# materialization, we honor that materialization
@pytest.fixture(scope="class")
def packages(self):
return {"packages": [{"local": "override-view-adapter-dep"}]}

def test_adapter_dependency(self, project, override_view_adapter_dep):
def test_adapter_dependency(self, project, override_view_adapter_dep, set_up_deprecations):
run_dbt(["deps"])
# this should error because the override is buggy
run_dbt(["run"], expect_pass=False)

# overriding a built-in materialization scoped to adapter from package is deprecated
assert deprecations.active_deprecations == {"package-materialization-override"}


class TestOverrideDefaultDependency:
@pytest.fixture(scope="class")
def packages(self):
return {"packages": [{"local": "override-view-default-dep"}]}

def test_default_dependency(self, project, override_view_default_dep):
def test_default_dependency(self, project, override_view_default_dep, set_up_deprecations):
run_dbt(["deps"])
# this should error because the override is buggy
run_dbt(["run"], expect_pass=False)

# overriding a built-in materialization from package is deprecated
assert deprecations.active_deprecations == {"package-materialization-override"}


root_view_override_macro = """
{% materialization view, default %}
{{ return(view_default_override.materialization_view_default()) }}
{% endmaterialization %}
"""


class TestOverrideDefaultDependencyRootOverride:
@pytest.fixture(scope="class")
def packages(self):
return {"packages": [{"local": "override-view-default-dep"}]}

@pytest.fixture(scope="class")
def macros(self):
return {"my_view.sql": root_view_override_macro}

def test_default_dependency_with_root_override(
self, project, override_view_default_dep, set_up_deprecations
):
run_dbt(["deps"])
deprecations.reset_deprecations()
assert deprecations.active_deprecations == set()
# this should error because the override is buggy
run_dbt(["run"], expect_pass=False)
expected = {"package-materialization-override"}
assert expected == deprecations.active_deprecations

# using an package-overriden built-in materialization in a root matereialization is _not_ deprecated
assert deprecations.active_deprecations == set()


class TestCustomMaterializationDependency:
@pytest.fixture(scope="class")
def models(self):
return {"model.sql": models_custom_materialization__model_sql}

@pytest.fixture(scope="class")
def packages(self):
return {"packages": [{"local": "custom-materialization-dep"}]}

def test_custom_materialization_deopendency(
self, project, custom_materialization_dep, set_up_deprecations
):
run_dbt(["deps"])
# custom materilization is valid
run_dbt(["run"])

# using a custom materialization is from an installed package is _not_ deprecated
assert deprecations.active_deprecations == set()


class TestOverrideAdapterDependencyPassing:
Expand Down

0 comments on commit 018252e

Please sign in to comment.