Skip to content

Commit

Permalink
Added more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DevonFulcher committed Nov 5, 2024
1 parent 61969a9 commit af097c1
Showing 1 changed file with 55 additions and 5 deletions.
60 changes: 55 additions & 5 deletions tests/unit/contracts/graph/test_semantic_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,21 @@ def test_require_yaml_configuration_for_mf_time_spines(
assert patched_deprecations.warn.call_count == 1

@pytest.mark.parametrize(
"metric_type_params, num_warns",
"metric_type_params, num_warns, should_error, flag_value",
[
(MetricTypeParams(grain_to_date=TimeGranularity.MONTH), 1),
(
MetricTypeParams(grain_to_date=TimeGranularity.MONTH),
1,
False,
False,
),
(
MetricTypeParams(
window=MetricTimeWindow(count=1, granularity=TimeGranularity.MONTH)
),
1,
False,
False,
),
(
MetricTypeParams(
Expand All @@ -72,6 +79,8 @@ def test_require_yaml_configuration_for_mf_time_spines(
)
),
0,
False,
False,
),
(
MetricTypeParams(
Expand All @@ -80,16 +89,57 @@ def test_require_yaml_configuration_for_mf_time_spines(
)
),
0,
False,
False,
),
(
MetricTypeParams(grain_to_date=TimeGranularity.MONTH),
0,
True,
True,
),
(
MetricTypeParams(
window=MetricTimeWindow(count=1, granularity=TimeGranularity.MONTH)
),
0,
True,
True,
),
(
MetricTypeParams(
cumulative_type_params=CumulativeTypeParams(
grain_to_date=TimeGranularity.MONTH,
)
),
0,
False,
True,
),
(
MetricTypeParams(
cumulative_type_params=CumulativeTypeParams(
window=MetricTimeWindow(count=1, granularity=TimeGranularity.MONTH),
)
),
0,
False,
True,
),
],
)
def test_deprecate_cumulative_type_params(
self, manifest: Manifest, metric_type_params: MetricTypeParams, num_warns: int
self,
manifest: Manifest,
metric_type_params: MetricTypeParams,
num_warns: int,
should_error: bool,
flag_value: bool,
):
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
patched_get_flags.return_value.require_nested_cumulative_type_params = flag_value
manifest.metrics["metric.test.my_metric"] = Metric(
name="my_metric",
type=MetricType.CUMULATIVE,
Expand All @@ -104,5 +154,5 @@ def test_deprecate_cumulative_type_params(
label="My Metric",
)
sm_manifest = SemanticManifest(manifest)
assert sm_manifest.validate()
assert sm_manifest.validate() != should_error
assert patched_deprecations.warn.call_count == num_warns

0 comments on commit af097c1

Please sign in to comment.