Skip to content

Commit

Permalink
Add unit tests for _warn_for_unused_resource_config_paths method
Browse files Browse the repository at this point in the history
Note: At this point the test when run with for a `unit_test` config
taht should be considered used, fails. This is because it is not being
properly identified as used.
  • Loading branch information
QMalcolm committed Jun 14, 2024
1 parent c25fb92 commit fad3dd9
Showing 1 changed file with 48 additions and 1 deletion.
49 changes: 48 additions & 1 deletion tests/unit/parser/test_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
from dbt.artifacts.resources.base import FileHash
from dbt.config import RuntimeConfig
from dbt.contracts.graph.manifest import Manifest, ManifestStateCheck
from dbt.events.types import UnusedResourceConfigPath
from dbt.flags import set_from_args
from dbt.parser.manifest import ManifestLoader
from dbt.parser.manifest import ManifestLoader, _warn_for_unused_resource_config_paths
from dbt.parser.read_files import FileDiff
from dbt.tracking import User
from dbt_common.events.event_manager_client import add_callback_to_manager
from tests.utils import EventCatcher


class TestPartialParse:
Expand Down Expand Up @@ -191,3 +194,47 @@ def test_partial_parse_file_diff_flag(
set_from_args(Namespace(PARTIAL_PARSE_FILE_DIFF=False), {})
ManifestLoader.get_full_manifest(config=mock_project)
assert mock_file_diff.called


class TestWarnUnusedConfigs:
@pytest.mark.parametrize(
"resource_type,path,expect_used",
[
("data_tests", "unused_path", False),
("data_tests", "minimal", True),
("metrics", "unused_path", False),
("metrics", "test", True),
("models", "unused_path", False),
("models", "pkg", True),
("saved_queries", "unused_path", False),
("saved_queries", "test", True),
("seeds", "unused_path", False),
("seeds", "pkg", True),
("semantic_models", "unused_path", False),
("semantic_models", "test", True),
("sources", "unused_path", False),
("sources", "pkg", True),
("unit_tests", "unused_path", False),
("unit_tests", "pkg", True),
],
)
def test_warn_for_unused_resource_config_paths(
self,
resource_type: str,
path: str,
expect_used: bool,
manifest: Manifest,
runtime_config: RuntimeConfig,
) -> None:
catcher = EventCatcher(UnusedResourceConfigPath)
add_callback_to_manager(catcher.catch)

setattr(runtime_config, resource_type, {path: {"+materialized": "table"}})

_warn_for_unused_resource_config_paths(manifest=manifest, config=runtime_config)

if expect_used:
assert len(catcher.caught_events) == 0
else:
assert len(catcher.caught_events) == 1
assert f"{resource_type}.{path}" in str(catcher.caught_events[0].data)

0 comments on commit fad3dd9

Please sign in to comment.