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


Python Configuration._parse_section方法代码示例

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


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

示例1: test_invalid_path

# 需要导入模块: from conf_d import Configuration [as 别名]
# 或者: from conf_d.Configuration import _parse_section [as 别名]
 def test_invalid_path(self):
     conf = Configuration(
         name='invalid_path',
         path='/dev/null',
         parse=False
     )
     self.assertRaises(IOError, lambda: conf._parse_section(path=''))
     self.assertRaises(IOError, lambda: conf._parse_section(path=None))
     self.assertRaises(IOError, lambda: conf._parse_section(path='.'))
     self.assertRaises(IOError, lambda: conf._parse_section(path='/non-existent/path'))
开发者ID:milieuinfo,项目名称:conf_d,代码行数:12,代码来源:test_configuration.py

示例2: test_parse

# 需要导入模块: from conf_d import Configuration [as 别名]
# 或者: from conf_d.Configuration import _parse_section [as 别名]
    def test_parse(self):
        conf = Configuration(
            name='invalid_path',
            path='/dev/null',
            parse=False
        )

        expected = {}
        actual = conf._parse_section(path='./data/empty.ini')
        self.assertDictEqual(expected, actual)

        expected = {'section': {'key': 'value'}}
        actual = conf._parse_section(path='./data/single_section.ini')
        self.assertDictEqual(expected, actual)

        expected = {'section': {'key': 'value', 'key_two': 'other_value'}}
        actual = conf._parse_section(path='./data/single_section.ini', defaults={'key_two': 'other_value'})
        self.assertDictEqual(expected, actual)

        expected = {'section': {'key': 'value', 'key_two': 'other_value'}}
        actual = conf._parse_section(path='./data/single_section.ini', defaults={'key_two': 'other_value'}, only_section='section')
        self.assertDictEqual(expected, actual)

        expected = {}
        actual = conf._parse_section(path='./data/single_section.ini', defaults={'key_two': 'other_value'}, remove_section='section')
        self.assertDictEqual(expected, actual)

        expected = {
            'derp': {'cats': '1', 'expected': 'the spanish inquisition', 'no': 'sleep', 'til': 'brooklyn'},
            'multiple_sections': {'cats': '1', 'expected': 'the spanish inquisition', 'no': 'one'},
            'section': {'cats': '1', 'expected': 'the spanish inquisition', 'key': 'value', 'no': 'one'}
        }
        actual = conf._parse_section(path='./data/multiple_sections.ini', defaults={
            'no': 'one',
            'expected': 'the spanish inquisition',
            'cats': '1',
        })
        self.assertDictEqual(expected, actual)

        expected = {
            'multiple_sections': {'cats': '1', 'expected': 'the spanish inquisition', 'no': 'one'},
        }
        actual = conf._parse_section(path='./data/multiple_sections.ini', only_section='multiple_sections', defaults={
            'no': 'one',
            'expected': 'the spanish inquisition',
            'cats': '1',
        })
        self.assertDictEqual(expected, actual)

        expected = {
            'multiple_sections': {'cats': '1', 'expected': 'the spanish inquisition', 'no': 'one'},
            'section': {'cats': '1', 'expected': 'the spanish inquisition', 'key': 'value', 'no': 'one'}
        }
        actual = conf._parse_section(path='./data/multiple_sections.ini', remove_section='derp', defaults={
            'no': 'one',
            'expected': 'the spanish inquisition',
            'cats': '1',
        })
        self.assertDictEqual(expected, actual)
开发者ID:milieuinfo,项目名称:conf_d,代码行数:61,代码来源:test_configuration.py

示例3: test_custom_config_parser

# 需要导入模块: from conf_d import Configuration [as 别名]
# 或者: from conf_d.Configuration import _parse_section [as 别名]
    def test_custom_config_parser(self):
        conf = Configuration(
            name='multiple_sections',
            path='./data/multiple_sections.ini',
            config_parser=TestConfigParser,
            parse=False
        )

        self.assertRaises(NotImplementedError, lambda: conf._parse_section(path='./data/multiple_sections.ini'))
开发者ID:python-beaver,项目名称:python-conf_d,代码行数:11,代码来源:test_configuration.py


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