def setUp(self): super().setUp() self.tmp_directory = self.mktmpdir() self.configpath = os.path.join(self.tmp_directory, 'test.ini') shutil.copy(os.path.join('test', 'data', 'test.ini'), self.configpath) self.addCleanup(os.remove, self.configpath) self.config = Config.from_file(None, self.configpath) self.addCleanup(self.cleanup_config_obj) self.config.application["version"] = "testing" logging.disable(logging.ERROR) Option.registry = {} ListOption('profiles', self.PROFILES_KEY, []) Option('profiles', self.SETTINGS_KEY, {}) # Get valid profile option settings for testing option_settings = list(UserProfileGroups.get_all_settings_list()) self.test_setting_0 = option_settings[0] self.test_setting_1 = option_settings[1] self.test_setting_2 = option_settings[2] self.test_setting_3 = option_settings[3] TextOption("setting", self.test_setting_0, "abc") BoolOption("setting", self.test_setting_1, True) IntOption("setting", self.test_setting_2, 42) TextOption("setting", self.test_setting_3, "xyz")
def test_no_duplicate_settings(self): count1 = 0 for key in UserProfileGroups.get_setting_groups_list(): settings = UserProfileGroups.SETTINGS_GROUPS[key]["settings"] count1 += len(settings) count2 = len(UserProfileGroups.get_all_settings_list()) self.assertEqual(count1, count2)
def __getitem__(self, name): # Don't process settings that are not profile-specific if name in UserProfileGroups.get_all_settings_list(): for id, settings in self._get_active_profile_settings(): if name in settings and settings[name] is not None: return settings[name] opt = Option.get(self.__name, name) if opt is None: return None return self.value(name, opt, opt.default)
def __setitem__(self, name, value): # Don't process settings that are not profile-specific if name in UserProfileGroups.get_all_settings_list(): for id, settings in self._get_active_profile_settings(): if name in settings: self._save_profile_setting(id, name, value) return key = self.key(name) self.__qt_config.setValue(key, value) self._memoization[key].dirty = True