Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids committed Jan 16, 2023
1 parent b440604 commit 57414d9
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions tests/src/python/test_qgssettings.py
Expand Up @@ -12,7 +12,7 @@

import os
import tempfile
from qgis.core import QgsSettings, QgsTolerance, QgsMapLayerProxyModel
from qgis.core import Qgis, QgsSettings, QgsTolerance, QgsMapLayerProxyModel
from qgis.testing import start_app, unittest
from qgis.PyQt.QtCore import QSettings, QVariant
from pathlib import Path
Expand Down Expand Up @@ -222,7 +222,8 @@ def test_global_groups(self):

self.settings.beginGroup('testqgissettings')
self.assertEqual(sorted(['bar', 'foo']), sorted(self.settings.childGroups()))
self.assertEqual(['foo'], self.settings.globalChildGroups())
self.assertEqual(['foo'], self.settings.childGroups(Qgis.SettingsLocation.Global))
self.assertEqual(['bar'], self.settings.childGroups(Qgis.SettingsLocation.Local))
self.settings.endGroup()

self.globalsettings.remove('testqgissettings/foo')
Expand All @@ -232,6 +233,20 @@ def test_global_groups(self):
self.assertEqual([], self.settings.globalChildGroups())
self.settings.endGroup()

def test_location(self):
self.assertEqual(self.settings.allKeys(), [])
self.assertEqual(self.globalsettings.allKeys(), [])

self.addToDefaults('testqgissettings/global/setting', 'qgis')
self.settings.setValue('testqgissettings/local/setting', 'rocks')

self.assertEqual(self.settings.location('testqgissettings/global/setting'), Qgis.SettingsLocation.Global)
self.assertEqual(self.settings.location('testqgissettings/local/setting'), Qgis.SettingsLocation.Local)
self.assertEqual(self.settings.location('undefined-key'), Qgis.SettingsLocation.Any)

self.settings.setValue('testqgissettings/global/setting', 'rocks')
self.assertEqual(self.settings.location('testqgissettings/global/setting'), Qgis.SettingsLocation.Local)

def test_group_section(self):
# Test group by using Section
self.settings.beginGroup('firstgroup', section=QgsSettings.Core)
Expand Down

0 comments on commit 57414d9

Please sign in to comment.