def test_init_only_system_file(self): defaults = {'test': 'test'} want = {'test': 'test', 'sys': 'sys'} path = self._get_file("{'sys': 'sys'}") t = Settings(defaults, path, '') os.remove(path) got = t.get_all() self.assertDictEqual(got, want)
def test_read(self): want = {'test': 'test'} path = self._get_file("{'test': 'test'}") got = Settings.read(path, '') os.remove(path) self.assertDictEqual(want, got)
def test_init_user_and_system_file(self): defaults = {'test': 'test'} want = { 'test': 'test', 'sys': 'sys', 'user': '******', } s_path = self._get_file("{'sys': 'sys'}") u_path = self._get_file("{'user': '******'}") t = Settings(defaults, u_path, s_path) os.remove(s_path) os.remove(u_path) got = t.get_all() self.assertDictEqual(got, want)
def load_config(path: str, defaults: dict) -> DictObj: """Loads the configuration file and any project files loaded in projects_folder if defined Args: path: full path to config file defaults: dictionary filled with default settings Returns: DictObj filled with settings from config files """ try: settings = Settings(defaults, path, '').get_all() except FileNotFoundError as exception_object: raise FileNotFoundError( "{0!s}: not found".format(path)) from exception_object except IOError as exception_object: raise IOError("{0!s}: not a file".format(path)) from exception_object return DictObj( merge_dictionaries( settings, load_projects_folder( path, settings.get('backup', dict()).get('projects_folder'))))
def test_get_all(self): defaults = {'test': 'test'} t = Settings(defaults, '', '') got = t.get_all() self.assertDictEqual(defaults, got)
def test_get(self): t = Settings({'test': 'test'}, '', '') got = t.get('test') self.assertEqual('test', got)
def test_init_settings_files_dont_exist(self): defaults = {'test': 'test'} t = Settings(defaults, '', '') got = t.get_all() self.assertDictEqual(got, defaults)