openlp-core team mailing list archive
-
openlp-core team
-
Mailing list archive
-
Message #24302
[Merge] lp:~tomasgroth/openlp/bugfixes1 into lp:openlp
Tomas Groth has proposed merging lp:~tomasgroth/openlp/bugfixes1 into lp:openlp.
Requested reviews:
OpenLP Core (openlp-core)
Related bugs:
Bug #1265368 in OpenLP: "[regression] Traceback in web remote"
https://bugs.launchpad.net/openlp/+bug/1265368
For more details, see:
https://code.launchpad.net/~tomasgroth/openlp/bugfixes1/+merge/236259
Fix for bug 1265368.
Fix tests so they can run individually.
Fix for importing custom tags from openlyricsxml.
--
https://code.launchpad.net/~tomasgroth/openlp/bugfixes1/+merge/236259
Your team OpenLP Core is requested to review the proposed merge of lp:~tomasgroth/openlp/bugfixes1 into lp:openlp.
=== modified file 'openlp/core/ui/slidecontroller.py'
--- openlp/core/ui/slidecontroller.py 2014-07-12 23:47:53 +0000
+++ openlp/core/ui/slidecontroller.py 2014-09-28 15:49:42 +0000
@@ -374,7 +374,8 @@
triggers=self._slide_shortcut_activated) for s in shortcuts])
self.shortcut_timer.timeout.connect(self._slide_shortcut_activated)
# Signals
- self.preview_widget.itemSelectionChanged.connect(self.on_slide_selected)
+ self.preview_widget.clicked.connect(self.on_slide_selected)
+ self.preview_widget.verticalHeader().sectionClicked.connect(self.on_slide_selected)
if self.is_live:
# Need to use event as called across threads and UI is updated
QtCore.QObject.connect(self, QtCore.SIGNAL('slidecontroller_toggle_display'), self.toggle_display)
=== modified file 'openlp/plugins/songs/lib/openlyricsxml.py'
--- openlp/plugins/songs/lib/openlyricsxml.py 2014-07-03 16:54:51 +0000
+++ openlp/plugins/songs/lib/openlyricsxml.py 2014-09-28 15:49:42 +0000
@@ -239,6 +239,7 @@
def __init__(self, manager):
self.manager = manager
+ FormattingTags.load_tags()
def song_to_xml(self, song):
"""
@@ -582,18 +583,20 @@
# Some tags have only start html e.g. {br}
'end html': tag.close.text if hasattr(tag, 'close') else '',
'protected': False,
+ # Add 'temporary' key in case the formatting tag should not be saved otherwise it is supposed that
+ # formatting tag is permanent.
+ 'temporary': temporary
}
- # Add 'temporary' key in case the formatting tag should not be saved otherwise it is supposed that
- # formatting tag is permanent.
- if temporary:
- openlp_tag['temporary'] = temporary
found_tags.append(openlp_tag)
existing_tag_ids = [tag['start tag'] for tag in FormattingTags.get_html_tags()]
new_tags = [tag for tag in found_tags if tag['start tag'] not in existing_tag_ids]
# Do not save an empty list.
if new_tags:
FormattingTags.add_html_tags(new_tags)
- FormattingTags.save_html_tags()
+ if not temporary:
+ custom_tags = [tag for tag in FormattingTags.get_html_tags()
+ if not tag['protected'] and not tag['temporary']]
+ FormattingTags.save_html_tags(custom_tags)
def _process_lines_mixed_content(self, element, newlines=True):
"""
=== modified file 'tests/functional/openlp_plugins/remotes/test_router.py'
--- tests/functional/openlp_plugins/remotes/test_router.py 2014-05-07 20:38:34 +0000
+++ tests/functional/openlp_plugins/remotes/test_router.py 2014-09-28 15:49:42 +0000
@@ -130,6 +130,7 @@
Test the main poll logic
"""
# GIVEN: a defined router with two slides
+ Registry.create()
Registry().register('live_controller', MagicMock)
router = HttpRouter()
router.send_response = MagicMock()
=== modified file 'tests/functional/openlp_plugins/songs/test_ewimport.py'
--- tests/functional/openlp_plugins/songs/test_ewimport.py 2014-07-04 09:31:06 +0000
+++ tests/functional/openlp_plugins/songs/test_ewimport.py 2014-09-28 15:49:42 +0000
@@ -35,6 +35,7 @@
from tests.functional import MagicMock, patch
+from openlp.core.common import Registry
from openlp.plugins.songs.lib.importers.easyworship import EasyWorshipSongImport, FieldDescEntry, FieldType
TEST_PATH = os.path.abspath(
@@ -153,6 +154,11 @@
"""
Test the functions in the :mod:`ewimport` module.
"""
+ def setUp(self):
+ """
+ Create the registry
+ """
+ Registry.create()
def create_field_desc_entry_test(self):
"""
=== modified file 'tests/functional/openlp_plugins/songs/test_openlyricsimport.py'
--- tests/functional/openlp_plugins/songs/test_openlyricsimport.py 2014-07-04 09:31:06 +0000
+++ tests/functional/openlp_plugins/songs/test_openlyricsimport.py 2014-09-28 15:49:42 +0000
@@ -31,11 +31,18 @@
"""
import os
+import json
from unittest import TestCase
+from lxml import etree, objectify
from tests.functional import MagicMock, patch
+from tests.helpers.testmixin import TestMixin
from openlp.plugins.songs.lib.importers.openlyrics import OpenLyricsImport
from openlp.plugins.songs.lib.importers.songimport import SongImport
+from openlp.plugins.songs.lib.openlyricsxml import OpenLyrics
+from openlp.core.common import Registry, Settings
+from openlp.core.lib import FormattingTags
+
TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__),
'..', '..', '..', 'resources', 'openlyricssongs'))
@@ -59,11 +66,33 @@
}
}
-
-class TestOpenLyricsImport(TestCase):
+start_tags = [{"protected": False, "desc": "z", "start tag": "{z}", "end html": "</strong>", "temporary": False,
+ "end tag": "{/z}", "start html": "strong>"}]
+result_tags = [{"temporary": False, "protected": False, "desc": "z", "start tag": "{z}", "start html": "strong>",
+ "end html": "</strong>", "end tag": "{/z}"},
+ {"temporary": False, "end tag": "{/c}", "desc": "c", "start tag": "{c}",
+ "start html": "<span class=\"chord\" style=\"display:none\"><strong>", "end html": "</strong></span>",
+ "protected": False}]
+
+
+class TestOpenLyricsImport(TestCase, TestMixin):
"""
Test the functions in the :mod:`openlyricsimport` module.
"""
+ def setUp(self):
+ """
+ Create the registry
+ """
+ self.get_application()
+ Registry.create()
+ self.build_settings()
+
+ def tearDown(self):
+ """
+ Cleanup
+ """
+ self.destroy_settings()
+
def create_importer_test(self):
"""
Test creating an instance of the OpenLyrics file importer
@@ -97,3 +126,24 @@
# THEN: The xml_to_song() method should have been called
self.assertTrue(importer.open_lyrics.xml_to_song.called)
+
+ def process_formatting_tags_test(self):
+ """
+ Test that _process_formatting_tags works
+ """
+ # GIVEN: A OpenLyric XML with formatting tags and a mocked out manager
+ mocked_manager = MagicMock()
+ Settings().setValue('formattingTags/html_tags', json.dumps(start_tags))
+ ol = OpenLyrics(mocked_manager)
+ parser = etree.XMLParser(remove_blank_text=True)
+ parsed_file = etree.parse(open(os.path.join(TEST_PATH, 'duchu-tags.xml'), 'rb'), parser)
+ xml = etree.tostring(parsed_file).decode()
+ song_xml = objectify.fromstring(xml)
+
+ # WHEN: processing the formatting tags
+ ol._process_formatting_tags(song_xml, False)
+
+ # THEN: New tags should have been saved
+ self.assertListEqual(json.loads(json.dumps(result_tags)),
+ json.loads(str(Settings().value('formattingTags/html_tags'))),
+ 'The formatting tags should contain both the old and the new')
=== modified file 'tests/functional/openlp_plugins/songs/test_opensongimport.py'
--- tests/functional/openlp_plugins/songs/test_opensongimport.py 2014-07-04 09:31:06 +0000
+++ tests/functional/openlp_plugins/songs/test_opensongimport.py 2014-09-28 15:49:42 +0000
@@ -35,6 +35,7 @@
from tests.helpers.songfileimport import SongImportTestHelper
from openlp.plugins.songs.lib.importers.opensong import OpenSongImport
+from openlp.core.common import Registry
from tests.functional import patch, MagicMock
TEST_PATH = os.path.abspath(
@@ -64,6 +65,12 @@
"""
Test the functions in the :mod:`opensongimport` module.
"""
+ def setUp(self):
+ """
+ Create the registry
+ """
+ Registry.create()
+
def create_importer_test(self):
"""
Test creating an instance of the OpenSong file importer
=== modified file 'tests/functional/openlp_plugins/songs/test_powerpraiseimport.py'
--- tests/functional/openlp_plugins/songs/test_powerpraiseimport.py 2014-08-21 12:51:34 +0000
+++ tests/functional/openlp_plugins/songs/test_powerpraiseimport.py 2014-09-28 15:49:42 +0000
@@ -34,6 +34,7 @@
import os
from tests.helpers.songfileimport import SongImportTestHelper
+from openlp.core.common import Registry
TEST_PATH = os.path.abspath(
os.path.join(os.path.dirname(__file__), '..', '..', '..', 'resources', 'powerpraisesongs'))
=== modified file 'tests/functional/openlp_plugins/songs/test_songbeamerimport.py'
--- tests/functional/openlp_plugins/songs/test_songbeamerimport.py 2014-07-04 09:31:06 +0000
+++ tests/functional/openlp_plugins/songs/test_songbeamerimport.py 2014-09-28 15:49:42 +0000
@@ -36,6 +36,7 @@
from tests.functional import MagicMock, patch
from openlp.plugins.songs.lib.importers.songbeamer import SongBeamerImport
from openlp.plugins.songs.lib import VerseType
+from openlp.core.common import Registry
TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__),
'..', '..', '..', 'resources', 'songbeamersongs'))
@@ -59,6 +60,12 @@
"""
Test the functions in the :mod:`songbeamerimport` module.
"""
+ def setUp(self):
+ """
+ Create the registry
+ """
+ Registry.create()
+
def create_importer_test(self):
"""
Test creating an instance of the SongBeamer file importer
=== modified file 'tests/functional/openlp_plugins/songs/test_zionworximport.py'
--- tests/functional/openlp_plugins/songs/test_zionworximport.py 2014-07-04 09:31:06 +0000
+++ tests/functional/openlp_plugins/songs/test_zionworximport.py 2014-09-28 15:49:42 +0000
@@ -35,12 +35,19 @@
from tests.functional import MagicMock, patch
from openlp.plugins.songs.lib.importers.zionworx import ZionWorxImport
from openlp.plugins.songs.lib.importers.songimport import SongImport
+from openlp.core.common import Registry
class TestZionWorxImport(TestCase):
"""
Test the functions in the :mod:`zionworximport` module.
"""
+ def setUp(self):
+ """
+ Create the registry
+ """
+ Registry.create()
+
def create_importer_test(self):
"""
Test creating an instance of the ZionWorx file importer
=== modified file 'tests/helpers/songfileimport.py'
--- tests/helpers/songfileimport.py 2014-07-07 16:21:45 +0000
+++ tests/helpers/songfileimport.py 2014-09-28 15:49:42 +0000
@@ -34,6 +34,8 @@
import logging
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__)
@@ -53,6 +55,7 @@
"""
Patch and set up the mocks required.
"""
+ Registry.create()
self.add_copyright_patcher = patch('openlp.plugins.songs.lib.importers.%s.%s.add_copyright' %
(self.importer_module_name, self.importer_class_name))
self.add_verse_patcher = patch('openlp.plugins.songs.lib.importers.%s.%s.add_verse' %
=== added file 'tests/interfaces/openlp_core_ui/test_slidecontroller.py'
--- tests/interfaces/openlp_core_ui/test_slidecontroller.py 1970-01-01 00:00:00 +0000
+++ tests/interfaces/openlp_core_ui/test_slidecontroller.py 2014-09-28 15:49:42 +0000
@@ -0,0 +1,90 @@
+# -*- coding: utf-8 -*-
+# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
+
+###############################################################################
+# OpenLP - Open Source Lyrics Projection #
+# --------------------------------------------------------------------------- #
+# Copyright (c) 2008-2014 Raoul Snyman #
+# Portions copyright (c) 2008-2014 Tim Bentley, Gerald Britton, Jonathan #
+# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
+# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
+# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, #
+# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
+# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, #
+# Frode Woldsund, Martin Zibricky, Patrick Zimmermann #
+# --------------------------------------------------------------------------- #
+# 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 #
+###############################################################################
+"""
+Package to test the openlp.core.ui.slidecontroller package.
+"""
+from PyQt4 import QtCore, QtTest
+
+from unittest import TestCase
+from openlp.core import Registry
+from openlp.core.lib import ServiceItemAction
+from openlp.core.lib import ScreenList
+
+from openlp.core.ui import SlideController
+from openlp.core.ui.slidecontroller import WIDE_MENU, NON_TEXT_MENU
+
+from tests.interfaces import MagicMock, patch
+from tests.helpers.testmixin import TestMixin
+
+
+class TestSlideController(TestCase,TestMixin):
+
+ def setUp(self):
+ """
+ Create the UI
+ """
+ self.build_settings()
+ self.get_application()
+ Registry.create()
+ ScreenList.create(self.app.desktop())
+ self.mocked_main_window = MagicMock()
+ self.mocked_main_window.control_splitter = None
+ Registry().register('media_controller', MagicMock())
+ Registry().register('service_list', MagicMock())
+ Registry().register('main_window', self.mocked_main_window)
+ self.slide_controller = SlideController(None)
+ self.slide_controller.update_slide_limits = MagicMock()
+ self.slide_controller.type_prefix = MagicMock()
+ self.slide_controller.category = MagicMock()
+
+ def tearDown(self):
+ """
+ Clean up
+ """
+ self.destroy_settings()
+
+
+ def click_preview_widget_test(self):
+ """
+ Test that when the preview_widget is clicked then on_slide_selected is called
+ """
+ # GIVEN: An initialized SlideController with some mocking
+ with patch('openlp.core.ui.slidecontroller.create_action') as mocked_create_action:
+ mocked_create_action.return_value = None
+ self.slide_controller.on_slide_selected = MagicMock()
+ self.slide_controller.initialise()
+
+ # WHEN: The preview_widget is clicked
+ QtTest.QTest.mouseClick(self.slide_controller.preview_widget, QtCore.Qt.LeftButton)
+ QtTest.QTest.mouseClick(self.slide_controller.preview_widget.verticalHeader(), QtCore.Qt.LeftButton)
+
+
+ # THEN slide_selected should have been called twice
+ self.assertEqual(self.slide_controller.on_slide_selected.call_count, 2,
+ 'on_slide_selected should have been called 2 times')
\ No newline at end of file
=== added file 'tests/resources/openlyricssongs/duchu-tags.xml'
--- tests/resources/openlyricssongs/duchu-tags.xml 1970-01-01 00:00:00 +0000
+++ tests/resources/openlyricssongs/duchu-tags.xml 2014-09-28 15:49:42 +0000
@@ -0,0 +1,27 @@
+<?xml version='1.0' encoding='utf-8'?>
+<song xmlns="http://openlyrics.info/namespace/2009/song" version="0.8" createdIn="OpenLP 2.0.4" modifiedIn="OpenLP 2.0.4" modifiedDate="2014-06-27T09:55:49">
+ <properties>
+ <titles>
+ <title>Duchu svätý volám príď <akordy></title>
+ </titles>
+ <authors>
+ <author>Author Unknown</author>
+ </authors>
+ </properties>
+ <format>
+ <tags application="OpenLP">
+ <tag name="c">
+ <open><span class="chord" style="display:none"><strong></open>
+ <close></strong></span></close>
+ </tag>
+ </tags>
+ </format>
+ <lyrics>
+ <verse name="v1">
+ <lines><tag name="c">[D]</tag>Duchu svätý volám príď, <tag name="c">[Ami]</tag>oheň mojej duši daj,<br/><tag name="c">[G]</tag>Oheň môjmu telu daj, <tag name="c">[D]</tag>rozpáľ ma.</lines>
+ </verse>
+ <verse name="c1">
+ <lines>Všemoh<tag name="c">[Ami]</tag>úci <tag name="c">[G]</tag>Boh tu s nami <tag name="c">[D]</tag>je,<br/>neko<tag name="c">[Ami]</tag>nečne <tag name="c">[G]</tag>milostivý <tag name="c">[D]</tag>je,<br/>Uka<tag name="c">[Ami]</tag>zuje <tag name="c">[G]</tag>dobrotivú <tag name="c">[D]</tag>tvár voči <tag name="c">[Ami]</tag>t<tag name="c">[G]</tag>ým,<br/>ktorí milovať ho <tag name="c">[D]</tag>chcú.</lines>
+ </verse>
+ </lyrics>
+</song>
\ No newline at end of file
Follow ups