Skip to content

Commit cf1b01c

Browse files
committed
update tests and error handling for dpath validator
1 parent 7927a14 commit cf1b01c

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

airbyte_cdk/sources/declarative/validators/dpath_validator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ def validate(self, input_data: dict[str, Any]) -> None:
5050
for value in values:
5151
self.strategy.validate(value)
5252
except KeyError as e:
53-
raise KeyError(f"Error validating path '{self.field_path}': {e}")
53+
raise ValueError(f"Error validating path '{self.field_path}': {e}")
5454
else:
5555
try:
5656
value = dpath.get(input_data, path)
5757
self.strategy.validate(value)
5858
except KeyError as e:
59-
raise KeyError(f"Error validating path '{self.field_path}': {e}")
59+
raise ValueError(f"Error validating path '{self.field_path}': {e}")

unit_tests/sources/declarative/validators/test_dpath_validator.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ def test_given_invalid_path_when_validate_then_raise_key_error(self):
3838

3939
test_data = {"user": {"profile": {"email": "[email protected]"}}}
4040

41-
with pytest.raises(KeyError) as context:
41+
with pytest.raises(ValueError) as context:
4242
validator.validate(test_data)
4343

44-
assert "Error validating path" in str(context.exception)
44+
assert "Error validating path" in str(context.value)
4545
assert not strategy.validate_called
4646

4747
def test_given_strategy_fails_when_validate_then_raise_value_error(self):
@@ -54,8 +54,6 @@ def test_given_strategy_fails_when_validate_then_raise_value_error(self):
5454
with pytest.raises(ValueError) as context:
5555
validator.validate(test_data)
5656

57-
assert "Error validating value" in str(context.exception)
58-
assert error_message in str(context.exception)
5957
assert strategy.validate_called
6058
assert strategy.validated_value == "invalid-email"
6159

@@ -73,7 +71,7 @@ def test_given_empty_input_data_when_validate_then_validate_raises_exception(sel
7371

7472
test_data = {}
7573

76-
with pytest.raises(KeyError):
74+
with pytest.raises(ValueError):
7775
validator.validate(test_data)
7876

7977
def test_path_with_wildcard_when_validate_then_validate_is_successful(self):

0 commit comments

Comments
 (0)