def test_settings_entry_variant(self): settingsKey = "settingsEntryVariant/variantValue" settingsKeyComplete = self.pluginName + "/" + settingsKey # Make sure settings does not exists QgsSettings().remove(settingsKeyComplete, QgsSettings.Plugins) defaultValue = 42 description = "Variant value functionality test" settingsEntryVariant = QgsSettingsEntryVariant(settingsKey, self.pluginName, defaultValue, description) # Set/Get value # as settings still does not exists return default value self.assertEqual(settingsEntryVariant.valueAsVariant(), defaultValue) settingsEntryVariant.setValue("abc") # Verify setValue using QgsSettings self.assertEqual( QgsSettings().value(settingsKeyComplete, defaultValue, section=QgsSettings.Plugins), "abc") self.assertEqual(settingsEntryVariant.valueAsVariant(), "abc") # Settings type self.assertEqual(settingsEntryVariant.settingsType(), QgsSettingsEntryBase.SettingsType.Variant)
def test_settings_entry_base(self): settingsKey = "settingsEntryBase/variantValue" settingsKeyComplete = self.pluginName + "/" + settingsKey # Make sure settings does not exists QgsSettings().remove(settingsKeyComplete, QgsSettings.Plugins) defaultValue = 42 description = "Variant value for basic functionality test" settingsEntryVariant = QgsSettingsEntryVariant(settingsKey, self.pluginName, defaultValue, description) # Check key self.assertEqual(settingsEntryVariant.key(), settingsKeyComplete) # Passing dynamicKeyPart to a non dynamic settings has no effect self.assertEqual(settingsEntryVariant.key("gugus"), settingsKeyComplete) self.assertEqual(settingsEntryVariant.hasDynamicKey(), False) # At this point settings should still not exists in underlyng QSettings as it was still not written (setValue) self.assertEqual(settingsEntryVariant.exists(), False) settingsEntryVariant.setValue(43) self.assertEqual(settingsEntryVariant.exists(), True) settingsEntryVariant.remove() self.assertEqual(settingsEntryVariant.exists(), False) # Section self.assertEqual(settingsEntryVariant.section(), QgsSettings.Plugins) # DefaultValue self.assertEqual(settingsEntryVariant.defaultValueAsVariant(), defaultValue) # Set/Get value # as settings still does not exists return default value self.assertEqual(settingsEntryVariant.valueAsVariant(), defaultValue) settingsEntryVariant.setValue(43) # Verify setValue using QgsSettings self.assertEqual( QgsSettings().value(settingsKeyComplete, defaultValue, section=QgsSettings.Plugins), 43) self.assertEqual(settingsEntryVariant.valueAsVariant(), 43) # Settings type self.assertEqual(settingsEntryVariant.settingsType(), QgsSettingsEntryBase.SettingsType.Variant) # Description self.assertEqual(settingsEntryVariant.description(), description)