added expand_tags() method test

This commit is contained in:
Andreas Preikschat 2013-03-05 15:36:01 +01:00
parent a835930990
commit d5f4685788
1 changed files with 41 additions and 1 deletions

View File

@ -7,7 +7,7 @@ from datetime import datetime, timedelta
from mock import MagicMock, patch
from openlp.core.lib import str_to_bool, translate, check_directory_exists, get_text_file_string, build_icon, \
image_to_byte, check_item_selected, validate_thumb, create_separated_list
image_to_byte, check_item_selected, validate_thumb, create_separated_list, expand_tags
class TestLib(TestCase):
@ -299,6 +299,46 @@ class TestLib(TestCase):
MockedQtGui.QMessageBox.information.assert_called_with(u'parent', u'mocked translate', 'message')
assert not result, u'The result should be False'
def expand_tags_test(self):
"""
Test the expand_tags() method.
"""
with patch(u'openlp.core.lib.FormattingTags.get_html_tags') as mocked_get_tags:
# GIVEN: Mocked get_html_tags() method.
mocked_get_tags.return_value = [
{
u'desc': u'Black',
u'start tag': u'{b}',
u'start html': u'<span style="-webkit-text-fill-color:black">',
u'end tag': u'{/b}', u'end html': u'</span>', u'protected': True,
u'temporary': False
},
{
u'desc': u'Yellow',
u'start tag': u'{y}',
u'start html': u'<span style="-webkit-text-fill-color:yellow">',
u'end tag': u'{/y}', u'end html': u'</span>', u'protected': True,
u'temporary': False
},
{
u'desc': u'Green',
u'start tag': u'{g}',
u'start html': u'<span style="-webkit-text-fill-color:green">',
u'end tag': u'{/g}', u'end html': u'</span>', u'protected': True,
u'temporary': False
}
]
string_to_pass = u'{b}black{/b}{y}yellow{/y}'
wanted_string = u'<span style="-webkit-text-fill-color:black">black</span>' + \
'<span style="-webkit-text-fill-color:yellow">yellow</span>'
# WHEN: Replace the tags.
result_string = expand_tags(string_to_pass)
# THEN: The strings should be identical.
assert result_string == wanted_string, u'The strings should be identical.'
def validate_thumb_file_does_not_exist_test(self):
"""
Test the validate_thumb() function when the thumbnail does not exist