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


Python Config._verify_key方法代码示例

本文整理汇总了Python中pypackage.config.Config._verify_key方法的典型用法代码示例。如果您正苦于以下问题:Python Config._verify_key方法的具体用法?Python Config._verify_key怎么用?Python Config._verify_key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pypackage.config.Config的用法示例。


在下文中一共展示了Config._verify_key方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_verify_key__str_list_values

# 需要导入模块: from pypackage.config import Config [as 别名]
# 或者: from pypackage.config.Config import _verify_key [as 别名]
def test_verify_key__str_list_values():
    """If the type is list, the items inside should be strings."""

    conf = Config()
    conf.foo = ["bar", 3.14, "baz"]
    conf._verify_key("foo", list)
    assert conf.foo == ["bar", "3.14", "baz"]
开发者ID:a-tal,项目名称:pypackage,代码行数:9,代码来源:test_config.py

示例2: test_verify_key__dict_types

# 需要导入模块: from pypackage.config import Config [as 别名]
# 或者: from pypackage.config.Config import _verify_key [as 别名]
def test_verify_key__dict_types():
    """If a dict is provided with types, the key/values should be coerced."""

    conf = Config()
    conf.foo = {3.14: "500.123"}
    conf._verify_key("foo", {str: float})
    assert conf.foo == {"3.14": 500.123}
开发者ID:a-tal,项目名称:pypackage,代码行数:9,代码来源:test_config.py

示例3: test_verify_key__failure_coerce

# 需要导入模块: from pypackage.config import Config [as 别名]
# 或者: from pypackage.config.Config import _verify_key [as 别名]
def test_verify_key__failure_coerce():
    """Should try to coerce values into their types when not list or dict."""

    conf = Config()
    conf.foo = 3.14
    conf._verify_key("foo", str)
    assert conf.foo == "3.14"
开发者ID:a-tal,项目名称:pypackage,代码行数:9,代码来源:test_config.py

示例4: test_verify_key__list_object

# 需要导入模块: from pypackage.config import Config [as 别名]
# 或者: from pypackage.config.Config import _verify_key [as 别名]
def test_verify_key__list_object():
    """If an attribute should be a list, it should be listed."""

    conf = Config()
    conf.foo = "not a list"
    conf._verify_key("foo", list)
    assert conf.foo == ["not a list"]
开发者ID:a-tal,项目名称:pypackage,代码行数:9,代码来源:test_config.py

示例5: test_verify_key__failure

# 需要导入模块: from pypackage.config import Config [as 别名]
# 或者: from pypackage.config.Config import _verify_key [as 别名]
def test_verify_key__failure():
    """If unable to coerce into the expected type, raise TypeError."""

    conf = Config()
    conf.foo = "something"
    with pytest.raises(TypeError) as error:
        conf._verify_key("foo", float)
    assert error.value.args[0] == "foo should be a float, not str!"
开发者ID:a-tal,项目名称:pypackage,代码行数:10,代码来源:test_config.py

示例6: test_verify_key__dict_failure

# 需要导入模块: from pypackage.config import Config [as 别名]
# 或者: from pypackage.config.Config import _verify_key [as 别名]
def test_verify_key__dict_failure():
    """Do not try to coerce something that should be a dict into one."""

    conf = Config()
    conf.foo = "not a dict"
    with pytest.raises(TypeError) as error:
        conf._verify_key("foo", {})
    assert error.value.args[0] == "foo should be a dict, not str!"
开发者ID:a-tal,项目名称:pypackage,代码行数:10,代码来源:test_config.py

示例7: test_verify_key__multiple__fallthrough

# 需要导入模块: from pypackage.config import Config [as 别名]
# 或者: from pypackage.config.Config import _verify_key [as 别名]
def test_verify_key__multiple__fallthrough():
    """If the first coerce fails, try the second."""

    conf = Config()
    conf.bar = mock.MagicMock(spec=False)
    conf.bar.__float__ = mock.Mock(side_effect=ValueError)
    conf.bar.__str__ = mock.Mock(return_value="mock str")
    conf._verify_key("bar", (float, str))
    assert conf.bar == "mock str"
开发者ID:a-tal,项目名称:pypackage,代码行数:11,代码来源:test_config.py

示例8: test_verify_key__multiple__failure

# 需要导入模块: from pypackage.config import Config [as 别名]
# 或者: from pypackage.config.Config import _verify_key [as 别名]
def test_verify_key__multiple__failure():
    """When unable to coerce to any type, raise TypeError."""

    conf = Config()
    conf.foo = mock.MagicMock(spec=False)
    conf.foo.__float__ = mock.Mock(side_effect=ValueError)
    conf.foo.__str__ = mock.Mock(side_effect=ValueError)
    with pytest.raises(TypeError) as err:
        conf._verify_key("foo", (float, str))
    assert err.value.args[0] == "foo should be a float or str, not MagicMock!"
开发者ID:a-tal,项目名称:pypackage,代码行数:12,代码来源:test_config.py

示例9: test_verify_key__multiple__allowed

# 需要导入模块: from pypackage.config import Config [as 别名]
# 或者: from pypackage.config.Config import _verify_key [as 别名]
def test_verify_key__multiple__allowed():
    """There are some keys where multiple types are allowed."""

    conf = Config()
    conf.foo = 3.14
    conf._verify_key("foo", (list, str))
    assert conf.foo == [3.14]

    conf.foo = 3.14
    conf._verify_key("foo", (str, list))  # assert order matters
    assert conf.foo == "3.14"
开发者ID:a-tal,项目名称:pypackage,代码行数:13,代码来源:test_config.py


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