From 7dad28b1b73505179e90f0ee3310f729aa864f4a Mon Sep 17 00:00:00 2001 From: Paul Yang Date: Mon, 5 Feb 2024 12:50:56 -0800 Subject: [PATCH] Move fixtures from model_fixtures.py to manifest_fixtures.py. There was an earlier rename from model -> semantic manifest. --- metricflow/test/conftest.py | 1 - metricflow/test/fixtures/manifest_fixtures.py | 101 ++++++++++++++- metricflow/test/fixtures/model_fixtures.py | 115 ------------------ 3 files changed, 100 insertions(+), 117 deletions(-) delete mode 100644 metricflow/test/fixtures/model_fixtures.py diff --git a/metricflow/test/conftest.py b/metricflow/test/conftest.py index 0692295365..525b2a30a9 100644 --- a/metricflow/test/conftest.py +++ b/metricflow/test/conftest.py @@ -5,7 +5,6 @@ from metricflow.test.fixtures.dataflow_fixtures import * # noqa: F401, F403 from metricflow.test.fixtures.id_fixtures import * # noqa: F401, F403 from metricflow.test.fixtures.manifest_fixtures import * # noqa: F401, F403 -from metricflow.test.fixtures.model_fixtures import * # noqa: F401, F403 from metricflow.test.fixtures.setup_fixtures import * # noqa: F401, F403 from metricflow.test.fixtures.sql_client_fixtures import * # noqa: F401, F403 from metricflow.test.fixtures.sql_fixtures import * # noqa: F401, F403 diff --git a/metricflow/test/fixtures/manifest_fixtures.py b/metricflow/test/fixtures/manifest_fixtures.py index 88bc62d302..e43c73c91f 100644 --- a/metricflow/test/fixtures/manifest_fixtures.py +++ b/metricflow/test/fixtures/manifest_fixtures.py @@ -13,7 +13,7 @@ SemanticManifestBuildResult, parse_directory_of_yaml_files_to_semantic_manifest, ) -from dbt_semantic_interfaces.protocols import SemanticModel +from dbt_semantic_interfaces.protocols import SemanticManifest, SemanticModel from dbt_semantic_interfaces.test_utils import as_datetime from dbt_semantic_interfaces.validations.semantic_manifest_validator import SemanticManifestValidator @@ -198,3 +198,102 @@ def load_semantic_manifest( def template_mapping(mf_test_session_state: MetricFlowTestSessionState) -> Dict[str, str]: """Mapping for template variables in the model YAML files.""" return {"source_schema": mf_test_session_state.mf_source_schema} + + +@pytest.fixture(scope="session") +def simple_semantic_manifest_lookup_non_ds( # noqa: D + mf_engine_test_fixture_mapping: Mapping[SemanticManifestName, MetricFlowEngineTestFixture] +) -> SemanticManifestLookup: + return mf_engine_test_fixture_mapping[SemanticManifestName.NON_SM_MANIFEST].semantic_manifest_lookup + + +@pytest.fixture(scope="session") +def simple_semantic_manifest_lookup( # noqa: D + mf_engine_test_fixture_mapping: Mapping[SemanticManifestName, MetricFlowEngineTestFixture] +) -> SemanticManifestLookup: + return mf_engine_test_fixture_mapping[SemanticManifestName.SIMPLE_MANIFEST].semantic_manifest_lookup + + +@pytest.fixture(scope="session") +def partitioned_multi_hop_join_semantic_manifest_lookup( # noqa: D + mf_engine_test_fixture_mapping: Mapping[SemanticManifestName, MetricFlowEngineTestFixture] +) -> SemanticManifestLookup: + return mf_engine_test_fixture_mapping[ + SemanticManifestName.PARTITIONED_MULTI_HOP_JOIN_MANIFEST + ].semantic_manifest_lookup + + +@pytest.fixture(scope="session") +def multi_hop_join_semantic_manifest_lookup( # noqa: D + mf_engine_test_fixture_mapping: Mapping[SemanticManifestName, MetricFlowEngineTestFixture] +) -> SemanticManifestLookup: + return mf_engine_test_fixture_mapping[SemanticManifestName.MULTI_HOP_JOIN_MANIFEST].semantic_manifest_lookup + + +@pytest.fixture(scope="session") +def simple_semantic_manifest( + mf_engine_test_fixture_mapping: Mapping[SemanticManifestName, MetricFlowEngineTestFixture] +) -> SemanticManifest: + """Model used for many tests.""" + return mf_engine_test_fixture_mapping[SemanticManifestName.SIMPLE_MANIFEST].semantic_manifest + + +@pytest.fixture(scope="session") +def extended_date_semantic_manifest_lookup( # noqa: D + mf_engine_test_fixture_mapping: Mapping[SemanticManifestName, MetricFlowEngineTestFixture] +) -> SemanticManifestLookup: + return mf_engine_test_fixture_mapping[SemanticManifestName.EXTENDED_DATE_MANIFEST].semantic_manifest_lookup + + +@pytest.fixture(scope="session") +def scd_semantic_manifest_lookup( + mf_engine_test_fixture_mapping: Mapping[SemanticManifestName, MetricFlowEngineTestFixture] +) -> SemanticManifestLookup: + """Initialize semantic model for SCD tests.""" + return mf_engine_test_fixture_mapping[SemanticManifestName.SCD_MANIFEST].semantic_manifest_lookup + + +@pytest.fixture(scope="session") +def data_warehouse_validation_model( + mf_engine_test_fixture_mapping: Mapping[SemanticManifestName, MetricFlowEngineTestFixture] +) -> SemanticManifest: + """Model used for data warehouse validation tests.""" + return mf_engine_test_fixture_mapping[SemanticManifestName.DATA_WAREHOUSE_VALIDATION_MANIFEST].semantic_manifest + + +@pytest.fixture(scope="session") +def cyclic_join_semantic_manifest_lookup( + mf_engine_test_fixture_mapping: Mapping[SemanticManifestName, MetricFlowEngineTestFixture] +) -> SemanticManifestLookup: + """Manifest that contains a potential cycle in the join graph (if not handled properly).""" + return mf_engine_test_fixture_mapping[SemanticManifestName.CYCLIC_JOIN_MANIFEST].semantic_manifest_lookup + + +@pytest.fixture(scope="session") +def ambiguous_resolution_manifest( + mf_engine_test_fixture_mapping: Mapping[SemanticManifestName, MetricFlowEngineTestFixture] +) -> PydanticSemanticManifest: + """Manifest used to test ambiguous resolution of group-by-items.""" + return mf_engine_test_fixture_mapping[SemanticManifestName.AMBIGUOUS_RESOLUTION_MANIFEST].semantic_manifest + + +@pytest.fixture(scope="session") +def ambiguous_resolution_manifest_lookup( # noqa: D + mf_engine_test_fixture_mapping: Mapping[SemanticManifestName, MetricFlowEngineTestFixture] +) -> SemanticManifestLookup: + return mf_engine_test_fixture_mapping[SemanticManifestName.AMBIGUOUS_RESOLUTION_MANIFEST].semantic_manifest_lookup + + +@pytest.fixture(scope="session") +def simple_multi_hop_join_manifest( # noqa: D + mf_engine_test_fixture_mapping: Mapping[SemanticManifestName, MetricFlowEngineTestFixture] +) -> PydanticSemanticManifest: + return mf_engine_test_fixture_mapping[SemanticManifestName.SIMPLE_MULTI_HOP_JOIN_MANIFEST].semantic_manifest + + +@pytest.fixture(scope="session") +def simple_multi_hop_join_manifest_lookup( # noqa: D + mf_engine_test_fixture_mapping: Mapping[SemanticManifestName, MetricFlowEngineTestFixture] +) -> SemanticManifestLookup: + """Manifest used to test ambiguous resolution of group-by-items.""" + return mf_engine_test_fixture_mapping[SemanticManifestName.SIMPLE_MULTI_HOP_JOIN_MANIFEST].semantic_manifest_lookup diff --git a/metricflow/test/fixtures/model_fixtures.py b/metricflow/test/fixtures/model_fixtures.py deleted file mode 100644 index 8bff68c304..0000000000 --- a/metricflow/test/fixtures/model_fixtures.py +++ /dev/null @@ -1,115 +0,0 @@ -from __future__ import annotations - -import logging -from typing import Mapping - -import pytest -from dbt_semantic_interfaces.implementations.semantic_manifest import PydanticSemanticManifest -from dbt_semantic_interfaces.protocols.semantic_manifest import SemanticManifest - -from metricflow.model.semantic_manifest_lookup import SemanticManifestLookup -from metricflow.test.fixtures.manifest_fixtures import ( - MetricFlowEngineTestFixture, - SemanticManifestName, -) - -logger = logging.getLogger(__name__) - - -@pytest.fixture(scope="session") -def simple_semantic_manifest_lookup_non_ds( # noqa: D - mf_engine_test_fixture_mapping: Mapping[SemanticManifestName, MetricFlowEngineTestFixture] -) -> SemanticManifestLookup: - return mf_engine_test_fixture_mapping[SemanticManifestName.NON_SM_MANIFEST].semantic_manifest_lookup - - -@pytest.fixture(scope="session") -def simple_semantic_manifest_lookup( # noqa: D - mf_engine_test_fixture_mapping: Mapping[SemanticManifestName, MetricFlowEngineTestFixture] -) -> SemanticManifestLookup: - return mf_engine_test_fixture_mapping[SemanticManifestName.SIMPLE_MANIFEST].semantic_manifest_lookup - - -@pytest.fixture(scope="session") -def partitioned_multi_hop_join_semantic_manifest_lookup( # noqa: D - mf_engine_test_fixture_mapping: Mapping[SemanticManifestName, MetricFlowEngineTestFixture] -) -> SemanticManifestLookup: - return mf_engine_test_fixture_mapping[ - SemanticManifestName.PARTITIONED_MULTI_HOP_JOIN_MANIFEST - ].semantic_manifest_lookup - - -@pytest.fixture(scope="session") -def multi_hop_join_semantic_manifest_lookup( # noqa: D - mf_engine_test_fixture_mapping: Mapping[SemanticManifestName, MetricFlowEngineTestFixture] -) -> SemanticManifestLookup: - return mf_engine_test_fixture_mapping[SemanticManifestName.MULTI_HOP_JOIN_MANIFEST].semantic_manifest_lookup - - -@pytest.fixture(scope="session") -def simple_semantic_manifest( - mf_engine_test_fixture_mapping: Mapping[SemanticManifestName, MetricFlowEngineTestFixture] -) -> SemanticManifest: - """Model used for many tests.""" - return mf_engine_test_fixture_mapping[SemanticManifestName.SIMPLE_MANIFEST].semantic_manifest - - -@pytest.fixture(scope="session") -def extended_date_semantic_manifest_lookup( # noqa: D - mf_engine_test_fixture_mapping: Mapping[SemanticManifestName, MetricFlowEngineTestFixture] -) -> SemanticManifestLookup: - return mf_engine_test_fixture_mapping[SemanticManifestName.EXTENDED_DATE_MANIFEST].semantic_manifest_lookup - - -@pytest.fixture(scope="session") -def scd_semantic_manifest_lookup( - mf_engine_test_fixture_mapping: Mapping[SemanticManifestName, MetricFlowEngineTestFixture] -) -> SemanticManifestLookup: - """Initialize semantic model for SCD tests.""" - return mf_engine_test_fixture_mapping[SemanticManifestName.SCD_MANIFEST].semantic_manifest_lookup - - -@pytest.fixture(scope="session") -def data_warehouse_validation_model( - mf_engine_test_fixture_mapping: Mapping[SemanticManifestName, MetricFlowEngineTestFixture] -) -> SemanticManifest: - """Model used for data warehouse validation tests.""" - return mf_engine_test_fixture_mapping[SemanticManifestName.DATA_WAREHOUSE_VALIDATION_MANIFEST].semantic_manifest - - -@pytest.fixture(scope="session") -def cyclic_join_semantic_manifest_lookup( - mf_engine_test_fixture_mapping: Mapping[SemanticManifestName, MetricFlowEngineTestFixture] -) -> SemanticManifestLookup: - """Manifest that contains a potential cycle in the join graph (if not handled properly).""" - return mf_engine_test_fixture_mapping[SemanticManifestName.CYCLIC_JOIN_MANIFEST].semantic_manifest_lookup - - -@pytest.fixture(scope="session") -def ambiguous_resolution_manifest( - mf_engine_test_fixture_mapping: Mapping[SemanticManifestName, MetricFlowEngineTestFixture] -) -> PydanticSemanticManifest: - """Manifest used to test ambiguous resolution of group-by-items.""" - return mf_engine_test_fixture_mapping[SemanticManifestName.AMBIGUOUS_RESOLUTION_MANIFEST].semantic_manifest - - -@pytest.fixture(scope="session") -def ambiguous_resolution_manifest_lookup( # noqa: D - mf_engine_test_fixture_mapping: Mapping[SemanticManifestName, MetricFlowEngineTestFixture] -) -> SemanticManifestLookup: - return mf_engine_test_fixture_mapping[SemanticManifestName.AMBIGUOUS_RESOLUTION_MANIFEST].semantic_manifest_lookup - - -@pytest.fixture(scope="session") -def simple_multi_hop_join_manifest( # noqa: D - mf_engine_test_fixture_mapping: Mapping[SemanticManifestName, MetricFlowEngineTestFixture] -) -> PydanticSemanticManifest: - return mf_engine_test_fixture_mapping[SemanticManifestName.SIMPLE_MULTI_HOP_JOIN_MANIFEST].semantic_manifest - - -@pytest.fixture(scope="session") -def simple_multi_hop_join_manifest_lookup( # noqa: D - mf_engine_test_fixture_mapping: Mapping[SemanticManifestName, MetricFlowEngineTestFixture] -) -> SemanticManifestLookup: - """Manifest used to test ambiguous resolution of group-by-items.""" - return mf_engine_test_fixture_mapping[SemanticManifestName.SIMPLE_MULTI_HOP_JOIN_MANIFEST].semantic_manifest_lookup