def init_app(self, app_config_profile, app_import_name, app_root_path, config_file_objs=None): self.profile = app_config_profile self.dirs = appdirs.AppDirs(app_import_name, appauthor=False, multipath=True) self.app_import_name = app_import_name self.app_root_path = app_root_path if config_file_objs: self.config_file_objs = config_file_objs else: possible_config_fpaths = self.config_file_paths() self.config_file_objs = pymodule_fpaths_to_objects(possible_config_fpaths) if self.profile is None: self.profile = self.determine_selected_profile() self.configs_found = [] for dotted_location in self.default_config_locations_parsed(): dotted_location = dotted_location.format(app_import_name=app_import_name, profile=self.profile) self.from_obj_if_exists(dotted_location) # apply settings from any of this app's configuration files for fpath, objects in self.config_file_objs: if self.profile in objects: self.from_object(objects[self.profile]) self.configs_found.append('{}:{}'.format(fpath, self.profile)) sub_values = self.substitution_values() self.substitution_apply(sub_values)
def init_app(self, app_config_profile, app_import_name, app_root_path, use_test_profile, config_file_objs=None): self.use_test_profile = use_test_profile self.profile = app_config_profile self.dirs = appdirs.AppDirs(app_import_name, appauthor=False, multipath=True) self.app_import_name = app_import_name self.app_root_path = app_root_path if config_file_objs: self.config_file_objs = config_file_objs else: possible_config_fpaths = self.config_file_paths() self.config_file_objs = pymodule_fpaths_to_objects( possible_config_fpaths) if self.profile is None: self.profile = self.determine_selected_profile() self.configs_found = [] for dotted_location in self.default_config_locations_parsed(): dotted_location = dotted_location.format( app_import_name=app_import_name, profile=self.profile) self.from_obj_if_exists(dotted_location) # apply settings from any of this app's configuration files for fpath, objects in self.config_file_objs: if self.profile in objects: self.from_object(objects[self.profile]) self.configs_found.append('{}:{}'.format(fpath, self.profile)) sub_values = self.substitution_values() self.substitution_apply(sub_values)
def test_pymodule_fpaths_to_objects(self): with tempfile.NamedTemporaryFile(delete=False) as fh: fpath1 = fh.name fh.write(b'foo1="bar"') with tempfile.NamedTemporaryFile(delete=False) as fh: fpath2 = fh.name fh.write(b'foo2="bar"') with tempfile.NamedTemporaryFile() as fh: fpath3 = fh.name result = pymodule_fpaths_to_objects([fpath1, fpath2, fpath3]) fpath, fpath_objs = result.pop(0) assert fpath == fpath1 assert fpath_objs['foo1'] == 'bar' fpath, fpath_objs = result.pop(0) assert fpath == fpath2 assert fpath_objs['foo2'] == 'bar' # result should now be empty since fpath3 should get filtered out b/c it's not present assert len(result) == 0
def test_pymodule_fpaths_to_objects(self): with tempfile.NamedTemporaryFile(delete=False) as fh: fpath1 = fh.name fh.write(b'foo1="bar"') with tempfile.NamedTemporaryFile(delete=False) as fh: fpath2 = fh.name fh.write(b'foo2="bar"') with tempfile.NamedTemporaryFile() as fh: fpath3 = fh.name result = pymodule_fpaths_to_objects([fpath1, fpath2, fpath3]) fpath, fpath_objs = result.pop(0) assert fpath == fpath1 assert fpath_objs["foo1"] == "bar" fpath, fpath_objs = result.pop(0) assert fpath == fpath2 assert fpath_objs["foo2"] == "bar" # result should now be empty since fpath3 should get filtered out b/c it's not present assert len(result) == 0