Fixes possible bug and adds test

This commit is contained in:
Phill Ridout 2015-02-21 13:08:56 +00:00
parent 79204ea723
commit 4b52fde1da
2 changed files with 23 additions and 2 deletions

View File

@ -46,9 +46,9 @@ if is_linux():
def recent_files_conv(value):
"""
If the value is not a list convert it yo a list
If the value is not a list convert it to a list
:param value: Value to convert
:return:value as a List
:return: value as a List
"""
if isinstance(value, list):
return value
@ -56,6 +56,7 @@ def recent_files_conv(value):
return [value]
elif isinstance(value, bytes):
return [value.decode()]
return []
class Settings(QtCore.QSettings):

View File

@ -25,6 +25,7 @@ Package to test the openlp.core.lib.settings package.
from unittest import TestCase
from openlp.core.common import Settings
from openlp.core.common.settings import recent_files_conv
from tests.functional import patch
from tests.helpers.testmixin import TestMixin
@ -46,6 +47,25 @@ class TestSettings(TestCase, TestMixin):
"""
self.destroy_settings()
def recent_files_conv_test(self):
"""
Test that recent_files_conv, converts various possible types of values correctly.
"""
# GIVEN: A list of possible value types and the expected results
possible_values = [(['multiple', 'values'], ['multiple', 'values']),
(['single value'], ['single value']),
('string value', ['string value']),
(b'bytes value', ['bytes value']),
([], []),
(None, [])]
# WHEN: Calling recent_files_conv with the possible values
for value, expected_result in possible_values:
actual_result = recent_files_conv(value)
# THEN: The actual result should be the same as the expected result
self.assertEqual(actual_result, expected_result)
def settings_basic_test(self):
"""
Test the Settings creation and its default usage