Ejemplo n.º 1
0
    def test_settings_entry_base_default_value_override(self):
        settingsKey = "settingsEntryBase/defaultValueOverride/variantValue"
        settingsKeyComplete = self.pluginName + "/" + settingsKey

        # Make sure settings does not exists
        QgsSettings().remove(settingsKeyComplete, QgsSettings.Plugins)

        defaultValue = 42
        defaultValueOverride = 123
        description = "Variant value for default override functionality test"
        settingsEntryVariant = QgsSettingsEntryVariant(settingsKey,
                                                       self.pluginName,
                                                       defaultValue,
                                                       description)

        # Normal default value
        self.assertEqual(settingsEntryVariant.value(), defaultValue)

        # Normal default value
        self.assertEqual(
            settingsEntryVariant.value(None, False, defaultValueOverride),
            defaultValue)

        # Overridden default value
        self.assertEqual(
            settingsEntryVariant.value(None, True, defaultValueOverride),
            defaultValueOverride)
Ejemplo n.º 2
0
    def test_settings_entry_base_default_value_override(self):
        settingsKey = "settingsEntryBase/defaultValueOverride/variantValue"
        settingsKeyComplete = "plugins/{}/{}".format(self.pluginName,
                                                     settingsKey)

        # Make sure settings does not exists
        QgsSettings().remove(settingsKeyComplete)

        defaultValue = 42
        defaultValueOverride = 123
        description = "Variant value for default override functionality test"
        settingsEntryVariant = QgsSettingsEntryVariant(settingsKey,
                                                       self.pluginName,
                                                       defaultValue,
                                                       description)

        # Normal default value
        self.assertEqual(settingsEntryVariant.value(), defaultValue)

        # Normal default value
        self.assertEqual(settingsEntryVariant.value(), defaultValue)

        # Overridden default value
        self.assertEqual(
            settingsEntryVariant.valueWithDefaultOverride(
                defaultValueOverride), defaultValueOverride)
Ejemplo n.º 3
0
    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)
Ejemplo n.º 4
0
    def test_settings_entry_base_dynamic_key(self):
        settingsKeyDynamic = "settingsEntryBase/%1/variantValue"
        dynamicKeyPart1 = "first"
        dynamicKeyPart2 = "second"
        settingsKeyComplete1 = self.pluginName + "/" + settingsKeyDynamic.replace("%1", dynamicKeyPart1)
        settingsKeyComplete2 = self.pluginName + "/" + settingsKeyDynamic.replace("%1", dynamicKeyPart2)

        # Make sure settings does not exists
        QgsSettings().remove(settingsKeyComplete1, QgsSettings.Plugins)
        QgsSettings().remove(settingsKeyComplete2, QgsSettings.Plugins)

        defaultValue = 42
        settingsEntryVariantDynamic = QgsSettingsEntryVariant(settingsKeyDynamic, self.pluginName, defaultValue, "Variant value for dynamic key functionality test")

        # Check key
        self.assertEqual(settingsEntryVariantDynamic.key(dynamicKeyPart1), settingsKeyComplete1)
        self.assertEqual(settingsEntryVariantDynamic.key(dynamicKeyPart2), settingsKeyComplete2)

        # Get set values
        settingsEntryVariantDynamic.setValue(43, dynamicKeyPart1)
        settingsEntryVariantDynamic.setValue(44, dynamicKeyPart2)
        self.assertEqual(QgsSettings().value(settingsKeyComplete1, defaultValue, section=QgsSettings.Plugins), 43)
        self.assertEqual(QgsSettings().value(settingsKeyComplete2, defaultValue, section=QgsSettings.Plugins), 44)
        self.assertEqual(settingsEntryVariantDynamic.value(dynamicKeyPart1), 43)
        self.assertEqual(settingsEntryVariantDynamic.value(dynamicKeyPart2), 44)
Ejemplo n.º 5
0
    def test_settings_entry_base_dynamic_multiple_keys(self):
        settingsKeyDynamic = "settingsEntryBase/%1/anotherPart_%2/variantValue"
        dynamicKeyPart1 = "first"
        dynamicKeyPart2 = "second"
        settingsKeyComplete = self.pluginName + "/" + settingsKeyDynamic.replace(
            "%1", dynamicKeyPart1)
        settingsKeyComplete = settingsKeyComplete.replace(
            "%2", dynamicKeyPart2)

        # Make sure settings does not exists
        QgsSettings().remove(settingsKeyComplete, QgsSettings.Plugins)

        defaultValue = 42
        settingsEntryVariantDynamic = QgsSettingsEntryVariant(
            settingsKeyDynamic, self.pluginName, defaultValue,
            "Variant value for dynamic multiple keys functionality test")

        # Check key
        self.assertEqual(
            settingsEntryVariantDynamic.key([dynamicKeyPart1,
                                             dynamicKeyPart2]),
            settingsKeyComplete)

        # Get set values
        settingsEntryVariantDynamic.setValue(
            43, [dynamicKeyPart1, dynamicKeyPart2])
        self.assertEqual(
            QgsSettings().value(settingsKeyComplete,
                                defaultValue,
                                section=QgsSettings.Plugins), 43)
        self.assertEqual(
            settingsEntryVariantDynamic.value(
                [dynamicKeyPart1, dynamicKeyPart2]), 43)
Ejemplo n.º 6
0
    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)