Skip to content

Commit

Permalink
[MAINTENANCE] Add mssql support to testing framework (#10634)
Browse files Browse the repository at this point in the history
  • Loading branch information
tyler-hoffman authored Nov 7, 2024
1 parent 7d2c5c0 commit ae27ce6
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from great_expectations.datasource.fluent.interfaces import Batch
from tests.integration.conftest import parameterize_batch_for_data_sources
from tests.integration.test_utils.data_source_config import (
MSSQLDatasourceTestConfig,
MySQLDatasourceTestConfig,
PandasDataFrameDatasourceTestConfig,
PandasFilesystemCsvDatasourceTestConfig,
Expand All @@ -18,6 +19,7 @@

@parameterize_batch_for_data_sources(
data_source_configs=[
MSSQLDatasourceTestConfig(),
MySQLDatasourceTestConfig(),
PandasDataFrameDatasourceTestConfig(),
PandasFilesystemCsvDatasourceTestConfig(),
Expand All @@ -34,6 +36,7 @@ def test_expect_column_min_to_be_between(batch_for_datasource) -> None:

@parameterize_batch_for_data_sources(
data_source_configs=[
MSSQLDatasourceTestConfig(column_types={"date": sqltypes.DATE}),
MySQLDatasourceTestConfig(column_types={"date": sqltypes.DATE}),
PandasDataFrameDatasourceTestConfig(),
PandasFilesystemCsvDatasourceTestConfig(),
Expand Down Expand Up @@ -62,6 +65,7 @@ def test_expect_column_min_to_be_between__date(batch_for_datasource) -> None:

@parameterize_batch_for_data_sources(
data_source_configs=[
MSSQLDatasourceTestConfig(column_types={"date": sqltypes.DATE}),
MySQLDatasourceTestConfig(column_types={"date": sqltypes.DATE}),
PandasDataFrameDatasourceTestConfig(),
PandasFilesystemCsvDatasourceTestConfig(),
Expand Down Expand Up @@ -90,6 +94,7 @@ def test_expect_column_max_to_be_between__date(batch_for_datasource) -> None:

@parameterize_batch_for_data_sources(
data_source_configs=[
MSSQLDatasourceTestConfig(),
MySQLDatasourceTestConfig(),
PandasDataFrameDatasourceTestConfig(),
PandasFilesystemCsvDatasourceTestConfig(),
Expand All @@ -106,6 +111,7 @@ def test_expect_column_max_to_be_between(batch_for_datasource) -> None:

@parameterize_batch_for_data_sources(
data_source_configs=[
MSSQLDatasourceTestConfig(),
MySQLDatasourceTestConfig(),
PandasDataFrameDatasourceTestConfig(),
PandasFilesystemCsvDatasourceTestConfig(),
Expand All @@ -122,6 +128,7 @@ def test_expect_column_to_exist(batch_for_datasource):

@parameterize_batch_for_data_sources(
data_source_configs=[
MSSQLDatasourceTestConfig(),
MySQLDatasourceTestConfig(),
PandasDataFrameDatasourceTestConfig(),
PandasFilesystemCsvDatasourceTestConfig(),
Expand Down Expand Up @@ -155,6 +162,7 @@ def test_expect_column_mean_to_be_between(batch_for_datasource):
class TestExpectTableRowCountToEqualOtherTable:
@parameterize_batch_for_data_sources(
data_source_configs=[
MSSQLDatasourceTestConfig(),
MySQLDatasourceTestConfig(),
PostgreSQLDatasourceTestConfig(),
SnowflakeDatasourceTestConfig(),
Expand All @@ -174,6 +182,7 @@ def test_success(

@parameterize_batch_for_data_sources(
data_source_configs=[
MSSQLDatasourceTestConfig(),
MySQLDatasourceTestConfig(),
PostgreSQLDatasourceTestConfig(
extra_column_types={"other_table": {"col_b": sqltypes.VARCHAR}}
Expand All @@ -199,6 +208,7 @@ def test_different_counts(

@parameterize_batch_for_data_sources(
data_source_configs=[
MSSQLDatasourceTestConfig(),
MySQLDatasourceTestConfig(),
PostgreSQLDatasourceTestConfig(),
SnowflakeDatasourceTestConfig(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from .base import DataSourceTestConfig
from .mssql import MSSQLDatasourceTestConfig
from .mysql import MySQLDatasourceTestConfig
from .pandas_data_frame import PandasDataFrameDatasourceTestConfig
from .pandas_filesystem_csv import PandasFilesystemCsvDatasourceTestConfig
Expand Down
63 changes: 63 additions & 0 deletions tests/integration/test_utils/data_source_config/mssql.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
from typing import Mapping, Union

import pandas as pd
import pytest

from great_expectations.compatibility.typing_extensions import override
from great_expectations.datasource.fluent.interfaces import Batch
from tests.integration.test_utils.data_source_config.base import (
BatchTestSetup,
DataSourceTestConfig,
)
from tests.integration.test_utils.data_source_config.sql import SQLBatchTestSetup


class MSSQLDatasourceTestConfig(DataSourceTestConfig):
@property
@override
def label(self) -> str:
return "mssql"

@property
@override
def pytest_mark(self) -> pytest.MarkDecorator:
return pytest.mark.mssql

@override
def create_batch_setup(
self,
request: pytest.FixtureRequest,
data: pd.DataFrame,
extra_data: Mapping[str, pd.DataFrame],
) -> BatchTestSetup:
return MSSQLBatchTestSetup(
data=data,
config=self,
extra_data=extra_data,
)


class MSSQLBatchTestSetup(SQLBatchTestSetup[MSSQLDatasourceTestConfig]):
@property
@override
def connection_string(self) -> str:
return "mssql+pyodbc://sa:ReallyStrongPwd1234%^&*@localhost:1433/test_ci?driver=ODBC Driver 17 for SQL Server&charset=utf8&autocommit=true" # noqa: E501 # it's okay

@property
@override
def schema(self) -> Union[str, None]:
return None

@override
def make_batch(self) -> Batch:
name = self._random_resource_name()
return (
self.context.data_sources.add_sql(name=name, connection_string=self.connection_string)
.add_table_asset(
name=name,
table_name=self.table_name,
schema_name=self.schema,
)
.add_batch_definition_whole_table(name=name)
.get_batch()
)

0 comments on commit ae27ce6

Please sign in to comment.