From fb2de50fa739e3b07cc5632fb63ce5c1ad4198fc Mon Sep 17 00:00:00 2001 From: rileyh Date: Mon, 19 Feb 2024 20:47:11 +0000 Subject: [PATCH] [#130] Add two tests for error conditions with override_column_X --- hlink/tests/conf_validations_test.py | 44 ++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/hlink/tests/conf_validations_test.py b/hlink/tests/conf_validations_test.py index 5507989..9cf896c 100644 --- a/hlink/tests/conf_validations_test.py +++ b/hlink/tests/conf_validations_test.py @@ -179,3 +179,47 @@ def test_check_column_mappings_override_column_b(spark: SparkSession) -> None: df_b = spark.createDataFrame([[70], [50], [30]], ["AGE"]) check_column_mappings(config, df_a, df_b) + + +def test_check_column_mappings_override_column_a_not_present( + spark: SparkSession, +) -> None: + """ + The override_column_a column must be present in datasource A. + """ + config = { + "column_mappings": [ + {"column_name": "AGE", "override_column_a": "oops_not_there"} + ] + } + df_a = spark.createDataFrame([[20], [40], [60]], ["ageColumn"]) + df_b = spark.createDataFrame([[70], [50], [30]], ["AGE"]) + + expected_err = ( + r"Within a \[\[column_mappings\]\] the override_column_a column " + "'oops_not_there' does not exist in datasource_a" + ) + with pytest.raises(ValueError, match=expected_err): + check_column_mappings(config, df_a, df_b) + + +def test_check_column_mappings_override_column_b_not_present( + spark: SparkSession, +) -> None: + """ + The override_column_b column must be present in datasource B. + """ + config = { + "column_mappings": [ + {"column_name": "AGE", "override_column_b": "oops_not_there"} + ] + } + df_a = spark.createDataFrame([[20], [40], [60]], ["AGE"]) + df_b = spark.createDataFrame([[70], [50], [30]], ["AGE"]) + + expected_err = ( + r"Within a \[\[column_mappings\]\] the override_column_b column " + "'oops_not_there' does not exist in datasource_b" + ) + with pytest.raises(ValueError, match=expected_err): + check_column_mappings(config, df_a, df_b)