本文整理汇总了Python中cerberus.Validator.document方法的典型用法代码示例。如果您正苦于以下问题:Python Validator.document方法的具体用法?Python Validator.document怎么用?Python Validator.document使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cerberus.Validator
的用法示例。
在下文中一共展示了Validator.document方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test__error_1
# 需要导入模块: from cerberus import Validator [as 别名]
# 或者: from cerberus.Validator import document [as 别名]
def test__error_1():
v = Validator(schema={'foo': {'type': 'string'}})
v.document = {'foo': 42}
v._error('foo', errors.BAD_TYPE, 'string')
error = v._errors[0]
assert error.document_path == ('foo',)
assert error.schema_path == ('foo', 'type')
assert error.code == 0x24
assert error.rule == 'type'
assert error.constraint == 'string'
assert error.value == 42
assert error.info == ('string',)
assert not error.is_group_error
assert not error.is_logic_error
示例2: test__error_2
# 需要导入模块: from cerberus import Validator [as 别名]
# 或者: from cerberus.Validator import document [as 别名]
def test__error_2():
v = Validator(schema={'foo': {'keyschema': {'type': 'integer'}}})
v.document = {'foo': {'0': 'bar'}}
v._error('foo', errors.KEYSCHEMA, ())
error = v._errors[0]
assert error.document_path == ('foo',)
assert error.schema_path == ('foo', 'keyschema')
assert error.code == 0x83
assert error.rule == 'keyschema'
assert error.constraint == {'type': 'integer'}
assert error.value == {'0': 'bar'}
assert error.info == ((),)
assert error.is_group_error
assert not error.is_logic_error
示例3: test__error_3
# 需要导入模块: from cerberus import Validator [as 别名]
# 或者: from cerberus.Validator import document [as 别名]
def test__error_3():
valids = [{'type': 'string', 'regex': '0x[0-9a-f]{2}'},
{'type': 'integer', 'min': 0, 'max': 255}]
v = Validator(schema={'foo': {'oneof': valids}})
v.document = {'foo': '0x100'}
v._error('foo', errors.ONEOF, (), 0, 2)
error = v._errors[0]
assert error.document_path == ('foo',)
assert error.schema_path == ('foo', 'oneof')
assert error.code == 0x92
assert error.rule == 'oneof'
assert error.constraint == valids
assert error.value == '0x100'
assert error.info == ((), 0, 2)
assert error.is_group_error
assert error.is_logic_error