2013-02-11 18:08:32 +00:00
|
|
|
"""
|
2013-02-19 18:27:17 +00:00
|
|
|
Package to test the openlp.core.lib.settings package.
|
2013-02-11 18:08:32 +00:00
|
|
|
"""
|
|
|
|
import os
|
|
|
|
from unittest import TestCase
|
2013-02-19 18:27:17 +00:00
|
|
|
from tempfile import mkstemp
|
|
|
|
|
2013-02-11 18:08:32 +00:00
|
|
|
from openlp.core.lib import Settings
|
|
|
|
|
2013-02-21 07:33:21 +00:00
|
|
|
from PyQt4 import QtGui
|
2013-02-11 18:08:32 +00:00
|
|
|
|
2013-02-12 16:42:09 +00:00
|
|
|
|
2013-02-11 18:08:32 +00:00
|
|
|
class TestSettings(TestCase):
|
2013-03-13 19:51:56 +00:00
|
|
|
"""
|
|
|
|
Test the functions in the Settings module
|
|
|
|
"""
|
2013-02-11 19:20:08 +00:00
|
|
|
def setUp(self):
|
|
|
|
"""
|
|
|
|
Create the UI
|
|
|
|
"""
|
2013-08-31 18:17:38 +00:00
|
|
|
fd, self.ini_file = mkstemp('.ini')
|
2013-02-19 18:27:17 +00:00
|
|
|
Settings().set_filename(self.ini_file)
|
2013-02-18 20:44:55 +00:00
|
|
|
self.application = QtGui.QApplication.instance()
|
2013-02-11 19:20:08 +00:00
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
"""
|
|
|
|
Delete all the C++ objects at the end so that we don't have a segfault
|
|
|
|
"""
|
|
|
|
del self.application
|
2013-02-19 18:27:17 +00:00
|
|
|
os.unlink(self.ini_file)
|
|
|
|
os.unlink(Settings().fileName())
|
2013-02-11 19:20:08 +00:00
|
|
|
|
2013-02-11 18:08:32 +00:00
|
|
|
def settings_basic_test(self):
|
|
|
|
"""
|
2013-02-11 19:20:08 +00:00
|
|
|
Test the Settings creation and its default usage
|
2013-02-11 18:08:32 +00:00
|
|
|
"""
|
2013-02-11 19:20:08 +00:00
|
|
|
# GIVEN: A new Settings setup
|
|
|
|
|
|
|
|
# WHEN reading a setting for the first time
|
2013-08-31 18:17:38 +00:00
|
|
|
default_value = Settings().value('core/has run wizard')
|
2013-02-11 19:20:08 +00:00
|
|
|
|
|
|
|
# THEN the default value is returned
|
2013-08-31 18:17:38 +00:00
|
|
|
assert default_value is False, 'The default value should be False'
|
2013-02-11 19:20:08 +00:00
|
|
|
|
|
|
|
# WHEN a new value is saved into config
|
2013-08-31 18:17:38 +00:00
|
|
|
Settings().setValue('core/has run wizard', True)
|
2013-02-11 19:20:08 +00:00
|
|
|
|
|
|
|
# THEN the new value is returned when re-read
|
2013-08-31 18:17:38 +00:00
|
|
|
assert Settings().value('core/has run wizard') is True, 'The saved value should have been returned'
|
2013-02-11 19:20:08 +00:00
|
|
|
|
2013-02-11 19:48:38 +00:00
|
|
|
def settings_override_test(self):
|
|
|
|
"""
|
|
|
|
Test the Settings creation and its override usage
|
|
|
|
"""
|
|
|
|
# GIVEN: an override for the settings
|
|
|
|
screen_settings = {
|
2013-08-31 18:17:38 +00:00
|
|
|
'test/extend': 'very wide',
|
2013-02-11 19:48:38 +00:00
|
|
|
}
|
|
|
|
Settings().extend_default_settings(screen_settings)
|
|
|
|
|
|
|
|
# WHEN reading a setting for the first time
|
2013-08-31 18:17:38 +00:00
|
|
|
extend = Settings().value('test/extend')
|
2013-02-11 19:48:38 +00:00
|
|
|
|
|
|
|
# THEN the default value is returned
|
2013-08-31 18:17:38 +00:00
|
|
|
assert extend == 'very wide', 'The default value of "very wide" should be returned'
|
2013-02-11 19:48:38 +00:00
|
|
|
|
|
|
|
# WHEN a new value is saved into config
|
2013-08-31 18:17:38 +00:00
|
|
|
Settings().setValue('test/extend', 'very short')
|
2013-02-11 19:48:38 +00:00
|
|
|
|
|
|
|
# THEN the new value is returned when re-read
|
2013-08-31 18:17:38 +00:00
|
|
|
assert Settings().value('test/extend') == 'very short', 'The saved value should be returned'
|
2013-02-11 19:48:38 +00:00
|
|
|
|
|
|
|
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 = {
|
2013-08-31 18:17:38 +00:00
|
|
|
'test/extend': 'very wide',
|
2013-02-12 16:42:09 +00:00
|
|
|
}
|
2013-02-11 19:48:38 +00:00
|
|
|
Settings.extend_default_settings(screen_settings)
|
|
|
|
|
|
|
|
# WHEN reading a setting for the first time
|
|
|
|
settings = Settings()
|
2013-08-31 18:17:38 +00:00
|
|
|
settings.beginGroup('test')
|
|
|
|
extend = settings.value('extend')
|
2013-02-11 19:48:38 +00:00
|
|
|
|
|
|
|
# THEN the default value is returned
|
2013-08-31 18:17:38 +00:00
|
|
|
assert extend == 'very wide', 'The default value defined should be returned'
|
2013-02-11 19:48:38 +00:00
|
|
|
|
|
|
|
# WHEN a new value is saved into config
|
2013-08-31 18:17:38 +00:00
|
|
|
Settings().setValue('test/extend', 'very short')
|
2013-02-11 19:48:38 +00:00
|
|
|
|
|
|
|
# THEN the new value is returned when re-read
|
2013-08-31 18:17:38 +00:00
|
|
|
assert Settings().value('test/extend') == 'very short', 'The saved value should be returned'
|