-
Notifications
You must be signed in to change notification settings - Fork 241
Open
Labels
Description
In cerberus 1.2, the example for http://docs.python-cerberus.org/en/stable/customize.html#custom-validators seems to have the wrong number of arguments. I was only able to get this to work with 2 arguments (including self
), not 3. For example:
import quantities as pq
from cerberus import Validator
class MyValidator(Validator):
def _validate_type_seconds(self, value):
if not isinstance(value, pq.quantity.Quantity):
self._error('%s' % value, "Must be a Python quantity")
if not value.simplified.units == pq.s:
self._error('%s' % value, "Must have units of seconds")
return True
schema = {'amount': {'type': 'seconds'}}
v = MyValidator(schema)
assert v.validate({'amount': 10*pq.s}) is True
assert v.validate({'amount': 10*pq.mV}) is False
Note that def _validate_type_seconds(self, value)
has only self
and value
, whereas the documentation example has self
, field
, and value
.
chinnichaitanya