diff --git a/openlp/plugins/songs/lib/importers/easyslides.py b/openlp/plugins/songs/lib/importers/easyslides.py index 119cb91dc..b7afeef9e 100644 --- a/openlp/plugins/songs/lib/importers/easyslides.py +++ b/openlp/plugins/songs/lib/importers/easyslides.py @@ -65,7 +65,8 @@ class EasySlidesImport(SongImport): self._add_unicode_attribute('song_number', song.SongNumber) if self.song_number == '0': self.song_number = '' - self._add_authors(song) + if hasattr(song, 'Writer'): + self._add_authors(song.Writer) if hasattr(song, 'Copyright'): self._add_copyright(song.Copyright) if hasattr(song, 'LicenceAdmin1'): @@ -102,15 +103,13 @@ class EasySlidesImport(SongImport): if mandatory: self._success = False - def _add_authors(self, song): + def _add_authors(self, writer): try: - authors = str(song.Writer).split(',') - self.authors = [author.strip() for author in authors if author.strip()] - except UnicodeDecodeError: + self.parse_author(str(writer)) + except UnicodeDecodeError as e: + print(e) log.exception('Unicode decode error while decoding Writer') self._success = False - except AttributeError: - pass def _add_copyright(self, element): """ @@ -234,11 +233,10 @@ class EasySlidesImport(SongImport): for [reg, vt, vn, inst] in our_verse_order: if self._list_has(verses, [reg, vt, vn, inst]): # this is false, but needs user input - lang = None versetag = '%s%s' % (vt, vn) versetags.append(versetag) lines = '\n'.join(verses[reg][vt][vn][inst]) - self.verses.append([versetag, lines, lang]) + self.add_verse(lines, versetag) SeqTypes = { 'p': 'P1', 'q': 'P2', diff --git a/tests/functional/openlp_plugins/songs/test_easyslidesimport.py b/tests/functional/openlp_plugins/songs/test_easyslidesimport.py new file mode 100644 index 000000000..fa2391bbb --- /dev/null +++ b/tests/functional/openlp_plugins/songs/test_easyslidesimport.py @@ -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'))) diff --git a/tests/functional/openlp_plugins/songs/test_sundayplusimport.py b/tests/functional/openlp_plugins/songs/test_sundayplusimport.py index 45dc68caf..17a00f819 100644 --- a/tests/functional/openlp_plugins/songs/test_sundayplusimport.py +++ b/tests/functional/openlp_plugins/songs/test_sundayplusimport.py @@ -23,7 +23,6 @@ This module contains tests for the VideoPsalm song importer. """ import os -from unittest import TestCase from tests.helpers.songfileimport import SongImportTestHelper from tests.functional import patch @@ -46,7 +45,7 @@ class TestSundayPlusFileImport(SongImportTestHelper): with patch('openlp.plugins.songs.lib.importers.sundayplus.retrieve_windows_encoding') as \ mocked_retrieve_windows_encoding: mocked_retrieve_windows_encoding.return_value = 'cp1252' - #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.file_import([os.path.join(TEST_PATH, 'Abba Fader.ptf')], + 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.load_external_result_data(os.path.join(TEST_PATH, 'Amazing Grace.json'))) diff --git a/tests/resources/easyslidessongs/Amazing Grace.json b/tests/resources/easyslidessongs/Amazing Grace.json new file mode 100644 index 000000000..10579e652 --- /dev/null +++ b/tests/resources/easyslidessongs/Amazing Grace.json @@ -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" + ] + ] +} diff --git a/tests/resources/easyslidessongs/amazing-grace.xml b/tests/resources/easyslidessongs/amazing-grace.xml new file mode 100644 index 000000000..209fe1fc6 --- /dev/null +++ b/tests/resources/easyslidessongs/amazing-grace.xml @@ -0,0 +1,53 @@ + + + + Amazing Grace + + English + 0 + [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. + + + John Newton (1725-1807) + + + + + -1 + Public Domain + + SF19, MP31, TS18 + + + + +