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


Python ConfigTree.as_plain_ordered_dict方法代码示例

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


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

示例1: test_plain_ordered_dict

# 需要导入模块: from pyhocon.config_tree import ConfigTree [as 别名]
# 或者: from pyhocon.config_tree.ConfigTree import as_plain_ordered_dict [as 别名]
 def test_plain_ordered_dict(self):
     config_tree = ConfigTree()
     config_tree.put('"a.b"', 5)
     config_tree.put('a."b.c"', [ConfigTree(), 2])
     config_tree.get('a."b.c"')[0].put('"c.d"', 1)
     d = OrderedDict()
     d['a.b'] = 5
     d['a'] = OrderedDict()
     d['a']['b.c'] = [OrderedDict(), 2]
     d['a']['b.c'][0]['c.d'] = 1
     assert config_tree.as_plain_ordered_dict() == d
开发者ID:ryban,项目名称:pyhocon,代码行数:13,代码来源:test_config_tree.py

示例2: test_configtree_pop

# 需要导入模块: from pyhocon.config_tree import ConfigTree [as 别名]
# 或者: from pyhocon.config_tree.ConfigTree import as_plain_ordered_dict [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()
开发者ID:chimpler,项目名称:pyhocon,代码行数:54,代码来源:test_config_tree.py


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