Skip to content

Commit

Permalink
updated generate snapshot script to update snapshots in metricflow-se…
Browse files Browse the repository at this point in the history
…mantics
  • Loading branch information
WilliamDee committed Oct 15, 2024
1 parent 022c88b commit 967c21e
Showing 1 changed file with 28 additions and 24 deletions.
52 changes: 28 additions & 24 deletions tests_metricflow/generate_snapshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
from dataclasses import dataclass
from typing import Callable, Optional, Sequence

from dbt_semantic_interfaces.enum_extension import assert_values_exhausted
from dbt_semantic_interfaces.implementations.base import FrozenBaseModel
from metricflow_semantics.mf_logging.lazy_formattable import LazyFormat

Expand All @@ -55,6 +54,7 @@


TEST_DIRECTORY = "tests_metricflow"
MF_SEMANTICS_TEST_DIRECTORY = "metricflow-semantics/tests_metricflow_semantics"


class MetricFlowTestCredentialSet(FrozenBaseModel): # noqa: D101
Expand Down Expand Up @@ -142,29 +142,33 @@ def run_tests(test_configuration: MetricFlowTestConfiguration) -> None: # noqa:
if test_configuration.engine is SqlEngine.DUCKDB:
# DuckDB is fast, so generate all snapshots, including the engine-agnostic ones
run_command(f"pytest -x -vv -n 4 --overwrite-snapshots -k 'not itest' {TEST_DIRECTORY}")
elif (
test_configuration.engine is SqlEngine.REDSHIFT
or test_configuration.engine is SqlEngine.SNOWFLAKE
or test_configuration.engine is SqlEngine.BIGQUERY
or test_configuration.engine is SqlEngine.DATABRICKS
or test_configuration.engine is SqlEngine.POSTGRES
or test_configuration.engine is SqlEngine.TRINO
):
engine_name = test_configuration.engine.value.lower()
os.environ["MF_TEST_ADAPTER_TYPE"] = engine_name
hatch_env = f"{engine_name}-env"
use_persistent_source_schema = (
test_configuration.engine != SqlEngine.POSTGRES and test_configuration.engine != SqlEngine.TRINO
)
run_command(
f"hatch -v run {hatch_env}:pytest -x -vv -n 4 "
f"--overwrite-snapshots"
f"{' --use-persistent-source-schema' if use_persistent_source_schema else ''}"
f" -m '{SQL_ENGINE_SNAPSHOT_MARKER_NAME}' "
f"{TEST_DIRECTORY}"
)
else:
assert_values_exhausted(test_configuration.engine)

# Run snapshots changes for metricflow-semantics
# these are not dialect specific, so only need to run once
run_command(f"pytest -x -vv -n 4 --overwrite-snapshots {MF_SEMANTICS_TEST_DIRECTORY}")
# elif (
# test_configuration.engine is SqlEngine.REDSHIFT
# or test_configuration.engine is SqlEngine.SNOWFLAKE
# or test_configuration.engine is SqlEngine.BIGQUERY
# or test_configuration.engine is SqlEngine.DATABRICKS
# or test_configuration.engine is SqlEngine.POSTGRES
# or test_configuration.engine is SqlEngine.TRINO
# ):
# engine_name = test_configuration.engine.value.lower()
# os.environ["MF_TEST_ADAPTER_TYPE"] = engine_name
# hatch_env = f"{engine_name}-env"
# use_persistent_source_schema = (
# test_configuration.engine != SqlEngine.POSTGRES and test_configuration.engine != SqlEngine.TRINO
# )
# run_command(
# f"hatch -v run {hatch_env}:pytest -x -vv -n 4 "
# f"--overwrite-snapshots"
# f"{' --use-persistent-source-schema' if use_persistent_source_schema else ''}"
# f" -m '{SQL_ENGINE_SNAPSHOT_MARKER_NAME}' "
# f"{TEST_DIRECTORY}"
# )
# else:
# assert_values_exhausted(test_configuration.engine)


def run_cli(function_to_run: Callable) -> None: # noqa: D103
Expand Down

0 comments on commit 967c21e

Please sign in to comment.