diff --git a/tests/unit/contracts/graph/test_semantic_manifest.py b/tests/unit/contracts/graph/test_semantic_manifest.py index ba8c731c497..2351a95715a 100644 --- a/tests/unit/contracts/graph/test_semantic_manifest.py +++ b/tests/unit/contracts/graph/test_semantic_manifest.py @@ -5,7 +5,11 @@ from core.dbt.contracts.graph.manifest import Manifest from core.dbt.contracts.graph.nodes import Metric, ModelNode from dbt.artifacts.resources.types import NodeType -from dbt.artifacts.resources.v1.metric import MetricTimeWindow, MetricTypeParams +from dbt.artifacts.resources.v1.metric import ( + CumulativeTypeParams, + MetricTimeWindow, + MetricTypeParams, +) from dbt.contracts.graph.semantic_manifest import SemanticManifest from dbt_semantic_interfaces.type_enums import TimeGranularity from dbt_semantic_interfaces.type_enums.metric_type import MetricType @@ -52,48 +56,53 @@ def test_require_yaml_configuration_for_mf_time_spines( assert patched_deprecations.warn.call_count == 1 @pytest.mark.parametrize( - "metric", + "metric_type_params, num_warns", [ + (MetricTypeParams(grain_to_date=TimeGranularity.MONTH), 1), ( - Metric( - name="my_metric", - type=MetricType.CUMULATIVE, - type_params=MetricTypeParams(grain_to_date=TimeGranularity.MONTH), - resource_type=NodeType.Metric, - package_name="test", - path="models/test/my_metric.yml", - original_file_path="models/test/my_metric.yml", - unique_id="metric.test.my_metric", - fqn=["test", "my_metric"], - description="My metric", - label="My Metric", - ) + MetricTypeParams( + window=MetricTimeWindow(count=1, granularity=TimeGranularity.MONTH) + ), + 1, ), ( - Metric( - name="my_metric", - type=MetricType.CUMULATIVE, - type_params=MetricTypeParams( - window=MetricTimeWindow(count=1, granularity=TimeGranularity.MONTH) - ), - resource_type=NodeType.Metric, - package_name="test", - path="models/test/my_metric.yml", - original_file_path="models/test/my_metric.yml", - unique_id="metric.test.my_metric", - fqn=["test", "my_metric"], - description="My metric", - label="My Metric", - ) + MetricTypeParams( + window=MetricTimeWindow(count=1, granularity=TimeGranularity.MONTH), + grain_to_date=TimeGranularity.MONTH, + ), + 1, + ), + ( + MetricTypeParams( + cumulative_type_params=CumulativeTypeParams( + window=MetricTimeWindow(count=1, granularity=TimeGranularity.MONTH), + grain_to_date=TimeGranularity.MONTH, + ) + ), + 0, ), ], ) - def test_deprecate_cumulative_type_params(self, manifest: Manifest, metric: Metric): + def test_deprecate_cumulative_type_params( + self, manifest: Manifest, metric_type_params: MetricTypeParams, num_warns: int + ): with patch("dbt.contracts.graph.semantic_manifest.get_flags") as patched_get_flags, patch( "dbt.contracts.graph.semantic_manifest.deprecations" ) as patched_deprecations: patched_get_flags.return_value.require_nested_cumulative_type_params = False - manifest.metrics[metric.unique_id] = metric + manifest.metrics["metric.test.my_metric"] = Metric( + name="my_metric", + type=MetricType.CUMULATIVE, + type_params=metric_type_params, + resource_type=NodeType.Metric, + package_name="test", + path="models/test/my_metric.yml", + original_file_path="models/test/my_metric.yml", + unique_id="metric.test.my_metric", + fqn=["test", "my_metric"], + description="My metric", + label="My Metric", + ) sm_manifest = SemanticManifest(manifest) assert sm_manifest.validate() - assert patched_deprecations.warn.call_count == 1 + assert patched_deprecations.warn.call_count == num_warns