From af097c1343e4ac2f05954c68bf992dd0abc7307e Mon Sep 17 00:00:00 2001 From: Devon Fulcher <24593113+DevonFulcher@users.noreply.github.com> Date: Tue, 5 Nov 2024 14:05:42 -0600 Subject: [PATCH] Added more tests --- .../contracts/graph/test_semantic_manifest.py | 60 +++++++++++++++++-- 1 file changed, 55 insertions(+), 5 deletions(-) diff --git a/tests/unit/contracts/graph/test_semantic_manifest.py b/tests/unit/contracts/graph/test_semantic_manifest.py index f4cbd4bca78..043f9b7ad33 100644 --- a/tests/unit/contracts/graph/test_semantic_manifest.py +++ b/tests/unit/contracts/graph/test_semantic_manifest.py @@ -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( @@ -72,6 +79,8 @@ def test_require_yaml_configuration_for_mf_time_spines( ) ), 0, + False, + False, ), ( MetricTypeParams( @@ -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, @@ -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