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'))
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())