def test_get_list_of_list(value, cast_to, recovered): '''Test getting lists from the configuration''' section, option = 'section', 'option' c = pyhconf.ConfigParser() c.read_dict({section: {option: value}}) output = c.get_list_of_list(section, option, cast_to=cast_to) assert output == recovered
def test_get_list_nooption(use_default): '''Test that the default is correctly returned''' section, option = 'section', 'option' c = pyhconf.ConfigParser() c.read_dict({section: {option: ''}}) output = c.get_list(section, 'other_option', use_default=use_default) assert output == []
def test_read_string(conf_content, conversion): '''Make sure that ``ConfigParser.read_string`` is available in python 2 and handles strings''' c = pyhconf.ConfigParser() c.read_string(conversion(conf_content)) assert 'general' in c assert c['general']['option'] == 'value'
def test_read_file(conf_file): '''Make sure that ``ConfigParser.read_file`` is available in python 2''' c = pyhconf.ConfigParser() with conf_file.open() as f: c.read_file(f) assert 'general' in c assert c['general']['option'] == 'value'
def test_read(recwarn, conf_file, conversion): '''handle strings in py2 to avoid warnings with strings''' c = pyhconf.ConfigParser() flist = c.read(conversion(conf_file.strpath)) assert len(flist) == 1 assert 'general' in c assert c['general']['option'] == 'value' assert not recwarn
def test_override_conf(attr, val, modified, expected): '''Configuration override''' c = pyhconf.ConfigParser() c.read_dict({'sec1': {'opt1': 'val1'}}) args = Namespace(**{attr: val}) c = pyhconf.override_conf(c, args) assert len(c) == 2 assert len(c['sec1']) == 1 new_val = c['sec1']['opt1'] assert (new_val == 'val1') != modified if modified: assert new_val == expected