forked from openlp/openlp
Fixes possible bug and adds test
This commit is contained in:
parent
79204ea723
commit
4b52fde1da
@ -46,9 +46,9 @@ if is_linux():
|
|||||||
|
|
||||||
def recent_files_conv(value):
|
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
|
:param value: Value to convert
|
||||||
:return:value as a List
|
:return: value as a List
|
||||||
"""
|
"""
|
||||||
if isinstance(value, list):
|
if isinstance(value, list):
|
||||||
return value
|
return value
|
||||||
@ -56,6 +56,7 @@ def recent_files_conv(value):
|
|||||||
return [value]
|
return [value]
|
||||||
elif isinstance(value, bytes):
|
elif isinstance(value, bytes):
|
||||||
return [value.decode()]
|
return [value.decode()]
|
||||||
|
return []
|
||||||
|
|
||||||
|
|
||||||
class Settings(QtCore.QSettings):
|
class Settings(QtCore.QSettings):
|
||||||
|
@ -25,6 +25,7 @@ Package to test the openlp.core.lib.settings package.
|
|||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
|
|
||||||
from openlp.core.common import Settings
|
from openlp.core.common import Settings
|
||||||
|
from openlp.core.common.settings import recent_files_conv
|
||||||
from tests.functional import patch
|
from tests.functional import patch
|
||||||
from tests.helpers.testmixin import TestMixin
|
from tests.helpers.testmixin import TestMixin
|
||||||
|
|
||||||
@ -46,6 +47,25 @@ class TestSettings(TestCase, TestMixin):
|
|||||||
"""
|
"""
|
||||||
self.destroy_settings()
|
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):
|
def settings_basic_test(self):
|
||||||
"""
|
"""
|
||||||
Test the Settings creation and its default usage
|
Test the Settings creation and its default usage
|
||||||
|
Loading…
Reference in New Issue
Block a user