forked from openlp/openlp
Fix some broken tests that was not being used due to naming.
This commit is contained in:
parent
692a08f888
commit
e593d77e14
@ -20,6 +20,7 @@
|
||||
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
||||
###############################################################################
|
||||
|
||||
import re
|
||||
|
||||
from PyQt5 import QtGui, QtCore, QtWebKitWidgets
|
||||
|
||||
@ -441,7 +442,7 @@ class Renderer(OpenLPMixin, RegistryMixin, RegistryProperties):
|
||||
previous_raw = line + line_end
|
||||
continue
|
||||
# Figure out how many words of the line will fit on screen as the line will not fit as a whole.
|
||||
raw_words = Renderer.words_split(line)
|
||||
raw_words = words_split(line)
|
||||
html_words = list(map(expand_tags, raw_words))
|
||||
previous_html, previous_raw = \
|
||||
self._binary_chop(formatted, previous_html, previous_raw, html_words, raw_words, ' ', line_end)
|
||||
@ -528,8 +529,7 @@ def words_split(line):
|
||||
:param line: Line to be split
|
||||
"""
|
||||
# this parse we are to be wordy
|
||||
line = line.replace('\n', ' ')
|
||||
return line.split(' ')
|
||||
return re.split('\s+', line)
|
||||
|
||||
|
||||
def get_start_tags(raw_text):
|
||||
@ -548,11 +548,15 @@ def get_start_tags(raw_text):
|
||||
raw_tags = []
|
||||
html_tags = []
|
||||
for tag in FormattingTags.get_html_tags():
|
||||
print('looking at tag...')
|
||||
if tag['start tag'] == '{br}':
|
||||
continue
|
||||
if raw_text.count(tag['start tag']) != raw_text.count(tag['end tag']):
|
||||
print('should append')
|
||||
raw_tags.append((raw_text.find(tag['start tag']), tag['start tag'], tag['end tag']))
|
||||
html_tags.append((raw_text.find(tag['start tag']), tag['start html']))
|
||||
print(raw_tags)
|
||||
print(html_tags)
|
||||
# Sort the lists, so that the tags which were opened first on the first slide (the text we are checking) will be
|
||||
# opened first on the next slide as well.
|
||||
raw_tags.sort(key=lambda tag: tag[0])
|
||||
|
@ -27,7 +27,8 @@ from unittest import TestCase
|
||||
from PyQt5 import QtCore
|
||||
|
||||
from openlp.core.common import Registry
|
||||
from openlp.core.lib import Renderer, ScreenList, ServiceItem
|
||||
from openlp.core.lib import Renderer, ScreenList, ServiceItem, FormattingTags
|
||||
from openlp.core.lib.renderer import words_split, get_start_tags
|
||||
|
||||
from tests.functional import MagicMock
|
||||
|
||||
@ -71,34 +72,33 @@ class TestRenderer(TestCase):
|
||||
self.assertEqual(renderer.screen_ratio, 0.75, 'The base renderer should be a live controller')
|
||||
self.assertEqual(renderer.footer_start, 691, 'The base renderer should be a live controller')
|
||||
|
||||
def _get_start_tags_test(self):
|
||||
def get_start_tags_test(self):
|
||||
"""
|
||||
Test the _get_start_tags() method
|
||||
Test the get_start_tags() method
|
||||
"""
|
||||
# GIVEN: A new renderer instance. Broken raw_text (missing closing tags).
|
||||
renderer = Renderer()
|
||||
given_raw_text = '{st}{r}Text text text'
|
||||
expected_tuple = ('{st}{r}Text text text{/r}{/st}', '{st}{r}',
|
||||
'<strong><span style="-webkit-text-fill-color:red">')
|
||||
FormattingTags.load_tags()
|
||||
|
||||
# WHEN: The renderer converts the start tags
|
||||
result = renderer._get_start_tags(given_raw_text)
|
||||
result = get_start_tags(given_raw_text)
|
||||
|
||||
# THEN: Check if the correct tuple is returned.
|
||||
self.assertEqual(result, expected_tuple), 'A tuple should be returned containing the text with correct ' \
|
||||
'tags, the opening tags, and the opening html tags.'
|
||||
|
||||
def _word_split_test(self):
|
||||
def word_split_test(self):
|
||||
"""
|
||||
Test the _word_split() method
|
||||
Test the word_split() method
|
||||
"""
|
||||
# GIVEN: A line of text
|
||||
renderer = Renderer()
|
||||
given_line = 'beginning asdf \n end asdf'
|
||||
expected_words = ['beginning', 'asdf', 'end', 'asdf']
|
||||
|
||||
# WHEN: Split the line based on word split rules
|
||||
result_words = renderer._words_split(given_line)
|
||||
result_words = words_split(given_line)
|
||||
|
||||
# THEN: The word lists should be the same.
|
||||
self.assertListEqual(result_words, expected_words)
|
||||
|
Loading…
Reference in New Issue
Block a user