From b3e4afa4c391ab2803ea2e8335e786b59b981364 Mon Sep 17 00:00:00 2001 From: Alena Hutchinson Date: Wed, 18 Dec 2024 17:27:11 -0800 Subject: [PATCH] add pg test --- ...expect_column_values_to_be_in_type_list.py | 104 ++++++++++++++++++ 1 file changed, 104 insertions(+) diff --git a/tests/integration/data_sources_and_expectations/expectations/test_expect_column_values_to_be_in_type_list.py b/tests/integration/data_sources_and_expectations/expectations/test_expect_column_values_to_be_in_type_list.py index 69bbbb675dc2..6081bba4c1d8 100644 --- a/tests/integration/data_sources_and_expectations/expectations/test_expect_column_values_to_be_in_type_list.py +++ b/tests/integration/data_sources_and_expectations/expectations/test_expect_column_values_to_be_in_type_list.py @@ -386,6 +386,110 @@ def test_success_complete_snowflake( assert result_dict["observed_value"] in expectation.type_list +@pytest.mark.parametrize( + "expectation", + [ + pytest.param( + gxe.ExpectColumnValuesToBeInTypeList(column="CHAR", type_list=["CHAR", "CHAR(1)"]), + id="CHAR", + ), + pytest.param( + gxe.ExpectColumnValuesToBeInTypeList(column="TEXT", type_list=["TEXT"]), + id="TEXT", + ), + pytest.param( + gxe.ExpectColumnValuesToBeInTypeList(column="INTEGER", type_list=["INTEGER"]), + id="INTEGER", + ), + pytest.param( + gxe.ExpectColumnValuesToBeInTypeList(column="SMALLINT", type_list=["SMALLINT"]), + id="SMALLINT", + ), + pytest.param( + gxe.ExpectColumnValuesToBeInTypeList(column="BIGINT", type_list=["BIGINT"]), + id="BIGINT", + ), + pytest.param( + gxe.ExpectColumnValuesToBeInTypeList( + column="TIMESTAMP", type_list=["TIMESTAMP", "TIMESTAMP WITHOUT TIME ZONE"] + ), + id="TIMESTAMP", + ), + pytest.param( + gxe.ExpectColumnValuesToBeInTypeList(column="DATE", type_list=["DATE"]), + id="DATE", + ), + pytest.param( + gxe.ExpectColumnValuesToBeInTypeList( + column="DOUBLE_PRECISION", type_list=["DOUBLE PRECISION"] + ), + id="DOUBLE_PRECISION", + ), + pytest.param( + gxe.ExpectColumnValuesToBeInTypeList(column="BOOLEAN", type_list=["BOOLEAN"]), + id="BOOLEAN", + ), + pytest.param( + gxe.ExpectColumnValuesToBeInTypeList(column="NUMERIC", type_list=["NUMERIC"]), + id="NUMERIC", + ), + ], +) +@parameterize_batch_for_data_sources( + data_source_configs=[ + PostgreSQLDatasourceTestConfig( + column_types={ + "CHAR": POSTGRESQL_TYPES.CHAR, + "TEXT": POSTGRESQL_TYPES.TEXT, + "INTEGER": POSTGRESQL_TYPES.INTEGER, + "SMALLINT": POSTGRESQL_TYPES.SMALLINT, + "BIGINT": POSTGRESQL_TYPES.BIGINT, + "TIMESTAMP": POSTGRESQL_TYPES.TIMESTAMP, + "DATE": POSTGRESQL_TYPES.DATE, + "DOUBLE_PRECISION": POSTGRESQL_TYPES.DOUBLE_PRECISION, + "BOOLEAN": POSTGRESQL_TYPES.BOOLEAN, + "NUMERIC": POSTGRESQL_TYPES.NUMERIC, + } + ), + ], + data=pd.DataFrame( + { + "CHAR": ["a", "b", "c"], + "TEXT": ["a", "b", "c"], + "INTEGER": [1, 2, 3], + "SMALLINT": [1, 2, 3], + "BIGINT": [1, 2, 3], + "TIMESTAMP": [ + "2021-01-01 00:00:00", + "2021-01-02 00:00:00", + "2021-01-03 00:00:00", + ], + "DATE": [ + # Date in isoformat + "2021-01-01", + "2021-01-02", + "2021-01-03", + ], + "DOUBLE_PRECISION": [1.0, 2.0, 3.0], + "BOOLEAN": [False, False, True], + "NUMERIC": [1, 2, 3], + }, + dtype="object", + ), +) +def test_success_complete_postgres( + batch_for_datasource: Batch, expectation: gxe.ExpectColumnValuesToBeInTypeList +) -> None: + result = batch_for_datasource.validate(expectation, result_format=ResultFormat.COMPLETE) + result_dict = result.to_json_dict()["result"] + + assert result.success + assert isinstance(result_dict, dict) + assert isinstance(result_dict["observed_value"], str) + assert isinstance(expectation.type_list, list) + assert result_dict["observed_value"] in expectation.type_list + + @pytest.mark.parametrize( "expectation", [