本文整理汇总了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")
示例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"}