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


Python Config.get方法代码示例

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


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

示例1: test_env

# 需要导入模块: from cuckoo.common.config import Config [as 别名]
# 或者: from cuckoo.common.config.Config import get [as 别名]
def test_env():
    path = tempfile.mkstemp()[1]

    os.environ["CUCKOO_FOOBAR"] = "top"
    os.environ["FOOBAR"] = "kek"

    mkdir(cwd("footopbar"))

    open(path, "wb").write(ENV_EXAMPLE)
    c = Config("cuckoo", cfg=path)
    assert c.get("cuckoo")["tmppath"] == cwd() + "/footopbar"

    open(path, "wb").write(ENV2_EXAMPLE)
    with pytest.raises(CuckooConfigurationError) as e:
        Config("cuckoo", cfg=path)
    e.match("Missing environment variable")

    os.environ.pop("FOOBAR")
    os.environ.pop("CUCKOO_FOOBAR")
开发者ID:consen,项目名称:cuckoo,代码行数:21,代码来源:test_config.py

示例2: setup

# 需要导入模块: from cuckoo.common.config import Config [as 别名]
# 或者: from cuckoo.common.config.Config import get [as 别名]
class TestConfig:
    def setup(self):
        set_cwd(tempfile.mkdtemp())

        self.path = tempfile.mkstemp()[1]
        open(self.path, "wb").write(CONF_EXAMPLE)

        self.c = Config(cfg=self.path)

    def test_get_option_exist(self):
        """Fetch an option of each type from default config file."""
        assert self.c.get("cuckoo")["delete_original"] is False
        assert self.c.get("cuckoo")["tcpdump"] == "/usr/sbin/tcpdump"

    def test_config_file_not_found(self):
        assert Config("foo")

    def test_get_option_not_found(self):
        with pytest.raises(CuckooConfigurationError) as e:
            self.c.get("foo")
        e.match("not found in configuration")

    def test_get_option_not_found_in_file_not_found(self):
        self.c = Config("bar")
        with pytest.raises(CuckooConfigurationError) as e:
            self.c.get("foo")
        e.match("not found in configuration")

    def test_options(self):
        assert parse_options("a=b") == {"a": "b"}
        assert parse_options("a=b,b=c") == {"a": "b", "b": "c"}
        assert parse_options("a,b") == {}

        assert emit_options({"a": "b"}) == "a=b"
        assert emit_options({"a": "b", "b": "c"}) == "a=b,b=c"

        assert parse_options(emit_options({"x": "y"})) == {"x": "y"}
开发者ID:consen,项目名称:cuckoo,代码行数:39,代码来源:test_config.py


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