From 076cc57d390c7a3dfd2a598eccbc70dc502f85ce Mon Sep 17 00:00:00 2001 From: Simon Hanna Date: Sun, 10 Jan 2016 01:17:58 +0100 Subject: [PATCH 1/4] Fix Song import --- openlp/plugins/songs/lib/importer.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/openlp/plugins/songs/lib/importer.py b/openlp/plugins/songs/lib/importer.py index 545e14d60..5e099dde9 100644 --- a/openlp/plugins/songs/lib/importer.py +++ b/openlp/plugins/songs/lib/importer.py @@ -390,7 +390,7 @@ class SongFormat(object): """ Return a list of the supported song formats. """ - return [ + return sorted([ SongFormat.OpenLyrics, SongFormat.OpenLP2, SongFormat.Generic, @@ -400,6 +400,7 @@ class SongFormat(object): SongFormat.EasyWorshipDB, SongFormat.EasyWorshipService, SongFormat.FoilPresenter, + SongFormat.Lyrix, SongFormat.MediaShout, SongFormat.OpenSong, SongFormat.PowerPraise, @@ -411,13 +412,12 @@ class SongFormat(object): SongFormat.SongShowPlus, SongFormat.SongsOfFellowship, SongFormat.SundayPlus, + SongFormat.VideoPsalm, SongFormat.WordsOfWorship, SongFormat.WorshipAssistant, SongFormat.WorshipCenterPro, SongFormat.ZionWorx, - SongFormat.Lyrix, - SongFormat.VideoPsalm - ] + ]) @staticmethod def get(song_format, *attributes): From 70e1f3926b5717d5b941dd558b4310348d47815a Mon Sep 17 00:00:00 2001 From: Simon Hanna Date: Sun, 10 Jan 2016 01:18:27 +0100 Subject: [PATCH 2/4] Add test for fix --- tests/functional/openlp_plugins/songs/test_songformat.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/functional/openlp_plugins/songs/test_songformat.py b/tests/functional/openlp_plugins/songs/test_songformat.py index 0c82b049c..3611bf749 100644 --- a/tests/functional/openlp_plugins/songs/test_songformat.py +++ b/tests/functional/openlp_plugins/songs/test_songformat.py @@ -81,3 +81,11 @@ class TestSongFormat(TestCase): # THEN: Return all attributes that were specified self.assertEquals(len(SongFormat.get(song_format, 'canDisable', 'availability')), 2, "Did not return the correct number of attributes when retrieving multiple attributes at once") + + def test_get_format_list_returns_ordered_list(self): + """ + Test that get_format_list() returns a list that is ordered + according to the order specified in SongFormat + """ + self.assertEquals(sorted(SongFormat.get_format_list()), SongFormat.get_format_list(), + "The list returned should be sorted according to the ordering in SongFormat") From 9525453679b9005219d55810d7f27d69835b9a71 Mon Sep 17 00:00:00 2001 From: Simon Hanna Date: Sun, 10 Jan 2016 01:22:31 +0100 Subject: [PATCH 3/4] Ignore case when matching verse tags during SongBeamerImport --- .../plugins/songs/lib/importers/songbeamer.py | 54 +++++++++---------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/openlp/plugins/songs/lib/importers/songbeamer.py b/openlp/plugins/songs/lib/importers/songbeamer.py index 0146cb45b..71d047ab5 100644 --- a/openlp/plugins/songs/lib/importers/songbeamer.py +++ b/openlp/plugins/songs/lib/importers/songbeamer.py @@ -36,28 +36,28 @@ log = logging.getLogger(__name__) class SongBeamerTypes(object): MarkTypes = { - 'Refrain': VerseType.tags[VerseType.Chorus], - 'Chorus': VerseType.tags[VerseType.Chorus], - 'Vers': VerseType.tags[VerseType.Verse], - 'Verse': VerseType.tags[VerseType.Verse], - 'Strophe': VerseType.tags[VerseType.Verse], - 'Intro': VerseType.tags[VerseType.Intro], - 'Coda': VerseType.tags[VerseType.Ending], - 'Ending': VerseType.tags[VerseType.Ending], - 'Bridge': VerseType.tags[VerseType.Bridge], - 'Interlude': VerseType.tags[VerseType.Bridge], - 'Zwischenspiel': VerseType.tags[VerseType.Bridge], - 'Pre-Chorus': VerseType.tags[VerseType.PreChorus], - 'Pre-Refrain': VerseType.tags[VerseType.PreChorus], - 'Misc': VerseType.tags[VerseType.Other], - 'Pre-Bridge': VerseType.tags[VerseType.Other], - 'Pre-Coda': VerseType.tags[VerseType.Other], - 'Part': VerseType.tags[VerseType.Other], - 'Teil': VerseType.tags[VerseType.Other], - 'Unbekannt': VerseType.tags[VerseType.Other], - 'Unknown': VerseType.tags[VerseType.Other], - 'Unbenannt': VerseType.tags[VerseType.Other], - '$$M=': VerseType.tags[VerseType.Other] + 'refrain': VerseType.tags[VerseType.Chorus], + 'chorus': VerseType.tags[VerseType.Chorus], + 'vers': VerseType.tags[VerseType.Verse], + 'verse': VerseType.tags[VerseType.Verse], + 'strophe': VerseType.tags[VerseType.Verse], + 'intro': VerseType.tags[VerseType.Intro], + 'coda': VerseType.tags[VerseType.Ending], + 'ending': VerseType.tags[VerseType.Ending], + 'bridge': VerseType.tags[VerseType.Bridge], + 'interlude': VerseType.tags[VerseType.Bridge], + 'zwischenspiel': VerseType.tags[VerseType.Bridge], + 'pre-chorus': VerseType.tags[VerseType.PreChorus], + 'pre-refrain': VerseType.tags[VerseType.PreChorus], + 'misc': VerseType.tags[VerseType.Other], + 'pre-bridge': VerseType.tags[VerseType.Other], + 'pre-coda': VerseType.tags[VerseType.Other], + 'part': VerseType.tags[VerseType.Other], + 'teil': VerseType.tags[VerseType.Other], + 'unbekannt': VerseType.tags[VerseType.Other], + 'unknown': VerseType.tags[VerseType.Other], + 'unbenannt': VerseType.tags[VerseType.Other], + '$$m=': VerseType.tags[VerseType.Other] } @@ -267,20 +267,20 @@ class SongBeamerImport(SongImport): def check_verse_marks(self, line): """ - Check and add the verse's MarkType. Returns ``True`` if the given linE contains a correct verse mark otherwise + Check and add the verse's MarkType. Returns ``True`` if the given line contains a correct verse mark otherwise ``False``. :param line: The line to check for marks (unicode). """ marks = line.split(' ') - if len(marks) <= 2 and marks[0] in SongBeamerTypes.MarkTypes: - self.current_verse_type = SongBeamerTypes.MarkTypes[marks[0]] + if len(marks) <= 2 and marks[0].lower() in SongBeamerTypes.MarkTypes: + self.current_verse_type = SongBeamerTypes.MarkTypes[marks[0].lower()] if len(marks) == 2: # If we have a digit, we append it to current_verse_type. if marks[1].isdigit(): self.current_verse_type += marks[1] return True - elif marks[0].startswith('$$M='): # this verse-mark cannot be numbered - self.current_verse_type = SongBeamerTypes.MarkTypes['$$M='] + elif marks[0].lower().startswith('$$m='): # this verse-mark cannot be numbered + self.current_verse_type = SongBeamerTypes.MarkTypes['$$m='] return True return False From 0f1d6718bd1c118741b7b63edb079693f2f4ee83 Mon Sep 17 00:00:00 2001 From: Simon Hanna Date: Sun, 10 Jan 2016 01:34:53 +0100 Subject: [PATCH 4/4] Add tests for ignored case --- .../songs/test_songbeamerimport.py | 23 +++++++++++++------ .../openlp_plugins/songs/test_songformat.py | 5 +++- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/tests/functional/openlp_plugins/songs/test_songbeamerimport.py b/tests/functional/openlp_plugins/songs/test_songbeamerimport.py index d4b23b207..9f20e6a08 100644 --- a/tests/functional/openlp_plugins/songs/test_songbeamerimport.py +++ b/tests/functional/openlp_plugins/songs/test_songbeamerimport.py @@ -28,7 +28,7 @@ from unittest import TestCase from tests.helpers.songfileimport import SongImportTestHelper from tests.functional import MagicMock, patch -from openlp.plugins.songs.lib.importers.songbeamer import SongBeamerImport +from openlp.plugins.songs.lib.importers.songbeamer import SongBeamerImport, SongBeamerTypes from openlp.core.common import Registry TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), @@ -131,22 +131,22 @@ class TestSongBeamerImport(TestCase): self.assertEqual(self.current_verse_type, 'c', ' should be interpreted as ') # GIVEN: line with unnumbered verse-type and trailing space - line = 'Refrain ' + line = 'ReFrain ' self.current_verse_type = None # WHEN: line is being checked for verse marks result = SongBeamerImport.check_verse_marks(self, line) # THEN: we should get back true and c as self.current_verse_type - self.assertTrue(result, 'Versemark for should be found, value true') - self.assertEqual(self.current_verse_type, 'c', ' should be interpreted as ') + self.assertTrue(result, 'Versemark for should be found, value true') + self.assertEqual(self.current_verse_type, 'c', ' should be interpreted as ') # GIVEN: line with numbered verse-type - line = 'Verse 1' + line = 'VersE 1' self.current_verse_type = None # WHEN: line is being checked for verse marks result = SongBeamerImport.check_verse_marks(self, line) # THEN: we should get back true and v1 as self.current_verse_type - self.assertTrue(result, 'Versemark for should be found, value true') - self.assertEqual(self.current_verse_type, 'v1', u' should be interpreted as ') + self.assertTrue(result, 'Versemark for should be found, value true') + self.assertEqual(self.current_verse_type, 'v1', u' should be interpreted as ') # GIVEN: line with special unnumbered verse-mark (used in Songbeamer to allow usage of non-supported tags) line = '$$M=special' @@ -192,3 +192,12 @@ class TestSongBeamerImport(TestCase): # THEN: we should get back false and none as self.current_verse_type self.assertFalse(result, 'No versemark for <> should be found, value false') self.assertIsNone(self.current_verse_type, '<> should be interpreted as none versemark') + + def test_verse_marks_defined_in_lowercase(self): + """ + Test that the verse marks are all defined in lowercase + """ + # GIVEN: SongBeamber MarkTypes + for tag in SongBeamerTypes.MarkTypes.keys(): + # THEN: tag should be defined in lowercase + self.assertEquals(tag, tag.lower(), 'Tags should be defined in lowercase') diff --git a/tests/functional/openlp_plugins/songs/test_songformat.py b/tests/functional/openlp_plugins/songs/test_songformat.py index 3611bf749..19e1470c3 100644 --- a/tests/functional/openlp_plugins/songs/test_songformat.py +++ b/tests/functional/openlp_plugins/songs/test_songformat.py @@ -87,5 +87,8 @@ class TestSongFormat(TestCase): Test that get_format_list() returns a list that is ordered according to the order specified in SongFormat """ + # GIVEN: The SongFormat class + # WHEN: Retrieving all formats + # THEN: The returned list should be sorted according to the ordering defined in SongFormat self.assertEquals(sorted(SongFormat.get_format_list()), SongFormat.get_format_list(), - "The list returned should be sorted according to the ordering in SongFormat") + "The list returned should be sorted according to the ordering in SongFormat")