diff --git a/neurots/validator.py b/neurots/validator.py index c760d434..0a847fab 100644 --- a/neurots/validator.py +++ b/neurots/validator.py @@ -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): diff --git a/tests/test_validator.py b/tests/test_validator.py index f5885eb5..f596c3ab 100644 --- a/tests/test_validator.py +++ b/tests/test_validator.py @@ -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 = {