From 029381513568a420c6e56071bc565ff18244e17c Mon Sep 17 00:00:00 2001 From: Stefan Strasser Date: Sun, 13 Apr 2014 19:08:38 +0200 Subject: [PATCH] Songbeamer-import: added check_verse_marks_test to test the correct detection of different lines that may occur --- .../songs/test_songbeamerimport.py | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/tests/functional/openlp_plugins/songs/test_songbeamerimport.py b/tests/functional/openlp_plugins/songs/test_songbeamerimport.py index e7bd891d3..dbf72b068 100644 --- a/tests/functional/openlp_plugins/songs/test_songbeamerimport.py +++ b/tests/functional/openlp_plugins/songs/test_songbeamerimport.py @@ -35,6 +35,7 @@ from unittest import TestCase from tests.functional import MagicMock, patch from openlp.plugins.songs.lib.songbeamerimport import SongBeamerImport +from openlp.plugins.songs.lib import VerseType TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..', 'resources', 'songbeamersongs')) @@ -153,3 +154,80 @@ class TestSongBeamerImport(TestCase): self.assertEquals(importer.song_number, song_number, 'song_number for %s should be %s' % (song_file, song_number)) mocked_finish.assert_called_with() + + def check_verse_marks_test(self): + """ + Tests different lines to see if a verse mark is detected or not + """ + + # GIVEN: line with unnumbered verse-type + 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 + assert result is True, u'Versemark for should be found, value true' + assert self.current_verse_type == 'c', u' should be interpreted as ' + + # GIVEN: line with unnumbered verse-type and trailing space + 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 + assert result is True, u'Versemark for should be found, value true' + assert self.current_verse_type == 'c', u' should be interpreted as ' + + # GIVEN: line with numbered verse-type + 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 + assert result is True, u'Versemark for should be found, value true' + assert 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' + 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 o as self.current_verse_type + assert result is True, u'Versemark for <$$M=special> should be found, value true' + assert self.current_verse_type == 'o', u'<$$M=special> should be interpreted as ' + + # GIVEN: line with song-text with 3 words + line = 'Jesus my saviour' + 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 false and none as self.current_verse_type + assert result is False, u'No versemark for should be found, value false' + assert self.current_verse_type is None, u' should be interpreted as none versemark' + + # GIVEN: line with song-text with 2 words + line = 'Praise him' + 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 false and none as self.current_verse_type + assert result is False, u'No versemark for should be found, value false' + assert self.current_verse_type is None, u' should be interpreted as none versemark' + + # GIVEN: line with only a space (could occur, nothing regular) + line = ' ' + 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 false and none as self.current_verse_type + assert result is False, u'No versemark for < > should be found, value false' + assert self.current_verse_type is None, u'< > should be interpreted as none versemark' + + # GIVEN: blank line (could occur, nothing regular) + line = '' + 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 false and none as self.current_verse_type + assert result is False, u'No versemark for <> should be found, value false' + assert self.current_verse_type is None, u'<> should be interpreted as none versemark'