Пример #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)
Пример #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)
Пример #3
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)
Пример #4
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)