Skip to content
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 9 commits into from
Feb 4, 2018
Merged

#3198: Generate verbose 'voluptuous' errors #3199

merged 9 commits into from
Feb 4, 2018

Conversation

jeff1evesque
Copy link
Owner

Resolves #3198.

@jeff1evesque jeff1evesque added this to the 0.7 milestone Feb 3, 2018
@coveralls
Copy link

coveralls commented Feb 3, 2018

Coverage Status

Coverage increased (+0.009%) to 53.875% when pulling f79d24c on bug-3198 into 431b006 on master.

@jeff1evesque jeff1evesque changed the title #3198: Implement 'validate_with_humanized_errors' #3198: Generate verbose 'voluptuous' errors Feb 4, 2018
@jeff1evesque
Copy link
Owner Author

jeff1evesque commented 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 data_new session, we noticed the returned errors were correctly formatted:

errors

@jeff1evesque
Copy link
Owner Author

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"]]

@jeff1evesque
Copy link
Owner Author

jeff1evesque commented Feb 4, 2018

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):

errors

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants