Fix key error in tests

This commit is contained in:
Tim Bentley 2013-02-11 19:48:38 +00:00
parent b4a3833858
commit 19f9cb8c24
2 changed files with 47 additions and 1 deletions

View File

@ -322,7 +322,8 @@ class Settings(QtCore.QSettings):
"""
# 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)

View File

@ -47,3 +47,48 @@ class TestSettings(TestCase):
# 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'