def test_get_configuration(tmpdir): """Assert function returns a Sopel ``Config`` object""" working_dir = tmpdir.mkdir("working") working_dir.join('default.cfg').write('\n'.join( ['[core]', 'owner = TestName'])) parser = build_parser() options = parser.parse_args(['legacy', '-c', 'default.cfg']) with cd(working_dir.strpath): result = get_configuration(options) assert isinstance(result, config.Config) assert result.core.owner == 'TestName'
def __init__(self): self.dict = {} # opts input self.opts = self.get_opts() # Load config self.config = get_configuration(self.opts) self.setup_config() # load as dict config = configparser.ConfigParser() config.read(self.config.filename) for each_section in config.sections(): if each_section.lower() not in list(self.dict.keys()): self.dict[each_section.lower()] = dict() for (each_key, each_val) in config.items(each_section): if each_key.lower() not in list( self.dict[each_section.lower()].keys()): self.dict[each_section.lower()][ each_key.lower()] = each_val
def __init__(self): self.dict = {} # Load config parser = build_parser() if not len(sys.argv[1:]): argv = ['legacy'] else: argv = sys.argv[1:] opts = parser.parse_args(argv) self.config = get_configuration(opts) self.setup_config() # load as dict config = configparser.ConfigParser() config.read(self.config.filename) for each_section in config.sections(): if each_section.lower() not in list(self.dict.keys()): self.dict[each_section.lower()] = dict() for (each_key, each_val) in config.items(each_section): if each_key.lower() not in list( self.dict[each_section.lower()].keys()): self.dict[each_section.lower()][ each_key.lower()] = each_val