Skip to content

Commit

Permalink
add test to catch exception
Browse files Browse the repository at this point in the history
  • Loading branch information
rxu17 committed Sep 6, 2024
1 parent 15d7992 commit 7720c8e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/glue/jobs/run_great_expectations_on_parquet.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,9 @@ def add_expectations_from_json(
Returns:
EphemeralDataContext: context object with expectations added
"""
# Ensure the dataset exists in the JSON file
# Ensure the data type exists in the JSON file
if data_type not in expectations_data:
raise ValueError(f"No expectations found for dataset '{data_type}'")
raise ValueError(f"No expectations found for data type '{data_type}'")

# Extract the expectation suite and expectations for the dataset
suite_data = expectations_data[data_type]
Expand Down
25 changes: 25 additions & 0 deletions tests/test_run_great_expectations_on_parquet.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,31 @@ def test_that_add_expectations_from_json_has_expected_call():
mock_context.add_or_update_expectation_suite.assert_called_once()


def test_that_add_expectations_from_json_throws_value_error():
mock_context = MagicMock()

# Sample expectations data
expectations_data = {
"not-test-data": {
"expectation_suite_name": "test_suite",
"expectations": [
{
"expectation_type": "expect_column_to_exist",
"kwargs": {"column": "test_column"},
},
],
}
}

data_type = "test-data"
with pytest.raises(
ValueError, match="No expectations found for data type 'test-data'"
):
run_gx_on_pq.add_expectations_from_json(
expectations_data, mock_context, data_type
)


@pytest.mark.integration
def test_add_expectations_from_json_adds_details_correctly(test_context):
# Mock expectations data
Expand Down

0 comments on commit 7720c8e

Please sign in to comment.