jpmckinney / validictory

🎓 deprecated general purpose python data validator
Other
240 stars 57 forks source link

Integer max/min errors are reports as floats #76

Closed jmcnamara closed 10 years ago

jmcnamara commented 10 years ago

Hi,

Integer maximum and minimum exceptions are reported as floats.

Here is an example based on one of the examples in the docs:

import json
import validictory

data = json.loads(''' {"result": 10, "resultTwo": 12}''')

schema = {
    "properties": {
        "result": { # passes
            "minimum": 9,
            "maximum": 10
        },
        "resultTwo": { # fails
            "type": "integer",
            "minimum": 13
        }
    }
}

try:
    validictory.validate(data, schema)
except validictory.validator.FieldValidationError as e:
    print e

Running this give:

Value 12 for field 'resultTwo' is less than minimum value: 13.000000

While this isn't strictly incorrect it looks a little odd.

Replacing the format string %f with %g in the error handler would probably be a sufficient fix rather than varying the format string based on the validation type.

Regards,

John

jmcnamara commented 10 years ago

It looks like I had a slightly older version of valedictory on the machine I was testing on. This issues doesn't occur on the latest PyPi version or the GitHub master.

Sorry for the noise. Closing.

jmcnamara commented 10 years ago

Brief followup:

I had installed the module as follows:

$ pip install validictory

And got the 0.9.3 release. Installing as follows picked up the latest release:

$ pip install --pre validictory