Skip to content
Permalink
Browse files

Add unit test for remove and beginGroup with section.

  • Loading branch information
ismailsunni committed Sep 28, 2017
1 parent 0c7c494 commit 04e54903e81161ddcb571edab23b7ab7c052ea34
Showing with 30 additions and 0 deletions.
  1. +30 −0 tests/src/python/test_qgssettings.py
@@ -224,6 +224,30 @@ def test_global_groups(self):
self.assertEqual([], self.settings.globalChildGroups())
self.settings.endGroup()

def test_group_section(self):
# Test group by using Section
self.settings.beginGroup('firstgroup', section=QgsSettings.Core)
self.assertEqual([], self.settings.childGroups())
self.settings.setValue('key', 'value')
self.settings.setValue('key2/subkey1', 'subvalue1')
self.settings.setValue('key2/subkey2', 'subvalue2')
self.settings.setValue('key3', 'value3')

self.assertEqual(['key', 'key2/subkey1', 'key2/subkey2', 'key3'], self.settings.allKeys())
self.assertEqual(['key', 'key3'], self.settings.childKeys())
self.assertEqual(['key2'], self.settings.childGroups())
self.settings.endGroup()
# Set value by writing the group manually
self.settings.setValue('firstgroup/key4', 'value4', section=QgsSettings.Core)
# Checking the value that have been set
self.assertEqual(self.settings.value('firstgroup/key', section=QgsSettings.Core), 'value')
self.assertEqual(self.settings.value('firstgroup/key2/subkey1', section=QgsSettings.Core), 'subvalue1')
self.assertEqual(self.settings.value('firstgroup/key2/subkey2', section=QgsSettings.Core), 'subvalue2')
self.assertEqual(self.settings.value('firstgroup/key3', section=QgsSettings.Core), 'value3')
self.assertEqual(self.settings.value('firstgroup/key4', section=QgsSettings.Core), 'value4')
# Clean up firstgroup
self.settings.remove('firstgroup', section=QgsSettings.Core)

def test_array(self):
self.assertEqual(self.settings.allKeys(), [])
self.addArrayToDefaults('testqgissettings', 'key', ['qgisrocks1', 'qgisrocks2', 'qgisrocks3'])
@@ -361,6 +385,12 @@ def test_remove(self):
self.settings.remove('testQgisSettings/temp')
self.assertEqual(self.settings.value('testqQgisSettings/temp'), None)

# Test remove by using Section
self.settings.setValue('testQgisSettings/tempSection', True, section=QgsSettings.Core)
self.assertEqual(self.settings.value('testQgisSettings/tempSection', section=QgsSettings.Core), True)
self.settings.remove('testQgisSettings/temp', section=QgsSettings.Core)
self.assertEqual(self.settings.value('testqQgisSettings/temp', section=QgsSettings.Core), None)


if __name__ == '__main__':
unittest.main()

0 comments on commit 04e5490

Please sign in to comment.
You can’t perform that action at this time.