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):
|
||||
"""
|
||||
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):
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user