From 0d2745a1d18f278d9a1d1998497b587815f7c535 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Tue, 7 Jun 2016 09:35:06 +0200 Subject: [PATCH] Fix bug #1589815 by first reducing the string to digits only and then checking if there's anything left. --- .../plugins/songs/lib/importers/opensong.py | 2 +- .../songs/test_opensongimport.py | 6 +- tests/helpers/songfileimport.py | 3 +- tests/resources/opensongsongs/Amazing Grace | 2 +- .../opensongsongs/Amazing Grace with bad CCLI | 56 +++++++++++++++++++ .../Amazing Grace without CCLI.json | 42 ++++++++++++++ 6 files changed, 106 insertions(+), 5 deletions(-) create mode 100644 tests/resources/opensongsongs/Amazing Grace with bad CCLI create mode 100644 tests/resources/opensongsongs/Amazing Grace without CCLI.json diff --git a/openlp/plugins/songs/lib/importers/opensong.py b/openlp/plugins/songs/lib/importers/opensong.py index a1bfacbcb..161f8cd68 100644 --- a/openlp/plugins/songs/lib/importers/opensong.py +++ b/openlp/plugins/songs/lib/importers/opensong.py @@ -156,8 +156,8 @@ class OpenSongImport(SongImport): ustring = str(root.__getattr__(attr)) if isinstance(fn_or_string, str): if attr in ['ccli']: + ustring = ''.join(re.findall('\d+', ustring)) if ustring: - ustring = ''.join(re.findall('\d+', ustring)) setattr(self, fn_or_string, int(ustring)) else: setattr(self, fn_or_string, None) diff --git a/tests/functional/openlp_plugins/songs/test_opensongimport.py b/tests/functional/openlp_plugins/songs/test_opensongimport.py index 7d51527b8..d1386005f 100644 --- a/tests/functional/openlp_plugins/songs/test_opensongimport.py +++ b/tests/functional/openlp_plugins/songs/test_opensongimport.py @@ -22,13 +22,13 @@ """ This module contains tests for the OpenSong song importer. """ - import os from unittest import TestCase -from tests.helpers.songfileimport import SongImportTestHelper from openlp.plugins.songs.lib.importers.opensong import OpenSongImport from openlp.core.common import Registry + +from tests.helpers.songfileimport import SongImportTestHelper from tests.functional import patch, MagicMock TEST_PATH = os.path.abspath( @@ -54,6 +54,8 @@ class TestOpenSongFileImport(SongImportTestHelper): self.load_external_result_data(os.path.join(TEST_PATH, 'One, Two, Three, Four, Five.json'))) self.file_import([os.path.join(TEST_PATH, 'Amazing Grace2')], self.load_external_result_data(os.path.join(TEST_PATH, 'Amazing Grace.json'))) + self.file_import([os.path.join(TEST_PATH, 'Amazing Grace with bad CCLI')], + self.load_external_result_data(os.path.join(TEST_PATH, 'Amazing Grace without CCLI.json'))) class TestOpenSongImport(TestCase): diff --git a/tests/helpers/songfileimport.py b/tests/helpers/songfileimport.py index bc4ebc9b5..9a9ab7d2b 100644 --- a/tests/helpers/songfileimport.py +++ b/tests/helpers/songfileimport.py @@ -29,6 +29,7 @@ from unittest import TestCase from openlp.plugins.songs.lib.importers.opensong import OpenSongImport from openlp.core.common import Registry + from tests.functional import patch, MagicMock, call log = logging.getLogger(__name__) @@ -36,7 +37,7 @@ log = logging.getLogger(__name__) class SongImportTestHelper(TestCase): """ - This class is designed to be a helper class to reduce repition when testing the import of song files. + This class is designed to be a helper class to reduce repetition when testing the import of song files. """ def __init__(self, *args, **kwargs): super(SongImportTestHelper, self).__init__(*args, **kwargs) diff --git a/tests/resources/opensongsongs/Amazing Grace b/tests/resources/opensongsongs/Amazing Grace index 97062dc21..6b2c172b5 100644 --- a/tests/resources/opensongsongs/Amazing Grace +++ b/tests/resources/opensongsongs/Amazing Grace @@ -53,4 +53,4 @@ - \ No newline at end of file + diff --git a/tests/resources/opensongsongs/Amazing Grace with bad CCLI b/tests/resources/opensongsongs/Amazing Grace with bad CCLI new file mode 100644 index 000000000..292d4a825 --- /dev/null +++ b/tests/resources/opensongsongs/Amazing Grace with bad CCLI @@ -0,0 +1,56 @@ + + + Amazing Grace (Demonstration) + John Newton, Edwin Excell & John P. Rees + Public Domain + V1 V2 V3 V4 V5 + + + GE + God: Assurance/Grace/Salvation + Worship: Praise + + + + [V] +;Test the chords format +;Chords beging with . +;Verses begin with their verse number +;Link words with _ +;Comments begin with ; +. D D7 G D +1A______ma________zing grace! How sweet the sound! +2'Twas grace that taught my heart to fear, +3The Lord has pro____mised good to me, +4Thro' ma________ny dan____gers, toils and snares +5When we've been there ten thou__sand years, + +. Bm E A A7 +1That saved a wretch like me! +2And grace my fears re___lieved. +3His Word my hope se___cures. +4I have al___rea____dy come. +5Bright shi___ning as the sun, + +. D D7 G D +1I once was lost, but now am found; +2How pre___cious did that grace ap____pear, +3He will my shield and por___tion be +4'Tis grace that brought me safe thus far, +5We've no less days to sing God's praise, + +. Bm A G D +1Was blind, but now I see. +2The hour I first be_lieved. +3As long as life en_dures. +4And grace will lead me home. +5Than when we first be_gun. + + + Demonstration Songs 0 + + + + + + diff --git a/tests/resources/opensongsongs/Amazing Grace without CCLI.json b/tests/resources/opensongsongs/Amazing Grace without CCLI.json new file mode 100644 index 000000000..799fd33d9 --- /dev/null +++ b/tests/resources/opensongsongs/Amazing Grace without CCLI.json @@ -0,0 +1,42 @@ +{ + "authors": [ + "John Newton", + "Edwin Excell", + "John P. Rees" + ], + "ccli_number": null, + "comments": "\n\n\n", + "copyright": "Public Domain ", + "song_book_name": "Demonstration Songs", + "song_number": 0, + "title": "Amazing Grace (Demonstration)", + "topics": [ + "Assurance", + "Grace", + "Praise", + "Salvation" + ], + "verse_order_list": [], + "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" + ], + [ + "The Lord has promised good to me,\nHis Word my hope secures.\nHe will my shield and portion be\nAs long as life endures.", + "v3" + ], + [ + "Thro' many dangers, toils and snares\nI have already come.\n'Tis grace that brought me safe thus far,\nAnd grace will lead me home.", + "v4" + ], + [ + "When we've been there ten thousand years,\nBright shining as the sun,\nWe've no less days to sing God's praise,\nThan when we first begun.", + "v5" + ] + ] +}