Fix bug 1247493: OpenSong Importer fails

bzr-revno: 2367
Fixes: https://launchpad.net/bugs/1247493
This commit is contained in:
Samuel Mehrbrodt 2014-04-20 21:15:21 +01:00 committed by Tim Bentley
commit cec163085c
19 changed files with 61 additions and 55 deletions

View File

@ -73,13 +73,13 @@ class OpenSongBible(BibleDB):
log.debug('Starting OpenSong import from "%s"' % self.filename)
if not isinstance(self.filename, str):
self.filename = str(self.filename, 'utf8')
file = None
import_file = None
success = True
try:
# NOTE: We don't need to do any of the normal encoding detection here, because lxml does it's own encoding
# detection, and the two mechanisms together interfere with each other.
file = open(self.filename, 'r')
opensong = objectify.parse(file)
import_file = open(self.filename, 'rb')
opensong = objectify.parse(import_file)
bible = opensong.getroot()
language_id = self.get_language(bible_name)
if not language_id:
@ -93,7 +93,7 @@ class OpenSongBible(BibleDB):
log.error('Importing books from "%s" failed' % self.filename)
return False
book_details = BiblesResourcesDB.get_book_by_id(book_ref_id)
db_book = self.create_book(str(book.attrib['n']), book_ref_id, book_details['testament_id'])
db_book = self.create_book(book.attrib['n'], book_ref_id, book_details['testament_id'])
chapter_number = 0
for chapter in book.c:
if self.stop_import_flag:
@ -122,8 +122,8 @@ class OpenSongBible(BibleDB):
verse_number += 1
self.create_verse(db_book.id, chapter_number, verse_number, self.get_text(verse))
self.wizard.increment_progress_bar(
translate('BiblesPlugin.Opensong', 'Importing %s %s...',
'Importing <book name> <chapter>...')) % (db_book.name, chapter_number)
translate('BiblesPlugin.Opensong', 'Importing %(bookname)s %(chapter)s...' %
{'bookname': db_book.name, 'chapter': chapter_number}))
self.session.commit()
self.application.process_events()
except etree.XMLSyntaxError as inst:
@ -137,8 +137,8 @@ class OpenSongBible(BibleDB):
log.exception('Loading Bible from OpenSong file failed')
success = False
finally:
if file:
file.close()
if import_file:
import_file.close()
if self.stop_import_flag:
return False
else:

View File

@ -96,7 +96,7 @@ class CommandStack(object):
return len(self.data)
def __getitem__(self, index):
if not index in self.data:
if index not in self.data:
return None
elif self.data[index].get('arguments'):
return self.data[index]['command'], self.data[index]['arguments']

View File

@ -79,5 +79,5 @@ class TestCommonFunctions(TestCase):
trace_error_handler(mocked_logger)
# THEN: The mocked_logger.error() method should have been called with the correct parameters
mocked_logger.error.assert_called_with('OpenLP Error trace\n File openlp.fake at line 56 \n\t called trace_error_handler_test')
mocked_logger.error.assert_called_with(
'OpenLP Error trace\n File openlp.fake at line 56 \n\t called trace_error_handler_test')

View File

@ -403,8 +403,8 @@ class TestEasyWorshipSongImport(TestCase):
if song_copyright:
self.assertEqual(importer.copyright, song_copyright)
if ccli_number:
self.assertEqual(importer.ccli_number, ccli_number, 'ccli_number for %s should be %s'
% (title, ccli_number))
self.assertEqual(importer.ccli_number, ccli_number,
'ccli_number for %s should be %s' % (title, ccli_number))
for verse_text, verse_tag in add_verse_calls:
mocked_add_verse.assert_any_call(verse_text, verse_tag)
if verse_order_list:

View File

@ -129,7 +129,6 @@ class TestLib(TestCase):
# THEN: The result should be a tuple of songs..
assert result == (self.song1, self.song2), 'The result should be the tuble of songs'
def songs_probably_equal_different_song_test(self):
"""
Test the songs_probably_equal function with two different songs.

View File

@ -49,7 +49,8 @@ SONG_TEST_DATA = {
('4. Lobsingt seiner Treu´,\ndie immerdar neu,\nbis Er uns zur Herrlichket führet!\n\n', 'v')
],
'song_book_name': 'Glaubenslieder I',
'song_number': "1"
'song_number': "1",
'authors': ['Carl Brockhaus', 'Johann Jakob Vetter']
}
}
@ -140,6 +141,7 @@ class TestSongBeamerImport(TestCase):
add_verse_calls = SONG_TEST_DATA[song_file]['verses']
song_book_name = SONG_TEST_DATA[song_file]['song_book_name']
song_number = SONG_TEST_DATA[song_file]['song_number']
song_authors = SONG_TEST_DATA[song_file]['authors']
# THEN: do_import should return none, the song data should be as expected, and finish should have been
# called.
@ -148,11 +150,14 @@ class TestSongBeamerImport(TestCase):
for verse_text, verse_tag in add_verse_calls:
mocked_add_verse.assert_any_call(verse_text, verse_tag)
if song_book_name:
self.assertEqual(importer.song_book_name, song_book_name, 'song_book_name for %s should be "%s"' %
(song_file, song_book_name))
self.assertEqual(importer.song_book_name, song_book_name,
'song_book_name for %s should be "%s"' % (song_file, song_book_name))
if song_number:
self.assertEqual(importer.song_number, song_number, 'song_number for %s should be %s' %
(song_file, song_number))
self.assertEqual(importer.song_number, song_number,
'song_number for %s should be %s' % (song_file, song_number))
if song_authors:
for author in importer.authors:
self.assertIn(author, song_authors)
mocked_finish.assert_called_with()
def check_verse_marks_test(self):

View File

@ -116,24 +116,24 @@ class SongImportTestHelper(TestCase):
if song_copyright:
self.mocked_add_copyright.assert_called_with(song_copyright)
if ccli_number:
self.assertEqual(importer.ccli_number, ccli_number, 'ccli_number for %s should be %s' %
(source_file_name, ccli_number))
self.assertEqual(importer.ccli_number, ccli_number,
'ccli_number for %s should be %s' % (source_file_name, ccli_number))
for verse_text, verse_tag in add_verse_calls:
self.mocked_add_verse.assert_any_call(verse_text, verse_tag)
if topics:
self.assertEqual(importer.topics, topics, 'topics for %s should be %s' % (source_file_name, topics))
if comments:
self.assertEqual(importer.comments, comments, 'comments for %s should be "%s"' %
(source_file_name, comments))
self.assertEqual(importer.comments, comments,
'comments for %s should be "%s"' % (source_file_name, comments))
if song_book_name:
self.assertEqual(importer.song_book_name, song_book_name, 'song_book_name for %s should be "%s"' %
(source_file_name, song_book_name))
self.assertEqual(importer.song_book_name, song_book_name,
'song_book_name for %s should be "%s"' % (source_file_name, song_book_name))
if song_number:
self.assertEqual(importer.song_number, song_number, 'song_number for %s should be %s' %
(source_file_name, song_number))
self.assertEqual(importer.song_number, song_number,
'song_number for %s should be %s' % (source_file_name, song_number))
if verse_order_list:
self.assertEqual(importer.verse_order_list, [], 'verse_order_list for %s should be %s' %
(source_file_name, verse_order_list))
self.assertEqual(importer.verse_order_list, [],
'verse_order_list for %s should be %s' % (source_file_name, verse_order_list))
self.mocked_finish.assert_called_with()
def _get_data(self, data, key):

View File

@ -103,5 +103,5 @@ class TestBibleManager(TestCase, TestMixin):
# WHEN asking to parse the bible reference
results = parse_reference('1 Timothy 1:1-2:1', self.manager.db_cache['tests'], MagicMock(), 54)
# THEN a verse array should be returned
self.assertEqual([(54, 1, 1, -1), (54, 2, 1, 1)], results, "The bible verses should matches the expected "
"results")
self.assertEqual([(54, 1, 1, -1), (54, 2, 1, 1)], results,
"The bible verses should match the expected results")

View File

@ -1,5 +1,7 @@
#LangCount=1
#Title=GL 1 - Lobsinget dem Herrn
#Author=Carl Brockhaus
#Melody=Johann Jakob Vetter
#Editor=SongBeamer 4.20
#Version=3
#Format=F/K//