From 4b52fde1da5141429d7be9ba0eeaeff247ec6edc Mon Sep 17 00:00:00 2001 From: Phill Ridout Date: Sat, 21 Feb 2015 13:08:56 +0000 Subject: [PATCH] Fixes possible bug and adds test --- openlp/core/common/settings.py | 5 +++-- .../openlp_core_common/test_settings.py | 20 +++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/openlp/core/common/settings.py b/openlp/core/common/settings.py index 672c24d95..0a5e92b48 100644 --- a/openlp/core/common/settings.py +++ b/openlp/core/common/settings.py @@ -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): diff --git a/tests/functional/openlp_core_common/test_settings.py b/tests/functional/openlp_core_common/test_settings.py index 04a98b352..cf7abadc7 100644 --- a/tests/functional/openlp_core_common/test_settings.py +++ b/tests/functional/openlp_core_common/test_settings.py @@ -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