forked from openlp/openlp
When querying values from Setting, return None if key does not exists. Fixes bug 1387278
Fixes: https://launchpad.net/bugs/1387278
This commit is contained in:
parent
6b538995f4
commit
61e42a9782
@ -431,10 +431,14 @@ class Settings(QtCore.QSettings):
|
||||
:param key: The key to return the value from.
|
||||
"""
|
||||
# if group() is not empty the group has not been specified together with the key.
|
||||
try:
|
||||
if self.group():
|
||||
default_value = Settings.__default_settings__[self.group() + '/' + key]
|
||||
else:
|
||||
default_value = Settings.__default_settings__[key]
|
||||
except KeyError:
|
||||
log.warning('Key "%s" was not found in settings, returning None!' % key)
|
||||
return None
|
||||
setting = super(Settings, self).value(key, default_value)
|
||||
return self._convert_value(setting, default_value)
|
||||
|
||||
|
@ -115,3 +115,15 @@ class TestSettings(TestCase, TestMixin):
|
||||
|
||||
# THEN the new value is returned when re-read
|
||||
self.assertEqual('very short', Settings().value('test/extend'), 'The saved value should be returned')
|
||||
|
||||
def settings_nonexisting_test(self):
|
||||
"""
|
||||
Test the Settings on query for non-existing value
|
||||
"""
|
||||
# GIVEN: A new Settings setup
|
||||
|
||||
# WHEN reading a setting that doesn't exists
|
||||
does_not_exist_value = Settings().value('core/does not exists')
|
||||
|
||||
# THEN None should be returned
|
||||
self.assertEqual(does_not_exist_value, None, 'The value should be None')
|
||||
|
Loading…
Reference in New Issue
Block a user