openlp-core team mailing list archive
-
openlp-core team
-
Mailing list archive
-
Message #27119
[Merge] lp:~tomasgroth/openlp/py33fix into lp:openlp
Tomas Groth has proposed merging lp:~tomasgroth/openlp/py33fix into lp:openlp.
Requested reviews:
OpenLP Core (openlp-core)
For more details, see:
https://code.launchpad.net/~tomasgroth/openlp/py33fix/+merge/263840
Revert changes to support python 3.5 to make sure we support python 3.3.
Fix traceback in OSIS import on empty verse tag.
--
Your team OpenLP Core is requested to review the proposed merge of lp:~tomasgroth/openlp/py33fix into lp:openlp.
=== modified file 'openlp/plugins/bibles/lib/osis.py'
--- openlp/plugins/bibles/lib/osis.py 2015-03-09 20:57:39 +0000
+++ openlp/plugins/bibles/lib/osis.py 2015-07-04 22:27:52 +0000
@@ -153,7 +153,8 @@
# Verse-tags contains the text
for verse in chapter:
verse_number = verse.get("osisID").split('.')[2]
- self.create_verse(db_book.id, chapter_number, verse_number, verse.text.strip())
+ if verse.text:
+ self.create_verse(db_book.id, chapter_number, verse_number, verse.text.strip())
self.wizard.increment_progress_bar(
translate('BiblesPlugin.OsisImport', 'Importing %(bookname)s %(chapter)s...') %
{'bookname': db_book.name, 'chapter': chapter_number})
=== modified file 'openlp/plugins/songs/lib/songselect.py'
--- openlp/plugins/songs/lib/songselect.py 2015-06-17 17:46:45 +0000
+++ openlp/plugins/songs/lib/songselect.py 2015-07-04 22:27:52 +0000
@@ -27,7 +27,6 @@
from urllib.parse import urlencode
from urllib.request import HTTPCookieProcessor, URLError, build_opener
from html.parser import HTMLParser
-from html import unescape
from bs4 import BeautifulSoup, NavigableString
@@ -131,8 +130,8 @@
break
for result in search_results:
song = {
- 'title': unescape(result.find('h3').string),
- 'authors': [unescape(author.string) for author in result.find_all('li')],
+ 'title': self.html_parser.unescape(result.find('h3').string),
+ 'authors': [self.html_parser.unescape(author.string) for author in result.find_all('li')],
'link': BASE_URL + result.find('a')['href']
}
if callback:
@@ -168,7 +167,7 @@
if callback:
callback()
song['copyright'] = '/'.join([li.string for li in song_page.find('ul', 'copyright').find_all('li')])
- song['copyright'] = unescape(song['copyright'])
+ song['copyright'] = self.html_parser.unescape(song['copyright'])
song['ccli_number'] = song_page.find('ul', 'info').find('li').string.split(':')[1].strip()
song['verses'] = []
verses = lyrics_page.find('section', 'lyrics').find_all('p')
@@ -181,9 +180,9 @@
else:
verse['lyrics'] += '\n'
verse['lyrics'] = verse['lyrics'].strip(' \n\r\t')
- song['verses'].append(unescape(verse))
+ song['verses'].append(self.html_parser.unescape(verse))
for counter, author in enumerate(song['authors']):
- song['authors'][counter] = unescape(author)
+ song['authors'][counter] = self.html_parser.unescape(author)
return song
def save_song(self, song):
=== modified file 'tests/functional/openlp_plugins/bibles/test_osisimport.py'
--- tests/functional/openlp_plugins/bibles/test_osisimport.py 2015-01-18 13:39:21 +0000
+++ tests/functional/openlp_plugins/bibles/test_osisimport.py 2015-07-04 22:27:52 +0000
@@ -152,3 +152,33 @@
self.assertTrue(importer.create_verse.called)
for verse_tag, verse_text in test_data['verses']:
importer.create_verse.assert_any_call(importer.create_book().id, '1', verse_tag, verse_text)
+
+ def file_import_empty_verse_tags_test(self):
+ """
+ Test the actual import of OSIS Bible file, with an empty verse tags.
+ """
+ # GIVEN: Test files with a mocked out "manager", "import_wizard", and mocked functions
+ # get_book_ref_id_by_name, create_verse, create_book, session and get_language.
+ result_file = open(os.path.join(TEST_PATH, 'dk1933.json'), 'rb')
+ test_data = json.loads(result_file.read().decode())
+ bible_file = 'osis-dk1933-empty-verse.xml'
+ with patch('openlp.plugins.bibles.lib.osis.OSISBible.application'):
+ mocked_manager = MagicMock()
+ mocked_import_wizard = MagicMock()
+ importer = OSISBible(mocked_manager, path='.', name='.', filename='')
+ importer.wizard = mocked_import_wizard
+ importer.get_book_ref_id_by_name = MagicMock()
+ importer.create_verse = MagicMock()
+ importer.create_book = MagicMock()
+ importer.session = MagicMock()
+ importer.get_language = MagicMock()
+ importer.get_language.return_value = 'Danish'
+
+ # WHEN: Importing bible file
+ importer.filename = os.path.join(TEST_PATH, bible_file)
+ importer.do_import()
+
+ # THEN: The create_verse() method should have been called with each verse in the file.
+ self.assertTrue(importer.create_verse.called)
+ for verse_tag, verse_text in test_data['verses']:
+ importer.create_verse.assert_any_call(importer.create_book().id, '1', verse_tag, verse_text)
=== added file 'tests/resources/bibles/osis-dk1933-empty-verse.xml'
--- tests/resources/bibles/osis-dk1933-empty-verse.xml 1970-01-01 00:00:00 +0000
+++ tests/resources/bibles/osis-dk1933-empty-verse.xml 2015-07-04 22:27:52 +0000
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<osis xmlns="http://www.bibletechnologies.net/2003/OSIS/namespace" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.bibletechnologies.net/2003/OSIS/namespace http://www.bibletechnologies.net/osisCore.2.1.1.xsd">
+ <osisText osisIDWork="DanDetteBiblen" osisRefWork="defaultReferenceScheme" xml:lang="da">
+ <header>
+ <work osisWork="DanDetteBiblen">
+ <title>Dette er Biblen</title>
+ <identifier type="OSIS">Bible.DanDetteBiblen</identifier>
+ <refSystem>Bible.KJV</refSystem>
+ </work>
+ <work osisWork="defaultReferenceScheme">
+ <refSystem>Bible.KJV</refSystem>
+ </work>
+ </header>
+ <div type="x-testament">
+ <div type="book" osisID="Gen">
+ <chapter osisID="Gen.1">
+ <verse osisID="Gen.1.1">I Begyndelsen skabte Gud Himmelen og Jorden.</verse>
+ <verse osisID="Gen.1.2">Og Jorden var øde og tom, og der var Mørke over Verdensdybet. Men Guds Ånd svævede over Vandene.<p /></verse>
+ <verse osisID="Gen.1.3">Og Gud sagde: "Der blive Lys!" Og der blev Lys.</verse>
+ <verse osisID="Gen.1.4">Og Gud så, at Lyset var godt, og Gud satte Skel mellem Lyset og Mørket,</verse>
+ <verse osisID="Gen.1.5">og Gud kaldte Lyset Dag, og Mørket kaldte han Nat. Og det blev Aften, og det blev Morgen, første Dag.<p /></verse>
+ <verse osisID="Gen.1.6">Derpå sagde Gud: "Der blive en Hvælving midt i Vandene til at skille Vandene ad!"</verse>
+ <verse osisID="Gen.1.7">Og således skete det: Gud gjorde Hvælvingen og skilte Vandet under Hvælvingen fra Vandet over Hvælvingen;</verse>
+ <verse osisID="Gen.1.8">og Gud kaldte Hvælvingen Himmel. Og det blev Aften, og det blev Morgen, anden Dag.<p /></verse>
+ <verse osisID="Gen.1.9">Derpå sagde Gud: "Vandet under Himmelen samle sig på eet Sted, så det faste Land kommer til Syne!" Og således skete det;</verse>
+ <verse osisID="Gen.1.10">og Gud kaldte det faste Land Jord, og Stedet, hvor Vandet samlede sig, kaldte han Hav. Og Gud så, at det var godt.</verse>
+ <verse osisID="Gen.1.11"></verse>
+ </chapter>
+ </div>
+ </div>
+ </osisText>
+</osis>
References