-
Notifications
You must be signed in to change notification settings - Fork 85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#3198: Generate verbose 'voluptuous' errors #3199
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jeff1evesque
changed the title
#3198: Implement 'validate_with_humanized_errors'
#3198: Generate verbose 'voluptuous' errors
Feb 4, 2018
We have made the following uncommitted changes to our sample dataset: $ git diff interface/
diff --git a/interface/static/data/json/web_interface/svm.json b/interface/static/data/json/web_interface/svm.json
index 37ae44f..a78dfb2 100644
--- a/interface/static/data/json/web_interface/svm.json
+++ b/interface/static/data/json/web_interface/svm.json
@@ -12,9 +12,9 @@
}]
},
{
- "dependent-variable": "dep-variable-2",
+ "dependent-variable": 555,
"independent-variables": [{
- "indep-variable-1":24.32,
+ "indep-variable-1":"aaa",
"indep-variable-2":92.22,
"indep-variable-3":0.356,
"indep-variable-4":235,
@@ -24,10 +24,10 @@
}]
},
{
- "dependent-variable": "dep-variable-3",
+ "dependent-variable": 222,
"independent-variables": [{
"indep-variable-1":22.67,
- "indep-variable-2":101.21,
+ "indep-variable-2":"bbb",
"indep-variable-3":0.832,
"indep-variable-4":427,
"indep-variable-5":75.45, Upon submitting a |
The dataset validation needs to be restructured to the following idea: root@trusty64:/home/vagrant# cat test.py
from voluptuous import Schema, Required, All, Any, Length
from voluptuous.humanize import validate_with_humanized_errors
list_error = []
data = {
"dataset": [{
"dependent-variable": "dep-variable-1",
"independent-variables": [{
"indep-variable-1":23.45,
"indep-variable-2":98.01,
"indep-variable-3":0.432,
"indep-variable-4":325,
"indep-variable-5":54.64,
"indep-variable-6":0.002,
"indep-variable-7":25
}]
},
{
"dependent-variable": 777,
"independent-variables": [{
"indep-variable-1":222,
"indep-variable-2":92.22,
"indep-variable-3":"aaa",
"indep-variable-4":235,
"indep-variable-5":64.45,
"indep-variable-6":0.001,
"indep-variable-7":31
}]
},
{
"dependent-variable": 222,
"independent-variables": [{
"indep-variable-1":22.67,
"indep-variable-2":"bbb",
"indep-variable-3":0.832,
"indep-variable-4":427,
"indep-variable-5":75.45,
"indep-variable-6":0.002,
"indep-variable-7":24
}]
}
]
}
schema = Schema({
Required('dependent-variable'): All(str, Length(min=1)),
Required('independent-variables'): [{
Required(All(str, Length(min=1))): Any(int, float),
}],
})
for instance in data['dataset']:
try:
validate_with_humanized_errors(instance, schema)
except Exception, error:
split_error = str(error).splitlines()
list_error.append(split_error)
print(list_error)
root@trusty64:/home/vagrant#
root@trusty64:/home/vagrant#
root@trusty64:/home/vagrant#
root@trusty64:/home/vagrant# python test.py
[["expected int for dictionary value @ data['independent-variables'][0]['indep-variable-3']. Got 'aaa'", "expected str for dictionary value @ data['dependent-variable']. Got 777"], ["expected int for dictionary value @ data['independent-variables'][0]['indep-variable-2']. Got 'bbb'", "expected str for dictionary value @ data['dependent-variable']. Got 222"]] |
Given the following uncommitted sample dataset: $ git diff interface/
diff --git a/interface/static/data/json/web_interface/svm.json b/interface/static/data/json/web_interface/svm.json
index 37ae44f..a78dfb2 100644
--- a/interface/static/data/json/web_interface/svm.json
+++ b/interface/static/data/json/web_interface/svm.json
@@ -12,9 +12,9 @@
}]
},
{
- "dependent-variable": "dep-variable-2",
+ "dependent-variable": 555,
"independent-variables": [{
- "indep-variable-1":24.32,
+ "indep-variable-1":"aaa",
"indep-variable-2":92.22,
"indep-variable-3":0.356,
"indep-variable-4":235,
@@ -24,10 +24,10 @@
}]
},
{
- "dependent-variable": "dep-variable-3",
+ "dependent-variable": 222,
"independent-variables": [{
"indep-variable-1":22.67,
- "indep-variable-2":101.21,
+ "indep-variable-2":"bbb",
"indep-variable-3":0.832,
"indep-variable-4":427,
"indep-variable-5":75.45, We have sufficiently adjusted our validation, to allow compounding error reporting on our dataset(s): |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Resolves #3198.