2013-10-22 15:09:10 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2013-10-26 17:25:07 +00:00
|
|
|
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
|
2013-10-22 15:09:10 +00:00
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
# OpenLP - Open Source Lyrics Projection #
|
|
|
|
# --------------------------------------------------------------------------- #
|
2016-12-31 11:01:36 +00:00
|
|
|
# Copyright (c) 2008-2017 OpenLP Developers #
|
2013-10-22 15:09:10 +00:00
|
|
|
# --------------------------------------------------------------------------- #
|
|
|
|
# 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 #
|
|
|
|
###############################################################################
|
2013-10-06 22:07:49 +00:00
|
|
|
"""
|
|
|
|
This module contains tests for the Songbeamer song importer.
|
|
|
|
"""
|
|
|
|
|
|
|
|
import os
|
|
|
|
from unittest import TestCase
|
|
|
|
|
2015-12-20 16:46:39 +00:00
|
|
|
from tests.helpers.songfileimport import SongImportTestHelper
|
2013-10-22 15:09:10 +00:00
|
|
|
from tests.functional import MagicMock, patch
|
2016-01-10 00:34:53 +00:00
|
|
|
from openlp.plugins.songs.lib.importers.songbeamer import SongBeamerImport, SongBeamerTypes
|
2014-09-25 14:59:56 +00:00
|
|
|
from openlp.core.common import Registry
|
2013-10-06 22:07:49 +00:00
|
|
|
|
2013-10-22 15:09:10 +00:00
|
|
|
TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__),
|
|
|
|
'..', '..', '..', 'resources', 'songbeamersongs'))
|
2015-12-20 16:46:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestSongBeamerFileImport(SongImportTestHelper):
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
self.importer_class_name = 'SongBeamerImport'
|
|
|
|
self.importer_module_name = 'songbeamer'
|
|
|
|
super(TestSongBeamerFileImport, self).__init__(*args, **kwargs)
|
|
|
|
|
|
|
|
def test_song_import(self):
|
|
|
|
"""
|
|
|
|
Test that loading an OpenSong file works correctly on various files
|
|
|
|
"""
|
|
|
|
self.file_import([os.path.join(TEST_PATH, 'Lobsinget dem Herrn.sng')],
|
|
|
|
self.load_external_result_data(os.path.join(TEST_PATH, 'Lobsinget dem Herrn.json')))
|
2014-02-27 21:36:33 +00:00
|
|
|
|
2013-10-06 22:07:49 +00:00
|
|
|
|
|
|
|
class TestSongBeamerImport(TestCase):
|
|
|
|
"""
|
|
|
|
Test the functions in the :mod:`songbeamerimport` module.
|
|
|
|
"""
|
2014-09-25 14:59:56 +00:00
|
|
|
def setUp(self):
|
|
|
|
"""
|
|
|
|
Create the registry
|
|
|
|
"""
|
|
|
|
Registry.create()
|
|
|
|
|
2016-05-31 21:40:13 +00:00
|
|
|
def test_create_importer(self):
|
2013-10-06 22:07:49 +00:00
|
|
|
"""
|
|
|
|
Test creating an instance of the SongBeamer file importer
|
|
|
|
"""
|
|
|
|
# GIVEN: A mocked out SongImport class, and a mocked out "manager"
|
2014-07-04 09:31:06 +00:00
|
|
|
with patch('openlp.plugins.songs.lib.importers.songbeamer.SongImport'):
|
2013-10-06 22:07:49 +00:00
|
|
|
mocked_manager = MagicMock()
|
|
|
|
|
|
|
|
# WHEN: An importer object is created
|
2014-03-29 13:31:28 +00:00
|
|
|
importer = SongBeamerImport(mocked_manager, filenames=[])
|
2013-10-06 22:07:49 +00:00
|
|
|
|
|
|
|
# THEN: The importer object should not be None
|
|
|
|
self.assertIsNotNone(importer, 'Import should not be none')
|
|
|
|
|
2016-05-31 21:40:13 +00:00
|
|
|
def test_invalid_import_source(self):
|
2013-10-06 22:07:49 +00:00
|
|
|
"""
|
2014-03-06 20:40:08 +00:00
|
|
|
Test SongBeamerImport.do_import handles different invalid import_source values
|
2013-10-06 22:07:49 +00:00
|
|
|
"""
|
|
|
|
# GIVEN: A mocked out SongImport class, and a mocked out "manager"
|
2014-07-04 09:31:06 +00:00
|
|
|
with patch('openlp.plugins.songs.lib.importers.songbeamer.SongImport'):
|
2013-10-06 22:07:49 +00:00
|
|
|
mocked_manager = MagicMock()
|
|
|
|
mocked_import_wizard = MagicMock()
|
2014-03-29 13:31:28 +00:00
|
|
|
importer = SongBeamerImport(mocked_manager, filenames=[])
|
2013-10-06 22:07:49 +00:00
|
|
|
importer.import_wizard = mocked_import_wizard
|
|
|
|
importer.stop_import_flag = True
|
|
|
|
|
|
|
|
# WHEN: Import source is not a list
|
|
|
|
for source in ['not a list', 0]:
|
|
|
|
importer.import_source = source
|
|
|
|
|
2014-03-06 20:40:08 +00:00
|
|
|
# THEN: do_import should return none and the progress bar maximum should not be set.
|
|
|
|
self.assertIsNone(importer.do_import(), 'do_import should return None when import_source is not a list')
|
2014-04-14 18:33:34 +00:00
|
|
|
self.assertEqual(mocked_import_wizard.progress_bar.setMaximum.called, False,
|
2014-04-16 19:56:54 +00:00
|
|
|
'setMaxium on import_wizard.progress_bar should not have been called')
|
2013-10-06 22:07:49 +00:00
|
|
|
|
2016-05-31 21:40:13 +00:00
|
|
|
def test_valid_import_source(self):
|
2013-10-06 22:07:49 +00:00
|
|
|
"""
|
2014-03-06 20:40:08 +00:00
|
|
|
Test SongBeamerImport.do_import handles different invalid import_source values
|
2013-10-06 22:07:49 +00:00
|
|
|
"""
|
|
|
|
# GIVEN: A mocked out SongImport class, and a mocked out "manager"
|
2014-07-04 09:31:06 +00:00
|
|
|
with patch('openlp.plugins.songs.lib.importers.songbeamer.SongImport'):
|
2013-10-06 22:07:49 +00:00
|
|
|
mocked_manager = MagicMock()
|
|
|
|
mocked_import_wizard = MagicMock()
|
2014-03-29 13:31:28 +00:00
|
|
|
importer = SongBeamerImport(mocked_manager, filenames=[])
|
2013-10-06 22:07:49 +00:00
|
|
|
importer.import_wizard = mocked_import_wizard
|
|
|
|
importer.stop_import_flag = True
|
|
|
|
|
|
|
|
# WHEN: Import source is a list
|
|
|
|
importer.import_source = ['List', 'of', 'files']
|
|
|
|
|
2014-03-06 20:40:08 +00:00
|
|
|
# THEN: do_import should return none and the progress bar setMaximum should be called with the length of
|
2013-10-06 22:07:49 +00:00
|
|
|
# import_source.
|
2014-03-06 20:40:08 +00:00
|
|
|
self.assertIsNone(importer.do_import(),
|
2014-04-02 19:35:09 +00:00
|
|
|
'do_import should return None when import_source is a list and stop_import_flag is True')
|
2013-10-06 22:07:49 +00:00
|
|
|
mocked_import_wizard.progress_bar.setMaximum.assert_called_with(len(importer.import_source))
|
|
|
|
|
2016-05-31 21:40:13 +00:00
|
|
|
def test_check_verse_marks(self):
|
2014-04-13 17:08:38 +00:00
|
|
|
"""
|
|
|
|
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
|
2014-04-14 18:33:34 +00:00
|
|
|
self.assertTrue(result, 'Versemark for <Refrain> should be found, value true')
|
|
|
|
self.assertEqual(self.current_verse_type, 'c', '<Refrain> should be interpreted as <c>')
|
2014-04-13 17:08:38 +00:00
|
|
|
|
|
|
|
# GIVEN: line with unnumbered verse-type and trailing space
|
2016-01-10 00:34:53 +00:00
|
|
|
line = 'ReFrain '
|
2014-04-13 17:08:38 +00:00
|
|
|
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
|
2016-01-10 00:34:53 +00:00
|
|
|
self.assertTrue(result, 'Versemark for <ReFrain > should be found, value true')
|
|
|
|
self.assertEqual(self.current_verse_type, 'c', '<ReFrain > should be interpreted as <c>')
|
2014-04-13 17:08:38 +00:00
|
|
|
|
|
|
|
# GIVEN: line with numbered verse-type
|
2016-01-10 00:34:53 +00:00
|
|
|
line = 'VersE 1'
|
2014-04-13 17:08:38 +00:00
|
|
|
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
|
2016-01-10 00:34:53 +00:00
|
|
|
self.assertTrue(result, 'Versemark for <VersE 1> should be found, value true')
|
|
|
|
self.assertEqual(self.current_verse_type, 'v1', u'<VersE 1> should be interpreted as <v1>')
|
2014-04-13 17:08:38 +00:00
|
|
|
|
|
|
|
# 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
|
2014-04-14 18:33:34 +00:00
|
|
|
self.assertTrue(result, 'Versemark for <$$M=special> should be found, value true')
|
|
|
|
self.assertEqual(self.current_verse_type, 'o', u'<$$M=special> should be interpreted as <o>')
|
2014-04-13 17:08:38 +00:00
|
|
|
|
|
|
|
# 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
|
2014-04-14 18:33:34 +00:00
|
|
|
self.assertFalse(result, 'No versemark for <Jesus my saviour> should be found, value false')
|
|
|
|
self.assertIsNone(self.current_verse_type, '<Jesus my saviour> should be interpreted as none versemark')
|
2014-04-13 17:08:38 +00:00
|
|
|
|
|
|
|
# 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
|
2014-04-14 18:33:34 +00:00
|
|
|
self.assertFalse(result, 'No versemark for <Praise him> should be found, value false')
|
|
|
|
self.assertIsNone(self.current_verse_type, '<Praise him> should be interpreted as none versemark')
|
2014-04-13 17:08:38 +00:00
|
|
|
|
|
|
|
# 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
|
2014-04-14 18:33:34 +00:00
|
|
|
self.assertFalse(result, 'No versemark for < > should be found, value false')
|
|
|
|
self.assertIsNone(self.current_verse_type, '< > should be interpreted as none versemark')
|
2014-04-13 17:08:38 +00:00
|
|
|
|
|
|
|
# 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
|
2014-04-14 18:33:34 +00:00
|
|
|
self.assertFalse(result, 'No versemark for <> should be found, value false')
|
|
|
|
self.assertIsNone(self.current_verse_type, '<> should be interpreted as none versemark')
|
2016-01-10 00:34:53 +00:00
|
|
|
|
|
|
|
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')
|