Skip to content

Commit

Permalink
Add parser test for conversion metrics.
Browse files Browse the repository at this point in the history
  • Loading branch information
plypaul committed May 11, 2024
1 parent aa3190c commit 15830bc
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from __future__ import annotations

import pytest
from _pytest.fixtures import FixtureRequest
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) -> MetricFlowQueryParser: # noqa: D103
return MetricFlowQueryParser(SemanticManifestLookup(simple_semantic_manifest))


@pytest.mark.sql_engine_snapshot
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,
)
Original file line number Diff line number Diff line change
@@ -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'),
),
)

0 comments on commit 15830bc

Please sign in to comment.