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