Fix for easyslide importer and added test.

This commit is contained in:
Tomas Groth 2016-01-08 22:42:36 +01:00
parent 211f93a921
commit b5270b48a9
5 changed files with 139 additions and 12 deletions

View File

@ -65,7 +65,8 @@ class EasySlidesImport(SongImport):
self._add_unicode_attribute('song_number', song.SongNumber) self._add_unicode_attribute('song_number', song.SongNumber)
if self.song_number == '0': if self.song_number == '0':
self.song_number = '' self.song_number = ''
self._add_authors(song) if hasattr(song, 'Writer'):
self._add_authors(song.Writer)
if hasattr(song, 'Copyright'): if hasattr(song, 'Copyright'):
self._add_copyright(song.Copyright) self._add_copyright(song.Copyright)
if hasattr(song, 'LicenceAdmin1'): if hasattr(song, 'LicenceAdmin1'):
@ -102,15 +103,13 @@ class EasySlidesImport(SongImport):
if mandatory: if mandatory:
self._success = False self._success = False
def _add_authors(self, song): def _add_authors(self, writer):
try: try:
authors = str(song.Writer).split(',') self.parse_author(str(writer))
self.authors = [author.strip() for author in authors if author.strip()] except UnicodeDecodeError as e:
except UnicodeDecodeError: print(e)
log.exception('Unicode decode error while decoding Writer') log.exception('Unicode decode error while decoding Writer')
self._success = False self._success = False
except AttributeError:
pass
def _add_copyright(self, element): def _add_copyright(self, element):
""" """
@ -234,11 +233,10 @@ class EasySlidesImport(SongImport):
for [reg, vt, vn, inst] in our_verse_order: for [reg, vt, vn, inst] in our_verse_order:
if self._list_has(verses, [reg, vt, vn, inst]): if self._list_has(verses, [reg, vt, vn, inst]):
# this is false, but needs user input # this is false, but needs user input
lang = None
versetag = '%s%s' % (vt, vn) versetag = '%s%s' % (vt, vn)
versetags.append(versetag) versetags.append(versetag)
lines = '\n'.join(verses[reg][vt][vn][inst]) lines = '\n'.join(verses[reg][vt][vn][inst])
self.verses.append([versetag, lines, lang]) self.add_verse(lines, versetag)
SeqTypes = { SeqTypes = {
'p': 'P1', 'p': 'P1',
'q': 'P2', 'q': 'P2',

View File

@ -0,0 +1,45 @@
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
# Copyright (c) 2008-2016 OpenLP Developers #
# --------------------------------------------------------------------------- #
# This program is free software; you can redistribute it and/or modify it #
# under the terms of the GNU General Public License as published by the Free #
# Software Foundation; version 2 of the License. #
# #
# This program is distributed in the hope that it will be useful, but WITHOUT #
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
# more details. #
# #
# You should have received a copy of the GNU General Public License along #
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
###############################################################################
"""
This module contains tests for the EasySlides song importer.
"""
import os
from tests.helpers.songfileimport import SongImportTestHelper
TEST_PATH = os.path.abspath(
os.path.join(os.path.dirname(__file__), '..', '..', '..', 'resources', 'easyslidessongs'))
class TestEasySlidesFileImport(SongImportTestHelper):
def __init__(self, *args, **kwargs):
self.importer_class_name = 'EasySlidesImport'
self.importer_module_name = 'easyslides'
super(TestEasySlidesFileImport, self).__init__(*args, **kwargs)
def test_song_import(self):
"""
Test that loading an EasySlides file works correctly on various files
"""
self.file_import(os.path.join(TEST_PATH, 'amazing-grace.xml'),
self.load_external_result_data(os.path.join(TEST_PATH, 'Amazing Grace.json')))

View File

@ -23,7 +23,6 @@ This module contains tests for the VideoPsalm song importer.
""" """
import os import os
from unittest import TestCase
from tests.helpers.songfileimport import SongImportTestHelper from tests.helpers.songfileimport import SongImportTestHelper
from tests.functional import patch from tests.functional import patch
@ -46,7 +45,7 @@ class TestSundayPlusFileImport(SongImportTestHelper):
with patch('openlp.plugins.songs.lib.importers.sundayplus.retrieve_windows_encoding') as \ with patch('openlp.plugins.songs.lib.importers.sundayplus.retrieve_windows_encoding') as \
mocked_retrieve_windows_encoding: mocked_retrieve_windows_encoding:
mocked_retrieve_windows_encoding.return_value = 'cp1252' mocked_retrieve_windows_encoding.return_value = 'cp1252'
#self.file_import([os.path.join(TEST_PATH, 'Abba Fader.ptf')], self.file_import([os.path.join(TEST_PATH, 'Abba Fader.ptf')],
# self.load_external_result_data(os.path.join(TEST_PATH, 'abba-fader.json'))) self.load_external_result_data(os.path.join(TEST_PATH, 'abba-fader.json')))
self.file_import([os.path.join(TEST_PATH, 'Amazing Grace.ptf')], self.file_import([os.path.join(TEST_PATH, 'Amazing Grace.ptf')],
self.load_external_result_data(os.path.join(TEST_PATH, 'Amazing Grace.json'))) self.load_external_result_data(os.path.join(TEST_PATH, 'Amazing Grace.json')))

View File

@ -0,0 +1,32 @@
{
"title": "Amazing Grace",
"authors": [
"John Newton (1725-1807)"
],
"verses": [
[
"Amazing grace! How sweet the sound\nThat saved a wretch like me;\nI once was lost, but now am found,\nWas blind, but now I see.",
"V1"
],
[
"'Twas grace that taught my heart to fear,\nAnd grace my fears relieved;\nHow precious did that grace appear,\nThe hour I first believed!",
"V2"
],
[
"Through many dangers, toils and snares\nI have already come;\n'Tis grace that brought me safe thus far,\nAnd grace will lead me home.",
"V3"
],
[
"The Lord has promised good to me,\nHis word my hope secures;\nHe will my shield and portion be\nAs long as life endures.",
"V4"
],
[
"Yes, when this heart and flesh shall fail,\nAnd mortal life shall cease,\nI shall possess within the veil\nA life of joy and peace.",
"V5"
],
[
"When we've been there a thousand years,\nBright shining as the sun,\nWe've no less days to sing God's praise\nThan when we first begun.",
"V6"
]
]
}

View File

@ -0,0 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<EasiSlides>
<Item>
<Title1>Amazing Grace</Title1>
<Title2 />
<Folder>English</Folder>
<SongNumber>0</SongNumber>
<Contents>[1]
Amazing grace! How sweet the sound
That saved a wretch like me;
I once was lost, but now am found,
Was blind, but now I see.
[2]
'Twas grace that taught my heart to fear,
And grace my fears relieved;
How precious did that grace appear,
The hour I first believed!
[3]
Through many dangers, toils and snares
I have already come;
'Tis grace that brought me safe thus far,
And grace will lead me home.
[4]
The Lord has promised good to me,
His word my hope secures;
He will my shield and portion be
As long as life endures.
[5]
Yes, when this heart and flesh shall fail,
And mortal life shall cease,
I shall possess within the veil
A life of joy and peace.
[6]
When we've been there a thousand years,
Bright shining as the sun,
We've no less days to sing God's praise
Than when we first begun.</Contents>
<Notations />
<Sequence />
<Writer>John Newton (1725-1807)</Writer>
<Copyright />
<Category />
<Timing />
<MusicKey />
<Capo>-1</Capo>
<LicenceAdmin1>Public Domain</LicenceAdmin1>
<LicenceAdmin2 />
<BookReference>SF19, MP31, TS18</BookReference>
<UserReference />
<FormatData />
<Settings />
</Item>
</EasiSlides>