本文整理汇总了Python中pyhocon.config_tree.ConfigTree.pop方法的典型用法代码示例。如果您正苦于以下问题:Python ConfigTree.pop方法的具体用法?Python ConfigTree.pop怎么用?Python ConfigTree.pop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyhocon.config_tree.ConfigTree
的用法示例。
在下文中一共展示了ConfigTree.pop方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_configtree_pop
# 需要导入模块: from pyhocon.config_tree import ConfigTree [as 别名]
# 或者: from pyhocon.config_tree.ConfigTree import pop [as 别名]
def test_configtree_pop(self):
config_tree = ConfigTree()
config_tree.put("string", "string")
assert config_tree.pop("string", "default") == "string"
assert config_tree.pop("string-new", "default") == "default"
assert config_tree == ConfigTree()
with pytest.raises(ConfigMissingException):
assert config_tree.pop("string-new")
config_tree.put("list", [1, 2, 3])
assert config_tree.pop("list", [4]) == [1, 2, 3]
assert config_tree.pop("list-new", [4]) == [4]
assert config_tree == ConfigTree()
config_tree.put("config", {'a': 5})
assert config_tree.pop("config", {'b': 1}) == {'a': 5}
assert config_tree.pop("config-new", {'b': 1}) == {'b': 1}
assert config_tree == ConfigTree()
config_tree = ConfigTree()
config_tree.put('key', 'value')
assert config_tree.pop('key', 'value') == 'value'
assert 'key' not in config_tree
config_tree = ConfigTree()
config_tree.put('a.b.c.one', 1)
config_tree.put('a.b.c.two', 2)
config_tree.put('"f.k".g.three', 3)
exp = OrderedDict()
exp['a'] = OrderedDict()
exp['a']['b'] = OrderedDict()
exp['a']['b']['c'] = OrderedDict()
exp['a']['b']['c']['one'] = 1
exp['a']['b']['c']['two'] = 2
exp['f.k'] = OrderedDict()
exp['f.k']['g'] = OrderedDict()
exp['f.k']['g']['three'] = 3
assert config_tree.pop('a.b.c').as_plain_ordered_dict() == exp['a']['b']['c']
assert config_tree.pop('a.b.c', None) is None
with pytest.raises(ConfigMissingException):
assert config_tree.pop('a.b.c')
with pytest.raises(ConfigMissingException):
assert config_tree['a']['b'].pop('c')
assert config_tree.pop('a').as_plain_ordered_dict() == OrderedDict(b=OrderedDict())
assert config_tree.pop('"f.k"').as_plain_ordered_dict() == OrderedDict(g=OrderedDict(three=3))
assert config_tree.as_plain_ordered_dict() == OrderedDict()