From fdcd0bf2e7db012b4763e95ca1e06bd2adfff318 Mon Sep 17 00:00:00 2001 From: Paul Yang Date: Thu, 30 May 2024 18:56:48 -0700 Subject: [PATCH] Move `assert_data_tables_equal`. --- tests_metricflow/compare_df.py | 30 ------------------- tests_metricflow/execution/test_tasks.py | 2 +- .../integration/test_configured_cases.py | 2 +- tests_metricflow/sql/compare_data_table.py | 22 ++++++++++++++ .../sql_clients/test_sql_client.py | 2 +- .../table_snapshot/test_source_schema.py | 2 +- .../table_snapshot/test_table_snapshots.py | 2 +- 7 files changed, 27 insertions(+), 35 deletions(-) delete mode 100644 tests_metricflow/compare_df.py diff --git a/tests_metricflow/compare_df.py b/tests_metricflow/compare_df.py deleted file mode 100644 index c8300d2b65..0000000000 --- a/tests_metricflow/compare_df.py +++ /dev/null @@ -1,30 +0,0 @@ -from __future__ import annotations - -import logging - -from metricflow.data_table.mf_table import MetricFlowDataTable -from tests_metricflow.sql.compare_data_table import check_data_tables_are_equal - -logger = logging.getLogger(__name__) - - -def assert_data_tables_equal( - actual: MetricFlowDataTable, - expected: MetricFlowDataTable, - sort_columns: bool = True, - allow_empty: bool = False, - compare_names_using_lowercase: bool = False, -) -> None: - """Check that contents of DataTables are the same. - - If sort_columns is set to false, value and column order needs to be the same. - If compare_names_using_lowercase is set to True, we copy the data_tables and lower-case their names. - This is useful for Snowflake query output comparisons. - """ - check_data_tables_are_equal( - expected_table=expected, - actual_table=actual, - ignore_order=sort_columns, - allow_empty=allow_empty, - compare_column_names_using_lowercase=compare_names_using_lowercase, - ) diff --git a/tests_metricflow/execution/test_tasks.py b/tests_metricflow/execution/test_tasks.py index 3168476b8e..17fe99f2ef 100644 --- a/tests_metricflow/execution/test_tasks.py +++ b/tests_metricflow/execution/test_tasks.py @@ -14,7 +14,7 @@ from metricflow.execution.executor import SequentialPlanExecutor from metricflow.protocols.sql_client import SqlClient, SqlEngine from metricflow.sql.sql_table import SqlTable -from tests_metricflow.compare_df import assert_data_tables_equal +from tests_metricflow.sql.compare_data_table import assert_data_tables_equal def test_read_sql_task(sql_client: SqlClient) -> None: # noqa: D103 diff --git a/tests_metricflow/integration/test_configured_cases.py b/tests_metricflow/integration/test_configured_cases.py index cd46b7223e..135721f32e 100644 --- a/tests_metricflow/integration/test_configured_cases.py +++ b/tests_metricflow/integration/test_configured_cases.py @@ -36,12 +36,12 @@ SqlStringExpression, SqlSubtractTimeIntervalExpression, ) -from tests_metricflow.compare_df import assert_data_tables_equal from tests_metricflow.integration.configured_test_case import ( CONFIGURED_INTEGRATION_TESTS_REPOSITORY, IntegrationTestModel, RequiredDwEngineFeature, ) +from tests_metricflow.sql.compare_data_table import assert_data_tables_equal logger = logging.getLogger(__name__) diff --git a/tests_metricflow/sql/compare_data_table.py b/tests_metricflow/sql/compare_data_table.py index c33272789a..550a830475 100644 --- a/tests_metricflow/sql/compare_data_table.py +++ b/tests_metricflow/sql/compare_data_table.py @@ -157,3 +157,25 @@ def check_data_tables_are_equal( ) return + + +def assert_data_tables_equal( + actual: MetricFlowDataTable, + expected: MetricFlowDataTable, + sort_columns: bool = True, + allow_empty: bool = False, + compare_names_using_lowercase: bool = False, +) -> None: + """Check that contents of DataTables are the same. + + If sort_columns is set to false, value and column order needs to be the same. + If compare_names_using_lowercase is set to True, we copy the data_tables and lower-case their names. + This is useful for Snowflake query output comparisons. + """ + check_data_tables_are_equal( + expected_table=expected, + actual_table=actual, + ignore_order=sort_columns, + allow_empty=allow_empty, + compare_column_names_using_lowercase=compare_names_using_lowercase, + ) diff --git a/tests_metricflow/sql_clients/test_sql_client.py b/tests_metricflow/sql_clients/test_sql_client.py index 65bfe34507..a81b4c5f63 100644 --- a/tests_metricflow/sql_clients/test_sql_client.py +++ b/tests_metricflow/sql_clients/test_sql_client.py @@ -12,8 +12,8 @@ from metricflow.data_table.mf_table import MetricFlowDataTable from metricflow.protocols.sql_client import SqlClient, SqlEngine from metricflow.sql.sql_table import SqlTable -from tests_metricflow.compare_df import assert_data_tables_equal from tests_metricflow.fixtures.sql_clients.ddl_sql_client import SqlClientWithDDLMethods +from tests_metricflow.sql.compare_data_table import assert_data_tables_equal logger = logging.getLogger(__name__) diff --git a/tests_metricflow/table_snapshot/test_source_schema.py b/tests_metricflow/table_snapshot/test_source_schema.py index b866390fba..5b9e77364d 100644 --- a/tests_metricflow/table_snapshot/test_source_schema.py +++ b/tests_metricflow/table_snapshot/test_source_schema.py @@ -8,9 +8,9 @@ from metricflow.protocols.sql_client import SqlClient, SqlEngine from metricflow.sql.sql_table import SqlTable -from tests_metricflow.compare_df import assert_data_tables_equal from tests_metricflow.fixtures.table_fixtures import CONFIGURED_SOURCE_TABLE_SNAPSHOT_REPOSITORY from tests_metricflow.source_schema_tools import get_populate_source_schema_shell_command +from tests_metricflow.sql.compare_data_table import assert_data_tables_equal from tests_metricflow.table_snapshot.table_snapshots import ( SqlTableSnapshotRepository, TableSnapshotException, diff --git a/tests_metricflow/table_snapshot/test_table_snapshots.py b/tests_metricflow/table_snapshot/test_table_snapshots.py index a9ac77003a..a344a64594 100644 --- a/tests_metricflow/table_snapshot/test_table_snapshots.py +++ b/tests_metricflow/table_snapshot/test_table_snapshots.py @@ -10,8 +10,8 @@ from metricflow.data_table.mf_table import MetricFlowDataTable from metricflow.protocols.sql_client import SqlEngine -from tests_metricflow.compare_df import assert_data_tables_equal from tests_metricflow.fixtures.sql_clients.ddl_sql_client import SqlClientWithDDLMethods +from tests_metricflow.sql.compare_data_table import assert_data_tables_equal from tests_metricflow.table_snapshot.table_snapshots import ( SqlTableColumnDefinition, SqlTableColumnType,