diff --git a/openlp/core/lib/formattingtags.py b/openlp/core/lib/formattingtags.py index b7bbd7322..b2d8f6ea7 100644 --- a/openlp/core/lib/formattingtags.py +++ b/openlp/core/lib/formattingtags.py @@ -36,8 +36,7 @@ from openlp.core.lib import Settings, translate class FormattingTags(object): """ - Static Class to HTML Tags to be access around the code the list is managed - by the Options Tab. + Static Class to HTML Tags to be access around the code the list is managed by the Options Tab. """ html_expands = [] @@ -56,12 +55,11 @@ class FormattingTags(object): tags = [] for tag in FormattingTags.html_expands: if not tag[u'protected'] and not tag.get(u'temporary'): - # Using dict ensures that copy is made and encoding of values - # a little later does not affect tags in the original list + # Using dict ensures that copy is made and encoding of values a little later does not affect tags in + # the original list tags.append(dict(tag)) tag = tags[-1] - # Remove key 'temporary' from tags. - # It is not needed to be saved. + # Remove key 'temporary' from tags. It is not needed to be saved. if u'temporary' in tag: del tag[u'temporary'] for element in tag: @@ -73,15 +71,12 @@ class FormattingTags(object): @staticmethod def load_tags(): """ - Load the Tags from store so can be used in the system or used to - update the display. + Load the Tags from store so can be used in the system or used to update the display. """ - temporary_tags = [tag for tag in FormattingTags.html_expands - if tag.get(u'temporary')] + temporary_tags = [tag for tag in FormattingTags.html_expands if tag.get(u'temporary')] FormattingTags.html_expands = [] base_tags = [] # Append the base tags. - # Hex Color tags from http://www.w3schools.com/html/html_colornames.asp base_tags.append({u'desc': translate('OpenLP.FormattingTags', 'Red'), u'start tag': u'{r}', u'start html': u'', @@ -195,19 +190,17 @@ class FormattingTags(object): The end tag, e. g. ``{/r}`` * start html - The start html tag. For instance ```` + The start html tag. For instance ```` * end html The end html tag. For example ```` * protected - A boolean stating whether this is a build-in tag or not. Should be - ``True`` in most cases. + A boolean stating whether this is a build-in tag or not. Should be ``True`` in most cases. * temporary - A temporary tag will not be saved, but is also considered when - displaying text containing the tag. It has to be a ``boolean``. + A temporary tag will not be saved, but is also considered when displaying text containing the tag. It has + to be a ``boolean``. """ FormattingTags.html_expands.extend(tags) diff --git a/tests/functional/openlp_core_lib/test_formattingtags.py b/tests/functional/openlp_core_lib/test_formattingtags.py new file mode 100644 index 000000000..335650112 --- /dev/null +++ b/tests/functional/openlp_core_lib/test_formattingtags.py @@ -0,0 +1,78 @@ +""" +Package to test the openlp.core.lib.formattingtags package. +""" +import copy +from unittest import TestCase + +from mock import patch + +from openlp.core.lib import FormattingTags + + +TAG = { + u'end tag': '{/aa}', + u'start html': '', + u'start tag': '{aa}', + u'protected': False, + u'end html': '', + u'desc': 'name' +} + + +class TestFormattingTags(TestCase): + + def tearDown(self): + """ + Clean up the FormattingTags class. + """ + FormattingTags.html_expands = [] + + def get_html_tags_no_user_tags_test(self): + """ + Test the FormattingTags class' get_html_tags static method. + """ + with patch(u'openlp.core.lib.translate') as mocked_translate, \ + patch(u'openlp.core.lib.settings') as mocked_settings, \ + patch(u'openlp.core.lib.formattingtags.cPickle') as mocked_cPickle: + # GIVEN: Our mocked modules and functions. + mocked_translate.side_effect = lambda module, string_to_translate, comment: string_to_translate + mocked_settings.value.return_value = u'' + mocked_cPickle.load.return_value = [] + + # WHEN: Get the display tags. + FormattingTags.load_tags() + old_tags_list = copy.deepcopy(FormattingTags.get_html_tags()) + FormattingTags.load_tags() + new_tags_list = FormattingTags.get_html_tags() + + # THEN: Lists should be identically. + assert old_tags_list == new_tags_list, u'The formatting tag lists should be identically.' + + def get_html_tags_with_user_tags_test(self): + """ + Test the FormattingTags class' get_html_tags static method in combination with user tags. + """ + with patch(u'openlp.core.lib.translate') as mocked_translate, \ + patch(u'openlp.core.lib.settings') as mocked_settings, \ + patch(u'openlp.core.lib.formattingtags.cPickle') as mocked_cPickle: + # GIVEN: Our mocked modules and functions. + mocked_translate.side_effect = lambda module, string_to_translate: string_to_translate + mocked_settings.value.return_value = u'' + mocked_cPickle.loads.side_effect = [[], [TAG]] + + # WHEN: Get the display tags. + FormattingTags.load_tags() + old_tags_list = copy.deepcopy(FormattingTags.get_html_tags()) + + # WHEN: Add our tag and get the tags again. + FormattingTags.load_tags() + FormattingTags.add_html_tags([TAG]) + new_tags_list = FormattingTags.get_html_tags() + + # THEN: Lists should not be identically. + assert old_tags_list != new_tags_list, u'The lists should be different.' + + # THEN: Added tag and last tag should be the same. + new_tag = new_tags_list.pop() + assert TAG == new_tag, u'Tags should be identically.' + diff --git a/tests/functional/openlp_core_lib/test_serviceitem.py b/tests/functional/openlp_core_lib/test_serviceitem.py index 05952471d..0e2cf2883 100644 --- a/tests/functional/openlp_core_lib/test_serviceitem.py +++ b/tests/functional/openlp_core_lib/test_serviceitem.py @@ -209,4 +209,5 @@ class TestServiceItem(TestCase): first_line = items[0] except: first_line = u'' - return first_line \ No newline at end of file + return first_line + diff --git a/tests/functional/openlp_core_lib/test_uistrings.py b/tests/functional/openlp_core_lib/test_uistrings.py new file mode 100644 index 000000000..3351657d1 --- /dev/null +++ b/tests/functional/openlp_core_lib/test_uistrings.py @@ -0,0 +1,22 @@ +""" +Package to test the openlp.core.lib.uistrings package. +""" + +from unittest import TestCase + +from openlp.core.lib import UiStrings + +class TestUiStrings(TestCase): + + def check_same_instance_test(self): + """ + Test the UiStrings class - we always should have only one instance of the UiStrings class. + """ + # WHEN: Create two instances of the UiStrings class. + first_instance = UiStrings() + second_instance = UiStrings() + + # THEN: Check if the instances are the same. + assert first_instance is second_instance, "They should be the same instance!" + +