本文整理汇总了Python中voluptuous.Schema.infer方法的典型用法代码示例。如果您正苦于以下问题:Python Schema.infer方法的具体用法?Python Schema.infer怎么用?Python Schema.infer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类voluptuous.Schema
的用法示例。
在下文中一共展示了Schema.infer方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_schema_infer_list
# 需要导入模块: from voluptuous import Schema [as 别名]
# 或者: from voluptuous.Schema import infer [as 别名]
def test_schema_infer_list():
schema = Schema.infer({
'list': ['foo', True, 42, 3.14]
})
assert_equal(schema, Schema({
Required('list'): [str, bool, int, float]
}))
示例2: test_schema_infer_scalar
# 需要导入模块: from voluptuous import Schema [as 别名]
# 或者: from voluptuous.Schema import infer [as 别名]
def test_schema_infer_scalar():
assert_equal(Schema.infer('foo'), Schema(str))
assert_equal(Schema.infer(True), Schema(bool))
assert_equal(Schema.infer(42), Schema(int))
assert_equal(Schema.infer(3.14), Schema(float))
assert_equal(Schema.infer({}), Schema(dict))
assert_equal(Schema.infer([]), Schema(list))
示例3: test_schema_infer
# 需要导入模块: from voluptuous import Schema [as 别名]
# 或者: from voluptuous.Schema import infer [as 别名]
def test_schema_infer():
schema = Schema.infer({
'str': 'foo',
'bool': True,
'int': 42,
'float': 3.14
})
assert_equal(schema, Schema({
Required('str'): str,
Required('bool'): bool,
Required('int'): int,
Required('float'): float
}))
示例4: test_schema_infer_dict
# 需要导入模块: from voluptuous import Schema [as 别名]
# 或者: from voluptuous.Schema import infer [as 别名]
def test_schema_infer_dict():
schema = Schema.infer({
'a': {
'b': {
'c': 'foo'
}
}
})
assert_equal(schema, Schema({
Required('a'): {
Required('b'): {
Required('c'): str
}
}
}))
示例5: test_schema_infer_accepts_kwargs
# 需要导入模块: from voluptuous import Schema [as 别名]
# 或者: from voluptuous.Schema import infer [as 别名]
def test_schema_infer_accepts_kwargs():
schema = Schema.infer({
'str': 'foo',
'bool': True
}, required=False, extra=True)
# Subset of schema should be acceptable thanks to required=False.
schema({'bool': False})
# Keys that are in schema should still match required types.
try:
schema({'str': 42})
except Invalid:
pass
else:
assert False, 'Did not raise Invalid for Number'
# Extra fields should be acceptable thanks to extra=True.
schema({'str': 'bar', 'int': 42})