当前位置: 首页>>代码示例>>Python>>正文


Python Schema.infer方法代码示例

本文整理汇总了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]
    }))
开发者ID:tuukkamustonen,项目名称:voluptuous,代码行数:10,代码来源:tests.py

示例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))
开发者ID:tuukkamustonen,项目名称:voluptuous,代码行数:9,代码来源:tests.py

示例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
    }))
开发者ID:tuukkamustonen,项目名称:voluptuous,代码行数:15,代码来源:tests.py

示例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
            }
        }
    }))
开发者ID:tuukkamustonen,项目名称:voluptuous,代码行数:18,代码来源:tests.py

示例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})
开发者ID:tuukkamustonen,项目名称:voluptuous,代码行数:21,代码来源:tests.py


注:本文中的voluptuous.Schema.infer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。