Fixes for translation support + test

This commit is contained in:
Tomas Groth 2016-03-19 07:20:12 +01:00
parent fdc22b4e4c
commit 7b69634552
3 changed files with 62 additions and 10 deletions

View File

@ -170,20 +170,20 @@ class OpsProImport(SongImport):
idx += 1
# Handle the text based on whether translation is off or on
if language:
translation_verse_text += verse_text_lines[idx] + '\r\n'
idx += 1
if language == 'b':
translation_verse_text += start_tag
while idx < len(verse_text_lines) and not verse_text_lines[idx].startswith('['):
if language == 'a':
translation_verse_text += verse_text_lines[idx] + '\r\n'
else:
translation_verse_text += start_tag + verse_text_lines[idx] + end_tag + '\r\n'
translation_verse_text += verse_text_lines[idx] + '\r\n'
idx += 1
if language == 'b':
translation_verse_text += end_tag
language = None
elif translation:
translation_verse_text += verse_text_lines[idx] + '\r\n'
idx += 1
translation_verse_text += start_tag + verse_text_lines[idx] + end_tag + '\r\n'
idx += 1
if idx < len(verse_text_lines) and not verse_text_lines[idx].startswith('['):
translation_verse_text += start_tag + verse_text_lines[idx] + end_tag + '\r\n'
idx += 1
else:
translation_verse_text += verse_text_lines[idx] + '\r\n'
idx += 1
@ -194,8 +194,6 @@ class OpsProImport(SongImport):
# Remove comments
verse_text = re.sub('\(.*?\)\r\n', '', verse_text, flags=re.IGNORECASE)
self.add_verse(verse_text, verse_def)
#print(verse_def)
#print(verse_text)
self.finish()
def extract_mdb_password(self):

View File

@ -79,6 +79,7 @@ class TestOpsProSongImport(TestCase):
importer = OpsProImport(mocked_manager, filenames=[])
importer.finish = MagicMock()
song, lyrics = self._build_test_data('you are so faithfull.txt', False)
# WHEN: An importer object is created
importer.process_song(song, lyrics, [])
@ -98,6 +99,7 @@ class TestOpsProSongImport(TestCase):
importer = OpsProImport(mocked_manager, filenames=[])
importer.finish = MagicMock()
song, lyrics = self._build_test_data('amazing grace.txt', False)
# WHEN: An importer object is created
importer.process_song(song, lyrics, [])
@ -117,6 +119,7 @@ class TestOpsProSongImport(TestCase):
importer = OpsProImport(mocked_manager, filenames=[])
importer.finish = MagicMock()
song, lyrics = self._build_test_data('amazing grace2.txt', True)
# WHEN: An importer object is created
importer.process_song(song, lyrics, [])
@ -126,6 +129,26 @@ class TestOpsProSongImport(TestCase):
self.assertListEqual(importer.verses, self._get_data(result_data, 'verses'))
self.assertListEqual(importer.verse_order_list_generated, self._get_data(result_data, 'verse_order_list'))
@patch('openlp.plugins.songs.lib.importers.opspro.SongImport')
def trans_tag_test(self, mocked_songimport):
"""
Test importing lyrics with various translations tags works in OPS Pro
"""
# GIVEN: A mocked out SongImport class, a mocked out "manager" and a mocked song and lyrics entry
mocked_manager = MagicMock()
importer = OpsProImport(mocked_manager, filenames=[])
importer.finish = MagicMock()
song, lyrics = self._build_test_data('amazing grace3.txt', True)
# WHEN: An importer object is created
importer.process_song(song, lyrics, [])
# THEN: The imported data should look like expected
result_file = open(os.path.join(TEST_PATH, 'Amazing Grace3.json'), 'rb')
result_data = json.loads(result_file.read().decode())
self.assertListEqual(importer.verses, self._get_data(result_data, 'verses'))
self.assertListEqual(importer.verse_order_list_generated, self._get_data(result_data, 'verse_order_list'))
def _get_data(self, data, key):
if key in data:
return data[key]

View File

@ -0,0 +1,31 @@
{
"title": "Amazing Grace",
"verse_order_list": ["v1", "v2", "v3", "v4", "v5"],
"verses": [
[
"v1",
"Amazing grace! How sweet the sound!\r\n{translation}That saved a wretch like me!{/translation}\r\nI once was lost, but now am found;\r\n{translation}Was blind, but now I see.{/translation}",
null
],
[
"v2",
"'Twas grace that taught my heart to fear,\r\nAnd grace my fears relieved.\r\n{translation}How precious did that grace appear,\r\nThe hour I first believed.\r\n{/translation}",
null
],
[
"v3",
"The Lord has promised good to me,\r\nHis Word my hope secures.\r\nHe will my shield and portion be\r\n{translation}As long as life endures.{/translation}",
null
],
[
"v4",
"Thro' many dangers, toils and snares\r\nI have already come.\r\n'Tis grace that brought me safe thus far,\r\n{translation}And grace will lead me home.{/translation}",
null
],
[
"v5",
"[end]\r\n{translation}When we've been there ten thousand years,{/translation}\r\nBright shining as the sun,\r\n{translation}We've no less days to sing God's praise,{/translation}\r\nThan when we first begun.",
null
]
]
}