From 3a3ca8d93322a35062c5b192e081ceac26d1a1c3 Mon Sep 17 00:00:00 2001 From: Tomas Groth Date: Sun, 18 Sep 2016 16:54:55 +0200 Subject: [PATCH 1/4] Fix fetching bible texts from CrossWalk. --- openlp/plugins/bibles/lib/importers/http.py | 2 +- .../openlp_plugins/bibles/test_lib_http.py | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/openlp/plugins/bibles/lib/importers/http.py b/openlp/plugins/bibles/lib/importers/http.py index 6921c9005..d41187d93 100644 --- a/openlp/plugins/bibles/lib/importers/http.py +++ b/openlp/plugins/bibles/lib/importers/http.py @@ -493,7 +493,7 @@ class CWExtract(RegistryProperties): for verse in verses_div: self.application.process_events() verse_number = int(verse.find('strong').contents[0]) - verse_span = verse.find('span') + verse_span = verse.find('span', class_='verse-%d' % verse_number) tags_to_remove = verse_span.find_all(['a', 'sup']) for tag in tags_to_remove: tag.decompose() diff --git a/tests/interfaces/openlp_plugins/bibles/test_lib_http.py b/tests/interfaces/openlp_plugins/bibles/test_lib_http.py index 084bfa476..7068898fe 100644 --- a/tests/interfaces/openlp_plugins/bibles/test_lib_http.py +++ b/tests/interfaces/openlp_plugins/bibles/test_lib_http.py @@ -163,3 +163,19 @@ class TestBibleHTTP(TestCase): # THEN: The list should not be None, and some known bibles should be there self.assertIsNotNone(bibles) self.assertIn(('Giovanni Diodati 1649 (Italian)', 'gdb', 'it'), bibles) + + def test_crosswalk_get_verse_text(self): + """ + Test verse text from Crosswalk.com + """ + # GIVEN: A new Crosswalk extraction class + handler = CWExtract() + + # WHEN: downloading NIV Genesis from Crosswalk + niv_genesis_chapter_one = handler.get_bible_chapter('niv', 'Genesis', 1) + + # THEN: The verse list should contain the verses + self.assertTrue(niv_genesis_chapter_one.has_verse_list()) + self.assertEquals('In the beginning God created the heavens and the earth.', + niv_genesis_chapter_one.verse_list[1], + 'The first chapter of genesis should have been fetched.') From 4754d1eb8b3c653487c1652b2dae72189dbb376d Mon Sep 17 00:00:00 2001 From: Tomas Groth Date: Sun, 18 Sep 2016 17:28:55 +0200 Subject: [PATCH 2/4] Try to fix a mediashout import issue by replacing the line tab char with 2 linebreaks. --- openlp/plugins/songs/lib/importers/mediashout.py | 2 +- openlp/plugins/songs/lib/importers/songimport.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/openlp/plugins/songs/lib/importers/mediashout.py b/openlp/plugins/songs/lib/importers/mediashout.py index a3bd7bbbc..9b916cd43 100644 --- a/openlp/plugins/songs/lib/importers/mediashout.py +++ b/openlp/plugins/songs/lib/importers/mediashout.py @@ -101,7 +101,7 @@ class MediaShoutImport(SongImport): self.song_book_name = song.SongID for verse in verses: tag = VERSE_TAGS[verse.Type] + str(verse.Number) if verse.Type < len(VERSE_TAGS) else 'O' - self.add_verse(verse.Text, tag) + self.add_verse(self.tidy_text(verse.Text), tag) for order in verse_order: if order.Type < len(VERSE_TAGS): self.verse_order_list.append(VERSE_TAGS[order.Type] + str(order.Number)) diff --git a/openlp/plugins/songs/lib/importers/songimport.py b/openlp/plugins/songs/lib/importers/songimport.py index c9ef382a7..3fea7e9c7 100644 --- a/openlp/plugins/songs/lib/importers/songimport.py +++ b/openlp/plugins/songs/lib/importers/songimport.py @@ -140,6 +140,7 @@ class SongImport(QtCore.QObject): text = text.replace('\u2026', '...') text = text.replace('\u2013', '-') text = text.replace('\u2014', '-') + text = text.replace('\x0b', '\n\n') # Remove surplus blank lines, spaces, trailing/leading spaces text = re.sub(r'[ \t\v]+', ' ', text) text = re.sub(r' ?(\r\n?|\n) ?', '\n', text) From 32cfacff7e05955e04067b373296247c765eb849 Mon Sep 17 00:00:00 2001 From: Tomas Groth Date: Sun, 18 Sep 2016 17:47:59 +0200 Subject: [PATCH 3/4] Skip MediaShout import testing on non-win platforms. --- tests/functional/openlp_plugins/songs/test_mediashout.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/functional/openlp_plugins/songs/test_mediashout.py b/tests/functional/openlp_plugins/songs/test_mediashout.py index 4f03c4f94..c08b04df7 100644 --- a/tests/functional/openlp_plugins/songs/test_mediashout.py +++ b/tests/functional/openlp_plugins/songs/test_mediashout.py @@ -22,15 +22,20 @@ """ Test the MediaShout importer """ -from unittest import TestCase +from unittest import TestCase, skipUnless from collections import namedtuple from openlp.core.common import Registry -from openlp.plugins.songs.lib.importers.mediashout import MediaShoutImport +try: + from openlp.plugins.songs.lib.importers.mediashout import MediaShoutImport + CAN_RUN_TESTS = True +except ImportError: + CAN_RUN_TESTS = False from tests.functional import MagicMock, patch, call +@skipUnless(CAN_RUN_TESTS, 'Not Windows, skipping test') class TestMediaShoutImport(TestCase): """ Test the MediaShout importer From 453bd53657e0b11d600b83225911be65f3ec18a9 Mon Sep 17 00:00:00 2001 From: Tomas Groth Date: Fri, 23 Sep 2016 23:46:43 +0200 Subject: [PATCH 4/4] Fix the tidy_text method to not insert linefeeds, which is not allowed in XML. --- openlp/plugins/songs/lib/importers/songimport.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/openlp/plugins/songs/lib/importers/songimport.py b/openlp/plugins/songs/lib/importers/songimport.py index 3fea7e9c7..c8648db85 100644 --- a/openlp/plugins/songs/lib/importers/songimport.py +++ b/openlp/plugins/songs/lib/importers/songimport.py @@ -140,11 +140,13 @@ class SongImport(QtCore.QObject): text = text.replace('\u2026', '...') text = text.replace('\u2013', '-') text = text.replace('\u2014', '-') - text = text.replace('\x0b', '\n\n') + # Replace vertical tab with 2 linebreaks + text = text.replace('\v', '\n\n') + # Replace form feed (page break) with 2 linebreaks + text = text.replace('\f', '\n\n') # Remove surplus blank lines, spaces, trailing/leading spaces - text = re.sub(r'[ \t\v]+', ' ', text) + text = re.sub(r'[ \t]+', ' ', text) text = re.sub(r' ?(\r\n?|\n) ?', '\n', text) - text = re.sub(r' ?(\n{5}|\f)+ ?', '\f', text) return text def process_song_text(self, text):