Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamDee committed Nov 12, 2024
1 parent 6983d64 commit 890a1b0
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 5 deletions.
36 changes: 36 additions & 0 deletions tests/functional/metrics/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,8 @@
dimensions:
- name: purchased_at
type: TIME
type_params:
time_granularity: day
entities:
- name: purchase
type: primary
Expand Down Expand Up @@ -736,6 +738,8 @@
dimensions:
- name: purchased_at
type: TIME
type_params:
time_granularity: day
entities:
- name: purchase
type: primary
Expand Down Expand Up @@ -796,6 +800,20 @@
type: cumulative
type_params:
measure: num_visits
- name: visits_martian_day
label: Visits since start of martian_day
type: cumulative
type_params:
measure: num_visits
cumulative_type_params:
grain_to_date: martian_day
- name: visits_martian_day_window
label: Visits since start of martian_day window
type: cumulative
type_params:
measure: num_visits
cumulative_type_params:
window: 1 martian_day
"""

conversion_metric_yml = """
Expand All @@ -809,6 +827,24 @@
base_measure: num_visits
conversion_measure: num_orders
entity: purchase
- name: converted_orders_over_visits_with_window
label: Number of orders converted from visits with window
type: conversion
type_params:
conversion_type_params:
base_measure: num_visits
conversion_measure: num_orders
entity: purchase
window: 4 day
- name: converted_orders_over_visits_with_custom_window
label: Number of orders converted from visits with custom window
type: conversion
type_params:
conversion_type_params:
base_measure: num_visits
conversion_measure: num_orders
entity: purchase
window: 4 martian_day
"""

filtered_metrics_yml = """
Expand Down
31 changes: 26 additions & 5 deletions tests/functional/metrics/test_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
semantic_model_people_yml,
semantic_model_purchasing_yml,
)
from tests.functional.time_spines.fixtures import time_spine_yml


class TestSimpleMetrics:
Expand Down Expand Up @@ -361,6 +362,7 @@ def models(self):
"metricflow_time_spine.sql": metricflow_time_spine_sql,
"semantic_models.yml": conversion_semantic_model_purchasing_yml,
"conversion_metric.yml": conversion_metric_yml,
"time_spine.yml": time_spine_yml,
}

@pytest.fixture(scope="class")
Expand All @@ -382,10 +384,16 @@ def test_conversion_metric(
# make sure the metric is in the manifest
manifest = get_manifest(project.project_root)
metric_ids = list(manifest.metrics.keys())
expected_metric_ids = [
"metric.test.converted_orders_over_visits",
]
assert metric_ids == expected_metric_ids
expected_metric_ids = {
"metric.test.converted_orders_over_visits": None,
"metric.test.converted_orders_over_visits_with_window": MetricTimeWindow(
count=4, granularity=TimeGranularity.DAY.value
),
"metric.test.converted_orders_over_visits_with_custom_window": MetricTimeWindow(
count=4, granularity="martian_day"
),
}
assert set(metric_ids) == set(expected_metric_ids.keys())
assert manifest.metrics[
"metric.test.converted_orders_over_visits"
].type_params.conversion_type_params
Expand All @@ -409,6 +417,14 @@ def test_conversion_metric(
].type_params.conversion_type_params.entity
== "purchase"
)
for (
metric_id,
expected_window,
) in expected_metric_ids.items():
assert (
manifest.metrics[metric_id].type_params.conversion_type_params.window
== expected_window
), f"Found unexpected conversion window for {metric_id}"


class TestCumulativeMetric:
Expand All @@ -418,7 +434,8 @@ def models(self):
"purchasing.sql": purchasing_model_sql,
"metricflow_time_spine.sql": metricflow_time_spine_sql,
"semantic_models.yml": conversion_semantic_model_purchasing_yml,
"conversion_metric.yml": cumulative_metric_yml,
"cumulative_metric.yml": cumulative_metric_yml,
"time_spine.yml": time_spine_yml,
}

@pytest.fixture(scope="class")
Expand Down Expand Up @@ -459,6 +476,10 @@ def test_cumulative_metric(self, project):
"metric.test.cumulative_visits": CumulativeTypeParams(
period_agg=PeriodAggregation.FIRST
),
"metric.test.visits_martian_day": CumulativeTypeParams(grain_to_date="martian_day"),
"metric.test.visits_martian_day_window": CumulativeTypeParams(
window=MetricTimeWindow(count=1, granularity="martian_day"),
),
}
assert metric_ids == set(expected_metric_ids_to_cumulative_type_params.keys())
for (
Expand Down
18 changes: 18 additions & 0 deletions tests/functional/time_spines/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,21 @@
- name: date_day
granularity: day
"""

time_spine_yml = """
version: 2
models:
- name: metricflow_time_spine
time_spine:
standard_granularity_column: date_day
custom_granularities:
- name: retail_month
- name: martian_day
column_name: martian_day
columns:
- name: date_day
granularity: day
- name: retail_month
- name: martian_day
"""

0 comments on commit 890a1b0

Please sign in to comment.