openlp-core team mailing list archive
-
openlp-core team
-
Mailing list archive
-
Message #19364
[Merge] lp:~googol/openlp/tests into lp:openlp
Andreas Preikschat has proposed merging lp:~googol/openlp/tests into lp:openlp.
Requested reviews:
OpenLP Core (openlp-core)
For more details, see:
https://code.launchpad.net/~googol/openlp/tests/+merge/148748
Hello,
- Added UiStrings test
- Added FormattingTags tests
--
https://code.launchpad.net/~googol/openlp/tests/+merge/148748
Your team OpenLP Core is requested to review the proposed merge of lp:~googol/openlp/tests into lp:openlp.
=== modified file 'openlp/core/lib/formattingtags.py'
--- openlp/core/lib/formattingtags.py 2013-02-05 08:05:28 +0000
+++ openlp/core/lib/formattingtags.py 2013-02-15 16:18:26 +0000
@@ -36,8 +36,7 @@
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 @@
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 @@
@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'<span style="-webkit-text-fill-color:red">',
@@ -195,19 +190,17 @@
The end tag, e. g. ``{/r}``
* start html
- The start html tag. For instance ``<span style="
- -webkit-text-fill-color:red">``
+ The start html tag. For instance ``<span style="-webkit-text-fill-color:red">``
* end html
The end html tag. For example ``</span>``
* 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)
=== added file 'tests/functional/openlp_core_lib/test_formattingtags.py'
--- tests/functional/openlp_core_lib/test_formattingtags.py 1970-01-01 00:00:00 +0000
+++ tests/functional/openlp_core_lib/test_formattingtags.py 2013-02-15 16:18:26 +0000
@@ -0,0 +1,76 @@
+"""
+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
+
+
+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 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 = 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):
+ """
+ Add a tag and check if it still exists after reloading the tags list.
+ """
+ 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''
+ tag = {
+ u'end tag': '{/aa}',
+ u'start html': '<span>',
+ u'start tag': '{aa}',
+ u'protected': False,
+ u'end html': '</span>',
+ u'desc': 'name'
+ }
+ 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.'
+
=== modified file 'tests/functional/openlp_core_lib/test_serviceitem.py'
--- tests/functional/openlp_core_lib/test_serviceitem.py 2013-01-27 20:59:02 +0000
+++ tests/functional/openlp_core_lib/test_serviceitem.py 2013-02-15 16:18:26 +0000
@@ -210,4 +210,5 @@
first_line = items[0]
except:
first_line = u''
- return first_line
\ No newline at end of file
+ return first_line
+
=== added file 'tests/functional/openlp_core_lib/test_uistrings.py'
--- tests/functional/openlp_core_lib/test_uistrings.py 1970-01-01 00:00:00 +0000
+++ tests/functional/openlp_core_lib/test_uistrings.py 2013-02-15 16:18:26 +0000
@@ -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 if the always only one instance of the UiStrings is created.
+ """
+ # 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!"
+
+
Follow ups