Skip to content

Commit

Permalink
Fix: Report errors in list properly (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
adrien-berchet authored Sep 28, 2022
1 parent 2197d10 commit a17e5a0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion neurots/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class ValidationError(Exception):


def _format_error(error):
return f"""In [{"->".join(error.absolute_path)}]: {error.message}"""
return f"""In [{"->".join([str(i) for i in error.absolute_path])}]: {error.message}"""


def validate(instance, schema):
Expand Down
8 changes: 8 additions & 0 deletions tests/test_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ def test_unknown_root_key(self, dummy_params):
dummy_params["unknown_param"] = 0
tested.validate_neuron_params(dummy_params)

def test_error_in_list(self, dummy_params):
# Wrong element in lists should be reported correctly
dummy_params["grow_types"] = ["UNKNOWN TYPE"]
with pytest.raises(
tested.ValidationError, match=r"In \[grow_types->0\]: 'UNKNOWN TYPE' is not one of"
):
tested.validate_neuron_params(dummy_params)


def test_empty_params():
data = {
Expand Down

0 comments on commit a17e5a0

Please sign in to comment.