simplifying errors

This commit is contained in:
Samuel Colvin
2017-07-08 18:22:57 +01:00
parent ebca8df223
commit 378c96888e
6 changed files with 20 additions and 19 deletions
+1
View File
@@ -7,6 +7,7 @@ v0.4.0 (2017-XX-XX)
...................
* show length in string validation error
* fix aliases in config during inheritance #55
* simplify error display
* use unicode ellipsis in ``truncate``
v0.3.0 (2017-06-21)
+1 -1
View File
@@ -61,7 +61,7 @@ class ValidationError(ValueError):
def __init__(self, errors):
self.errors_raw = errors
e_count = len(errors)
self.message = f'{e_count} error{"" if e_count == 1 else "s"} validating input'
self.message = 'error validating input' if e_count == 1 else f'{e_count} errors validating input'
super().__init__(self.message)
def json(self, indent=2):
+14 -14
View File
@@ -27,7 +27,7 @@ def test_str_bytes():
with pytest.raises(ValidationError) as exc_info:
StrBytesModel(v=None)
assert exc_info.value.message == '1 error validating input'
assert exc_info.value.message == 'error validating input'
assert """\
{
"v": [
@@ -89,7 +89,7 @@ def test_union_int_str():
with pytest.raises(ValidationError) as exc_info:
Model(v=None)
assert exc_info.value.message == '1 error validating input'
assert exc_info.value.message == 'error validating input'
assert """\
{
"v": [
@@ -129,7 +129,7 @@ def test_typed_list():
with pytest.raises(ValidationError) as exc_info:
Model(v=[1, 'x', 'y'])
assert exc_info.value.message == '1 error validating input'
assert exc_info.value.message == 'error validating input'
assert """\
{
"v": [
@@ -150,7 +150,7 @@ def test_typed_list():
with pytest.raises(ValidationError) as exc_info:
Model(v=1)
assert exc_info.value.message == '1 error validating input'
assert exc_info.value.message == 'error validating input'
assert """\
{
"v": {
@@ -171,7 +171,7 @@ def test_typed_set():
with pytest.raises(ValidationError) as exc_info:
Model(v=[1, 'x'])
assert """\
1 error validating input
error validating input
v:
invalid literal for int() with base 10: 'x' (error_type=ValueError track=int index=1)""" == str(exc_info.value)
@@ -197,21 +197,21 @@ def test_typed_dict(value, result):
(
1,
"""\
1 error validating input
error validating input
v:
'int' object is not iterable (error_type=TypeError)"""
),
(
{'a': 'b'},
"""\
1 error validating input
error validating input
v:
invalid literal for int() with base 10: 'b' (error_type=ValueError track=int index=a)"""
),
(
[1, 2, 3],
"""\
1 error validating input
error validating input
v:
cannot convert dictionary update sequence element #0 to a sequence (error_type=TypeError)""",
)
@@ -229,7 +229,7 @@ def test_dict_key_error():
with pytest.raises(ValidationError) as exc_info:
DictIntModel(v={'foo': 2, '3': '4'})
assert """\
1 error validating input
error validating input
v:
invalid literal for int() with base 10: 'foo' (error_type=ValueError track=int index=key)""" == str(exc_info.value)
@@ -284,9 +284,9 @@ def test_recursive_list_error():
MasterListModel(v=[{}])
assert """\
1 error validating input
error validating input
v:
1 error validating input (error_type=ValidationError track=SubModel)
error validating input (error_type=ValidationError track=SubModel)
name:
field required (error_type=Missing)\
""" == str(exc_info.value)
@@ -302,7 +302,7 @@ v:
"track": null
}
},
"error_msg": "1 error validating input",
"error_msg": "error validating input",
"error_type": "ValidationError",
"index": 0,
"track": "SubModel"
@@ -320,7 +320,7 @@ def test_list_unions():
with pytest.raises(ValidationError) as exc_info:
Model(v=[1, 2, None])
assert """\
1 error validating input
error validating input
v:
int() argument must be a string, a bytes-like object or a number, not 'NoneType' \
(error_type=TypeError track=int index=2)
@@ -389,7 +389,7 @@ def test_alias_error():
with pytest.raises(ValidationError) as exc_info:
Model(_a='foo')
assert """\
1 error validating input
error validating input
_a:
invalid literal for int() with base 10: 'foo' (error_type=ValueError track=int)""" == str(exc_info.value)
+2 -2
View File
@@ -26,7 +26,7 @@ def test_ultra_simple_missing():
with pytest.raises(ValidationError) as exc_info:
UltraSimpleModel()
assert """\
1 error validating input
error validating input
a:
field required (error_type=Missing)""" == str(exc_info.value)
@@ -299,7 +299,7 @@ def test_required():
with pytest.raises(ValidationError) as exc_info:
Model()
assert """\
1 error validating input
error validating input
a:
field required (error_type=Missing)\
""" == str(exc_info.value)
+1 -1
View File
@@ -23,7 +23,7 @@ def test_sub_env_missing():
with pytest.raises(ValidationError) as exc_info:
SimpleSettings()
assert """\
1 error validating input
error validating input
apple:
None is not an allow value (error_type=TypeError track=str)\
""" == str(exc_info.value)
+1 -1
View File
@@ -240,7 +240,7 @@ def test_enum_successful():
def test_enum_fails():
with pytest.raises(ValueError) as exc_info:
CookingModel(tool=3)
assert exc_info.value.message == '1 error validating input'
assert exc_info.value.message == 'error validating input'
assert """\
{
"tool": {