← Back to team overview

openlp-core team mailing list archive

[Merge] lp:~springermac/openlp/fix-ups into lp:openlp

 

Jonathan Springer has proposed merging lp:~springermac/openlp/fix-ups into lp:openlp.

Requested reviews:
  Tim Bentley (trb143)
  Raoul Snyman (raoul-snyman)
  matysek (mzibricky)

For more details, see:
https://code.launchpad.net/~springermac/openlp/fix-ups/+merge/215324

Remove orphaned and unused registry execute, and fix two functions to register to the registry instead of executing.

Modify loading file from the command line to only load files ending with osz, or oszl.

Fix argument to pass correct type.

[SUCCESS] http://ci.openlp.org/job/Branch-01-Pull/267/
[SUCCESS] http://ci.openlp.org/job/Branch-02-Functional-Tests/228/
[SUCCESS] http://ci.openlp.org/job/Branch-03-Interface-Tests/177/
[SUCCESS] http://ci.openlp.org/job/Branch-04-Windows_Tests/138/
[FAILURE] http://ci.openlp.org/job/Branch-05-Code-Analysis/94/
-- 
https://code.launchpad.net/~springermac/openlp/fix-ups/+merge/215324
Your team OpenLP Core is subscribed to branch lp:openlp.
=== modified file 'openlp/core/ui/mainwindow.py'
--- openlp/core/ui/mainwindow.py	2014-03-28 20:38:38 +0000
+++ openlp/core/ui/mainwindow.py	2014-04-11 00:32:30 +0000
@@ -598,13 +598,7 @@
             self.live_controller.display.setFocus()
         self.activateWindow()
         if self.arguments:
-            args = []
-            for a in self.arguments:
-                args.extend([a])
-            filename = args[0]
-            if not isinstance(filename, str):
-                filename = str(filename, sys.getfilesystemencoding())
-            self.service_manager_contents.load_file(filename)
+            self.open_cmd_line_files()
         elif Settings().value(self.general_settings_section + '/auto open'):
             self.service_manager_contents.load_Last_file()
         self.timer_version_id = self.startTimer(1000)
@@ -1364,3 +1358,17 @@
         if self.new_data_path == AppLocation.get_directory(AppLocation.DataDir):
             settings.remove('advanced/data path')
         self.application.set_normal_cursor()
+
+    def open_cmd_line_files(self):
+        """
+        Open files passed in through command line arguments
+        """
+        args = []
+        for a in self.arguments:
+            args.extend([a])
+        for arg in args:
+            filename = arg
+            if not isinstance(filename, str):
+                filename = str(filename, sys.getfilesystemencoding())
+            if filename.endswith(('.osz', '.oszl')):
+                self.service_manager_contents.load_file(filename)

=== modified file 'openlp/core/ui/slidecontroller.py'
--- openlp/core/ui/slidecontroller.py	2014-03-26 11:26:16 +0000
+++ openlp/core/ui/slidecontroller.py	2014-04-11 00:32:30 +0000
@@ -1039,7 +1039,6 @@
         """
         self.preview_widget.change_slide(row)
         self.update_preview()
-        Registry().execute('slidecontroller_%s_changed' % self.type_prefix, row)
 
     def update_preview(self):
         """

=== modified file 'openlp/core/utils/languagemanager.py'
--- openlp/core/utils/languagemanager.py	2014-03-20 19:10:31 +0000
+++ openlp/core/utils/languagemanager.py	2014-04-11 00:32:30 +0000
@@ -74,7 +74,7 @@
         log.debug('Translation files: %s', AppLocation.get_directory(
             AppLocation.LanguageDir))
         trans_dir = QtCore.QDir(AppLocation.get_directory(AppLocation.LanguageDir))
-        file_names = trans_dir.entryList('*.qm', QtCore.QDir.Files, QtCore.QDir.Name)
+        file_names = trans_dir.entryList(['*.qm'], QtCore.QDir.Files, QtCore.QDir.Name)
         # Remove qm files from the list which start with "qt_".
         file_names = [file_ for file_ in file_names if not file_.startswith('qt_')]
         return list(map(trans_dir.filePath, file_names))

=== modified file 'openlp/plugins/bibles/forms/bibleupgradeform.py'
--- openlp/plugins/bibles/forms/bibleupgradeform.py	2014-03-21 18:23:35 +0000
+++ openlp/plugins/bibles/forms/bibleupgradeform.py	2014-04-11 00:32:30 +0000
@@ -78,7 +78,7 @@
         Set up the UI for the bible wizard.
         """
         super(BibleUpgradeForm, self).setupUi(image)
-        Registry().execute('openlp_stop_wizard', self.stop_import)
+        Registry().register_function('openlp_stop_wizard', self.stop_import)
 
     def stop_import(self):
         """

=== modified file 'openlp/plugins/bibles/lib/db.py'
--- openlp/plugins/bibles/lib/db.py	2014-04-01 17:32:19 +0000
+++ openlp/plugins/bibles/lib/db.py	2014-04-11 00:32:30 +0000
@@ -154,7 +154,7 @@
         if 'path' in kwargs:
             self.path = kwargs['path']
         self.wizard = None
-        Registry().execute('openlp_stop_wizard', self.stop_import)
+        Registry().register_function('openlp_stop_wizard', self.stop_import)
 
     def stop_import(self):
         """

=== added file 'tests/functional/openlp_core_ui/test_mainwindow.py'
--- tests/functional/openlp_core_ui/test_mainwindow.py	1970-01-01 00:00:00 +0000
+++ tests/functional/openlp_core_ui/test_mainwindow.py	2014-04-11 00:32:30 +0000
@@ -0,0 +1,97 @@
+# -*- 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 openlp.core.ui.mainwindow package.
+"""
+import os
+
+from unittest import TestCase
+
+from openlp.core.ui.mainwindow import MainWindow
+from openlp.core.common.registry import Registry
+from tests.utils.constants import TEST_RESOURCES_PATH
+from tests.helpers.testmixin import TestMixin
+from tests.functional import MagicMock, patch
+
+
+class TestMainWindow(TestCase, TestMixin):
+
+    def setUp(self):
+        Registry.create()
+        self.registry = Registry()
+        self.get_application()
+        # Mock cursor busy/normal methods.
+        self.app.set_busy_cursor = MagicMock()
+        self.app.set_normal_cursor = MagicMock()
+        self.app.args = []
+        Registry().register('application', self.app)
+        # Mock classes and methods used by mainwindow.
+        with patch('openlp.core.ui.mainwindow.SettingsForm') as mocked_settings_form, \
+                patch('openlp.core.ui.mainwindow.ImageManager') as mocked_image_manager, \
+                patch('openlp.core.ui.mainwindow.LiveController') as mocked_live_controller, \
+                patch('openlp.core.ui.mainwindow.PreviewController') as mocked_preview_controller, \
+                patch('openlp.core.ui.mainwindow.OpenLPDockWidget') as mocked_dock_widget, \
+                patch('openlp.core.ui.mainwindow.QtGui.QToolBox') as mocked_q_tool_box_class, \
+                patch('openlp.core.ui.mainwindow.QtGui.QMainWindow.addDockWidget') as mocked_add_dock_method, \
+                patch('openlp.core.ui.mainwindow.ThemeManager') as mocked_theme_manager, \
+                patch('openlp.core.ui.mainwindow.Renderer') as mocked_renderer:
+            self.main_window = MainWindow()
+
+    def tearDown(self):
+        del self.main_window
+
+    def cmd_line_file_test(self):
+        """
+        Test that passing a service file from the command line loads the service.
+        """
+        # GIVEN a service as an argument to openlp
+        service = os.path.join(TEST_RESOURCES_PATH, 'service', 'test.osz')
+        self.main_window.arguments = [service]
+        with patch('openlp.core.ui.servicemanager.ServiceManager.load_file') as mocked_load_path:
+
+            # WHEN the argument is processed
+            self.main_window.open_cmd_line_files()
+
+            # THEN the service from the arguments is loaded
+            mocked_load_path.assert_called_with(service), 'load_path should have been called with the service\'s path'
+
+    def cmd_line_arg_test(self):
+        """
+        Test that passing a non service file does nothing.
+        """
+        # GIVEN a non service file as an argument to openlp
+        service = os.path.join('openlp.py')
+        self.main_window.arguments = [service]
+        with patch('openlp.core.ui.servicemanager.ServiceManager.load_file') as mocked_load_path:
+
+            # WHEN the argument is processed
+            self.main_window.open_cmd_line_files()
+
+            # THEN the file should not be opened
+            assert not mocked_load_path.called, 'load_path should not have been called'

=== added directory 'tests/resources/service'
=== added file 'tests/resources/service/test.osz'
Binary files tests/resources/service/test.osz	1970-01-01 00:00:00 +0000 and tests/resources/service/test.osz	2014-04-11 00:32:30 +0000 differ

Follow ups