← Back to team overview

openlp-core team mailing list archive

[Merge] lp:~trb143/openlp/settings_migration into lp:openlp

 

Tim Bentley has proposed merging lp:~trb143/openlp/settings_migration into lp:openlp.

Requested reviews:
  OpenLP Core (openlp-core)

For more details, see:
https://code.launchpad.net/~trb143/openlp/settings_migration/+merge/147755

Add tests for Settings 

Fix bugs which made nose fail but OpenLP was happy about without these Settings would never be able to be tested!


Run twice and both pass
http://ci.openlp.org/view/Specific%20Branch/job/OpenLP-Pull_and_Run_Functional_Tests/45/console
-- 
https://code.launchpad.net/~trb143/openlp/settings_migration/+merge/147755
Your team OpenLP Core is requested to review the proposed merge of lp:~trb143/openlp/settings_migration into lp:openlp.
=== modified file 'openlp/core/lib/settings.py'
--- openlp/core/lib/settings.py	2013-02-07 18:00:40 +0000
+++ openlp/core/lib/settings.py	2013-02-11 20:00:29 +0000
@@ -322,7 +322,8 @@
         """
         # if group() is not empty the group has not been specified together with the key.
         if self.group():
-            default_value = Settings.__default_settings__[self.group() + u'/' + key]
+            qq = self.group() + u'/' + key
+            default_value = Settings.__default_settings__[unicode(self.group() + u'/' + key)]
         else:
             default_value = Settings.__default_settings__[key]
         setting = super(Settings, self).value(key, default_value)
@@ -343,7 +344,7 @@
         """
         # On OS X (and probably on other platforms too) empty value from QSettings is represented as type
         # PyQt4.QtCore.QPyNullVariant. This type has to be converted to proper 'None' Python type.
-        if isinstance(setting, QtCore.QPyNullVariant) and setting.isNull():
+        if setting.isNull() and isinstance(setting, QtCore.QPyNullVariant):
             setting = None
         # Handle 'None' type (empty value) properly.
         if setting is None:

=== added file 'tests/functional/openlp_core_lib/test_settings.py'
--- tests/functional/openlp_core_lib/test_settings.py	1970-01-01 00:00:00 +0000
+++ tests/functional/openlp_core_lib/test_settings.py	2013-02-11 20:00:29 +0000
@@ -0,0 +1,97 @@
+"""
+    Package to test the openlp.core.lib package.
+"""
+import os
+
+from unittest import TestCase
+from mock import MagicMock
+from openlp.core.lib import Settings
+
+from PyQt4 import QtGui, QtTest
+
+TESTPATH = os.path.abspath(os.path.join(os.path.dirname(__file__), u'..', u'..', u'resources'))
+
+class TestSettings(TestCase):
+
+    def setUp(self):
+        """
+        Create the UI
+        """
+        self.application = QtGui.QApplication([])
+        self.application.setOrganizationName(u'OpenLP-tests')
+        self.application.setOrganizationDomain(u'openlp.org')
+        Settings()
+
+    def tearDown(self):
+        """
+        Delete all the C++ objects at the end so that we don't have a segfault
+        """
+        del self.application
+        try:
+            os.remove(Settings().fileName())
+        except:
+            pass
+
+    def settings_basic_test(self):
+        """
+        Test the Settings creation and its default usage
+        """
+        # GIVEN: A new Settings setup
+
+        # WHEN reading a setting for the first time
+        default_value = Settings().value(u'general/has run wizard')
+
+        # THEN the default value is returned
+        assert default_value is False, u'The default value defined is returned'
+
+        # WHEN a new value is saved into config
+        Settings().setValue(u'general/has run wizard', True)
+
+        # THEN the new value is returned when re-read
+        assert Settings().value(u'general/has run wizard') is True, u'The saved value is returned'
+
+    def settings_override_test(self):
+        """
+        Test the Settings creation and its override usage
+        """
+        # GIVEN: an override for the settings
+        screen_settings = {
+            u'test/extend': u'very wide',
+        }
+        Settings().extend_default_settings(screen_settings)
+
+        # WHEN reading a setting for the first time
+        extend = Settings().value(u'test/extend')
+
+        # THEN the default value is returned
+        assert extend == u'very wide', u'The default value defined is returned'
+
+        # WHEN a new value is saved into config
+        Settings().setValue(u'test/extend', u'very short')
+
+        # THEN the new value is returned when re-read
+        assert Settings().value(u'test/extend') == u'very short', u'The saved value is returned'
+
+    def settings_override_with_group_test(self):
+        """
+        Test the Settings creation and its override usage - with groups
+        """
+        # GIVEN: an override for the settings
+        screen_settings = {
+            u'test/extend': u'very wide',
+            }
+        Settings.extend_default_settings(screen_settings)
+
+        # WHEN reading a setting for the first time
+        settings = Settings()
+        settings.beginGroup(u'test')
+        extend = settings.value(u'extend')
+
+        # THEN the default value is returned
+        assert extend == u'very wide', u'The default value defined is returned'
+
+        # WHEN a new value is saved into config
+        Settings().setValue(u'test/extend', u'very short')
+
+        # THEN the new value is returned when re-read
+        assert Settings().value(u'test/extend') == u'very short', u'The saved value is returned'
\ No newline at end of file


Follow ups