Skip to content

Commit

Permalink
More unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DevonFulcher committed Oct 31, 2024
1 parent 2e6f4bc commit 33bd179
Showing 1 changed file with 42 additions and 33 deletions.
75 changes: 42 additions & 33 deletions tests/unit/contracts/graph/test_semantic_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit 33bd179

Please sign in to comment.