Skip to content

Commit

Permalink
Update time spine test fixture to support multiple
Browse files Browse the repository at this point in the history
  • Loading branch information
courtneyholcomb committed Jul 29, 2024
1 parent d7ea994 commit fdcf983
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
5 changes: 3 additions & 2 deletions tests_metricflow/dataflow/builder/test_node_data_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from _pytest.fixtures import FixtureRequest
from dbt_semantic_interfaces.references import SemanticModelElementReference
from dbt_semantic_interfaces.type_enums.time_granularity import TimeGranularity
from metricflow_semantics.aggregation_properties import AggregationState
from metricflow_semantics.instances import (
InstanceSet,
Expand Down Expand Up @@ -38,7 +39,7 @@

def test_no_parent_node_data_set(
simple_semantic_manifest_lookup: SemanticManifestLookup,
time_spine_source: TimeSpineSource,
time_spine_sources: Mapping[TimeGranularity, TimeSpineSource],
) -> None:
"""Tests getting the data set from a single node."""
resolver: DataflowPlanNodeOutputDataSetResolver = DataflowPlanNodeOutputDataSetResolver(
Expand Down Expand Up @@ -93,7 +94,7 @@ def test_joined_node_data_set(
mf_test_configuration: MetricFlowTestConfiguration,
mf_engine_test_fixture_mapping: Mapping[SemanticManifestSetup, MetricFlowEngineTestFixture],
simple_semantic_manifest_lookup: SemanticManifestLookup,
time_spine_source: TimeSpineSource,
time_spine_sources: Mapping[TimeGranularity, TimeSpineSource],
) -> None:
"""Tests getting the data set from a dataflow plan with a join."""
resolver: DataflowPlanNodeOutputDataSetResolver = DataflowPlanNodeOutputDataSetResolver(
Expand Down
26 changes: 23 additions & 3 deletions tests_metricflow/fixtures/dataflow_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import Mapping

import pytest
from dbt_semantic_interfaces.type_enums.time_granularity import TimeGranularity
from metricflow_semantics.query.query_parser import MetricFlowQueryParser
from metricflow_semantics.specs.column_assoc import ColumnAssociationResolver
from metricflow_semantics.test_helpers.config_helpers import MetricFlowTestConfiguration
Expand Down Expand Up @@ -90,7 +91,26 @@ def scd_query_parser( # noqa: D103


@pytest.fixture(scope="session")
def time_spine_source( # noqa: D103
def time_spine_sources( # noqa: D103
sql_client: SqlClient, mf_test_configuration: MetricFlowTestConfiguration # noqa: F811
) -> TimeSpineSource:
return TimeSpineSource(schema_name=mf_test_configuration.mf_source_schema, table_name="mf_time_spine")
) -> Mapping[TimeGranularity, TimeSpineSource]:
legacy_time_spine_grain = TimeGranularity.DAY
time_spine_base_table_name = "mf_time_spine"
print("expected schema name:", mf_test_configuration.mf_source_schema)
# Legacy time spine
time_spine_sources = {
legacy_time_spine_grain: TimeSpineSource(
schema_name=mf_test_configuration.mf_source_schema, table_name=time_spine_base_table_name
)
}
# Current time spines
for granularity in TimeGranularity:
if granularity.to_int() < legacy_time_spine_grain.to_int():
time_spine_sources[granularity] = TimeSpineSource(
schema_name=mf_test_configuration.mf_source_schema,
table_name=f"{time_spine_base_table_name}_{granularity.value}",
time_column_name="ts",
time_column_granularity=granularity,
)

return time_spine_sources
4 changes: 3 additions & 1 deletion tests_metricflow/integration/conftest.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from __future__ import annotations

from dataclasses import dataclass
from typing import Mapping

import pytest
from dbt_semantic_interfaces.test_utils import as_datetime
from dbt_semantic_interfaces.type_enums.time_granularity import TimeGranularity
from metricflow_semantics.model.semantic_manifest_lookup import SemanticManifestLookup
from metricflow_semantics.specs.dunder_column_association_resolver import DunderColumnAssociationResolver
from metricflow_semantics.test_helpers.config_helpers import MetricFlowTestConfiguration
Expand All @@ -29,7 +31,7 @@ def it_helpers( # noqa: D103
sql_client: SqlClient,
create_source_tables: bool,
simple_semantic_manifest_lookup: SemanticManifestLookup,
time_spine_source: TimeSpineSource,
time_spine_sources: Mapping[TimeGranularity, TimeSpineSource],
mf_test_configuration: MetricFlowTestConfiguration,
) -> IntegrationTestHelpers:
return IntegrationTestHelpers(
Expand Down
3 changes: 2 additions & 1 deletion tests_metricflow/integration/test_configured_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,13 +235,14 @@ def test_case(
name: str,
mf_test_configuration: MetricFlowTestConfiguration,
mf_engine_test_fixture_mapping: Mapping[SemanticManifestSetup, MetricFlowEngineTestFixture],
time_spine_source: TimeSpineSource,
time_spine_sources: Mapping[TimeGranularity, TimeSpineSource],
sql_client: SqlClient,
create_source_tables: bool,
) -> None:
"""Runs all integration tests configured in the test case YAML directory."""
case = CONFIGURED_INTEGRATION_TESTS_REPOSITORY.get_test_case(name)
logger.info(f"Running integration test case: '{case.name}' from file '{case.file_path}'")
time_spine_source = time_spine_sources[TimeGranularity.DAY]

missing_required_features = filter_not_supported_features(sql_client, case.required_features)
if missing_required_features:
Expand Down

0 comments on commit fdcf983

Please sign in to comment.