本文整理汇总了Python中conf_d.Configuration.has方法的典型用法代码示例。如果您正苦于以下问题:Python Configuration.has方法的具体用法?Python Configuration.has怎么用?Python Configuration.has使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类conf_d.Configuration
的用法示例。
在下文中一共展示了Configuration.has方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_has_section
# 需要导入模块: from conf_d import Configuration [as 别名]
# 或者: from conf_d.Configuration import has [as 别名]
def test_has_section(self):
conf = Configuration(
name='multiple_sections',
path='./data/multiple_sections.ini',
)
self.assertEqual(True, conf.has('multiple_sections'))
self.assertEqual(True, conf.has('derp'))
self.assertEqual(True, conf.has('derp', 'no'))
示例2: test_readme
# 需要导入模块: from conf_d import Configuration [as 别名]
# 或者: from conf_d.Configuration import has [as 别名]
def test_readme(self):
def digitize(config):
for key in config:
if not config[key].isdigit():
try:
config[key] = float(config[key])
except ValueError:
pass
else:
try:
config[key] = int(config[key])
except ValueError:
pass
return config
conf = Configuration(
name='derp',
path='./data/conf',
main_defaults={
'no': 'one',
'expected': 'the spanish inquisition',
'cats': '1',
},
section_parser=digitize
)
expected = {
'sections': {'herp': {'sleep': 1, 'wait': 5.0, 'timeout': 'seventy'}},
'derp': {'expected': 'the spanish inquisition', 'til': 'brooklyn', 'cats': '1', 'no': 'sleep'}
}
self.assertEqual(expected, conf.raw())
actual = conf.get(section='derp', key='no', default="jumping")
self.assertEqual('sleep', actual)
actual = conf.get(section='derp', key='til')
self.assertEqual('brooklyn', actual)
actual = conf.get(section='derp', key='cats')
self.assertEqual('1', actual)
actual = conf.get(section='derp', key='dogs')
self.assertEqual(None, actual)
actual = conf.get(section='herp', key='sleep')
self.assertEqual(1, actual)
actual = conf.get(section='herp', key='wait')
self.assertEqual(5.0, actual)
actual = conf.get(section='herp', key='timeout')
self.assertEqual('seventy', actual)
actual = conf.has(section='derp')
self.assertEqual(True, actual)
actual = conf.has(section='derp', key='no')
self.assertEqual(True, actual)
expected = {
'sections': {
'herp': {
'sleep': 1,
'wait': 5.0,
'timeout': 'seventy'
}
},
'derp': {
'expected': 'the spanish inquisition',
'til': 'brooklyn',
'cats': '1',
'no': 'sleep'
}
}
self.assertEqual(expected, conf.raw())