From fdcf983f91555da7f9e8c79ec294689816f3c623 Mon Sep 17 00:00:00 2001 From: Courtney Holcomb Date: Sat, 27 Jul 2024 10:27:17 -0700 Subject: [PATCH] Update time spine test fixture to support multiple --- .../dataflow/builder/test_node_data_set.py | 5 ++-- .../fixtures/dataflow_fixtures.py | 26 ++++++++++++++++--- tests_metricflow/integration/conftest.py | 4 ++- .../integration/test_configured_cases.py | 3 ++- 4 files changed, 31 insertions(+), 7 deletions(-) diff --git a/tests_metricflow/dataflow/builder/test_node_data_set.py b/tests_metricflow/dataflow/builder/test_node_data_set.py index 1402472277..86bc84d7d5 100644 --- a/tests_metricflow/dataflow/builder/test_node_data_set.py +++ b/tests_metricflow/dataflow/builder/test_node_data_set.py @@ -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, @@ -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( @@ -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( diff --git a/tests_metricflow/fixtures/dataflow_fixtures.py b/tests_metricflow/fixtures/dataflow_fixtures.py index 76604df857..362725c605 100644 --- a/tests_metricflow/fixtures/dataflow_fixtures.py +++ b/tests_metricflow/fixtures/dataflow_fixtures.py @@ -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 @@ -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 diff --git a/tests_metricflow/integration/conftest.py b/tests_metricflow/integration/conftest.py index 7fef0e7567..5c0da3bdb1 100644 --- a/tests_metricflow/integration/conftest.py +++ b/tests_metricflow/integration/conftest.py @@ -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 @@ -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( diff --git a/tests_metricflow/integration/test_configured_cases.py b/tests_metricflow/integration/test_configured_cases.py index 2193c9d1d5..1a781ebdf9 100644 --- a/tests_metricflow/integration/test_configured_cases.py +++ b/tests_metricflow/integration/test_configured_cases.py @@ -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: