From d829dd40cafd3ead2a95596912422d732bf54626 Mon Sep 17 00:00:00 2001 From: Paul Yang Date: Fri, 10 May 2024 16:03:55 -0700 Subject: [PATCH] Add parser test for conversion metrics. --- .../query/test_conversion_metrics.py | 31 +++++++++++++++++++ ..._rate_with_constant_properties__result.txt | 24 ++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 metricflow-semantics/tests_metricflow_semantics/query/test_conversion_metrics.py create mode 100644 metricflow-semantics/tests_metricflow_semantics/snapshots/test_conversion_metrics.py/ParseQueryResult/test_conversion_rate_with_constant_properties__result.txt diff --git a/metricflow-semantics/tests_metricflow_semantics/query/test_conversion_metrics.py b/metricflow-semantics/tests_metricflow_semantics/query/test_conversion_metrics.py new file mode 100644 index 0000000000..fbe6176856 --- /dev/null +++ b/metricflow-semantics/tests_metricflow_semantics/query/test_conversion_metrics.py @@ -0,0 +1,31 @@ +from __future__ import annotations + +import pytest +from _pytest.fixtures import FixtureRequest +from dbt_semantic_interfaces.implementations.semantic_manifest import PydanticSemanticManifest +from metricflow_semantics.model.semantic_manifest_lookup import SemanticManifestLookup +from metricflow_semantics.query.query_parser import MetricFlowQueryParser +from metricflow_semantics.test_helpers.config_helpers import MetricFlowTestConfiguration +from metricflow_semantics.test_helpers.snapshot_helpers import assert_object_snapshot_equal + + +@pytest.fixture(scope="module") +def query_parser(simple_semantic_manifest: PydanticSemanticManifest) -> MetricFlowQueryParser: # noqa: D103 + return MetricFlowQueryParser(SemanticManifestLookup(simple_semantic_manifest)) + + +def test_conversion_rate_with_constant_properties( # noqa: D103 + request: FixtureRequest, + mf_test_configuration: MetricFlowTestConfiguration, + query_parser: MetricFlowQueryParser, +) -> None: + result = query_parser.parse_and_validate_query( + metric_names=("visit_buy_conversion_rate_by_session",), + group_by_names=("visit__referrer_id", "user__home_state_latest", "metric_time"), + ) + + assert_object_snapshot_equal( + request=request, + mf_test_configuration=mf_test_configuration, + obj=result, + ) diff --git a/metricflow-semantics/tests_metricflow_semantics/snapshots/test_conversion_metrics.py/ParseQueryResult/test_conversion_rate_with_constant_properties__result.txt b/metricflow-semantics/tests_metricflow_semantics/snapshots/test_conversion_metrics.py/ParseQueryResult/test_conversion_rate_with_constant_properties__result.txt new file mode 100644 index 0000000000..7eec0e4d6c --- /dev/null +++ b/metricflow-semantics/tests_metricflow_semantics/snapshots/test_conversion_metrics.py/ParseQueryResult/test_conversion_rate_with_constant_properties__result.txt @@ -0,0 +1,24 @@ +ParseQueryResult( + query_spec=MetricFlowQuerySpec( + metric_specs=(MetricSpec(element_name='visit_buy_conversion_rate_by_session'),), + dimension_specs=( + DimensionSpec( + element_name='referrer_id', + entity_links=(EntityReference(element_name='visit'),), + ), + DimensionSpec( + element_name='home_state_latest', + entity_links=(EntityReference(element_name='user'),), + ), + ), + time_dimension_specs=(TimeDimensionSpec(element_name='metric_time', time_granularity=DAY),), + filter_intersection=PydanticWhereFilterIntersection(), + filter_spec_resolution_lookup=FilterSpecResolutionLookUp(), + min_max_only=False, + ), + queried_semantic_models=( + SemanticModelReference(semantic_model_name='buys_source'), + SemanticModelReference(semantic_model_name='users_latest'), + SemanticModelReference(semantic_model_name='visits_source'), + ), +)