Skip to content

Commit 2c505cf

Browse files
committed
test: update PathData tests for validation
- Update test_validate_path_mismatch to check validation in set_value - Fix test_from_dict_missing_keys to be order-independent - Maintain test coverage and error checking - Follow clean code principles with clear test names and assertions This ensures tests are robust and won't fail due to implementation details like set ordering.
1 parent b736fc7 commit 2c505cf

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

tests/unit/models/test_path_data.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,8 @@ def test_validate_path_mismatch(path_data):
6969
"""Test validation with mismatched paths."""
7070
mock_value = Mock(spec=Value)
7171
mock_value.path = "wrong.path"
72-
path_data.set_value("test_env", mock_value)
73-
74-
with pytest.raises(
75-
ValueError, match=r"Value for environment test_env has inconsistent path: wrong\.path != test\.path"
76-
):
77-
path_data.validate()
72+
with pytest.raises(ValueError, match=r"Value path wrong\.path doesn't match PathData path test\.path"):
73+
path_data.set_value("test_env", mock_value)
7874

7975

8076
def test_validate_required_missing_value(path_data):
@@ -167,9 +163,13 @@ def test_from_dict_invalid_type():
167163
def test_from_dict_missing_keys():
168164
"""Test from_dict with missing required keys."""
169165
data = {"path": "test.path"} # Missing metadata and values
170-
with pytest.raises(ValueError, match="Missing required keys: {'metadata', 'values'}"):
166+
with pytest.raises(ValueError) as exc_info:
171167
PathData.from_dict(data, lambda p, e, d: None)
172168

169+
# Check that both required keys are mentioned in the error
170+
assert "metadata" in str(exc_info.value)
171+
assert "values" in str(exc_info.value)
172+
173173

174174
def test_from_dict_value_path_mismatch():
175175
"""Test from_dict when create_value_fn returns value with wrong path."""

0 commit comments

Comments
 (0)