From c89b54e4a4239f5c31d4b33ba991845f098a22f9 Mon Sep 17 00:00:00 2001 From: Ken Roberts Date: Fri, 7 Nov 2014 14:24:20 -0800 Subject: [PATCH 1/9] Add basic test for projector.sourceselectform --- .../test_projectorsourceform.py | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 tests/interfaces/openlp_core_ui/test_projectorsourceform.py diff --git a/tests/interfaces/openlp_core_ui/test_projectorsourceform.py b/tests/interfaces/openlp_core_ui/test_projectorsourceform.py new file mode 100644 index 000000000..88b475d7e --- /dev/null +++ b/tests/interfaces/openlp_core_ui/test_projectorsourceform.py @@ -0,0 +1,77 @@ +# -*- 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, Ken Roberts, 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 # +############################################################################### +""" + :mod: `tests.interfaces.openlp_core_ui.test_projectorsourceform` module + + Tests for the Projector Source Select form. +""" +import logging +log = logging.getLogger(__name__) +log.debug('test_projectorsourceform loaded') + +from unittest import TestCase + +from tests.helpers.testmixin import TestMixin +from openlp.core.lib.projector.constants import PJLINK_DEFAULT_CODES, PJLINK_DEFAULT_SOURCES + +from openlp.core.ui.projector.sourceselectform import source_group + +def build_source_dict(): + """ + Builds a source dictionary to verify source_group returns a valid dictionary of dictionary items + + :returns: dictionary of valid PJLink source codes grouped by PJLink source group + """ + test_group = {} + for group in PJLINK_DEFAULT_SOURCES.keys(): + test_group[group] = {} + for key in PJLINK_DEFAULT_CODES: + test_group[key[0]][key] = PJLINK_DEFAULT_CODES[key] + return test_group + +class ProjectorSourceFormTest(TestCase, TestMixin): + """ + Test class for the Projector Source Select form module + """ + def source_dict_test(self): + """ + Test that source list dict returned from sourceselectform module is a valid dict with proper entries + """ + # GIVEN: A list of inputs + codes = [] + for item in PJLINK_DEFAULT_CODES.keys(): + codes.append(item) + codes.sort() + + # WHEN: projector.sourceselectform.source_select() is called + check = source_group(codes, PJLINK_DEFAULT_CODES) + + # THEN: return dictionary should match test dictionary + self.assertEquals(check, build_source_dict(), + "Source group dictionary should match test dictionary") From f2cd0a974352d05f70a750ac44e9e12eacbb7efb Mon Sep 17 00:00:00 2001 From: Ken Roberts Date: Fri, 7 Nov 2014 14:44:40 -0800 Subject: [PATCH 2/9] Fix "Discard" and "Reset" button calls, pep8 --- openlp/core/ui/projector/sourceselectform.py | 39 ++++++++++--------- .../test_projectorsourceform.py | 2 + 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/openlp/core/ui/projector/sourceselectform.py b/openlp/core/ui/projector/sourceselectform.py index 6e7ab7f76..6c03473ad 100644 --- a/openlp/core/ui/projector/sourceselectform.py +++ b/openlp/core/ui/projector/sourceselectform.py @@ -152,16 +152,15 @@ def set_button_tooltip(bar): """ for button in bar.buttons(): if bar.standardButton(button) == QDialogButtonBox.Cancel: - tip = "Ignoring current changes and return to OpenLP" + button.setToolTip("Ignoring current changes and return to OpenLP") elif bar.standardButton(button) == QDialogButtonBox.Reset: - tip = "Delete all user-defined text and revert to PJLink default text" + button.setToolTip("Delete all user-defined text and revert to PJLink default text") elif bar.standardButton(button) == QDialogButtonBox.Discard: - tip = "Discard changes and reset to previous user-defined text" + button.setToolTip("Discard changes and reset to previous user-defined text") elif bar.standardButton(button) == QDialogButtonBox.Ok: - tip = "Save changes and return to OpenLP" + button.setToolTip("Save changes and return to OpenLP") else: - tip = "" - button.setToolTip(tip) + log.debug('No tooltip for button {}'.format(button.text())) class FingerTabBarWidget(QTabBar): @@ -286,6 +285,10 @@ class SourceSelectTabs(QDialog): thistab = self.tabwidget.addTab(tab, PJLINK_DEFAULT_SOURCES[key]) if buttonchecked: self.tabwidget.setCurrentIndex(thistab) + self.button_box = QDialogButtonBox(QtGui.QDialogButtonBox.Reset | + QtGui.QDialogButtonBox.Discard | + QtGui.QDialogButtonBox.Ok | + QtGui.QDialogButtonBox.Cancel) else: for key in keys: (tab, button_count, buttonchecked) = Build_Tab(group=self.button_group, @@ -297,10 +300,8 @@ class SourceSelectTabs(QDialog): thistab = self.tabwidget.addTab(tab, PJLINK_DEFAULT_SOURCES[key]) if buttonchecked: self.tabwidget.setCurrentIndex(thistab) - self.button_box = QDialogButtonBox(QtGui.QDialogButtonBox.Reset | - QtGui.QDialogButtonBox.Discard | - QtGui.QDialogButtonBox.Ok | - QtGui.QDialogButtonBox.Cancel) + self.button_box = QDialogButtonBox(QtGui.QDialogButtonBox.Ok | + QtGui.QDialogButtonBox.Cancel) self.button_box.clicked.connect(self.button_clicked) self.layout.addWidget(self.button_box) set_button_tooltip(self.button_box) @@ -321,9 +322,9 @@ class SourceSelectTabs(QDialog): if self.button_box.standardButton(button) == self.button_box.Cancel: self.done(0) elif self.button_box.standardButton(button) == self.button_box.Reset: - self.delete_sources() - elif self.button_box.standardButton(button) == self.button_box.Discard: self.done(100) + elif self.button_box.standardButton(button) == self.button_box.Discard: + self.delete_sources() elif self.button_box.standardButton(button) == self.button_box.Ok: return self.accept_me() else: @@ -418,6 +419,10 @@ class SourceSelectSingle(QDialog): item.setText(source_item.text) self.layout.addRow(PJLINK_DEFAULT_CODES[key], item) self.button_group.append(item) + self.button_box = QDialogButtonBox(QtGui.QDialogButtonBox.Reset | + QtGui.QDialogButtonBox.Discard | + QtGui.QDialogButtonBox.Ok | + QtGui.QDialogButtonBox.Cancel) else: for key in keys: source_text = self.projectordb.get_source_by_code(code=key, projector_id=self.projector.db_item.id) @@ -427,10 +432,8 @@ class SourceSelectSingle(QDialog): self.layout.addWidget(button) self.button_group.addButton(button, int(key)) button_list.append(key) - self.button_box = QDialogButtonBox(QtGui.QDialogButtonBox.Reset | - QtGui.QDialogButtonBox.Discard | - QtGui.QDialogButtonBox.Ok | - QtGui.QDialogButtonBox.Cancel) + self.button_box = QDialogButtonBox(QtGui.QDialogButtonBox.Ok | + QtGui.QDialogButtonBox.Cancel) self.button_box.clicked.connect(self.button_clicked) self.layout.addWidget(self.button_box) self.setMinimumHeight(key_count*25) @@ -452,9 +455,9 @@ class SourceSelectSingle(QDialog): if self.button_box.standardButton(button) == self.button_box.Cancel: self.done(0) elif self.button_box.standardButton(button) == self.button_box.Reset: - self.delete_sources() - elif self.button_box.standardButton(button) == self.button_box.Discard: self.done(100) + elif self.button_box.standardButton(button) == self.button_box.Discard: + self.delete_sources() elif self.button_box.standardButton(button) == self.button_box.Ok: return self.accept_me() else: diff --git a/tests/interfaces/openlp_core_ui/test_projectorsourceform.py b/tests/interfaces/openlp_core_ui/test_projectorsourceform.py index 88b475d7e..ed005a7d9 100644 --- a/tests/interfaces/openlp_core_ui/test_projectorsourceform.py +++ b/tests/interfaces/openlp_core_ui/test_projectorsourceform.py @@ -42,6 +42,7 @@ from openlp.core.lib.projector.constants import PJLINK_DEFAULT_CODES, PJLINK_DEF from openlp.core.ui.projector.sourceselectform import source_group + def build_source_dict(): """ Builds a source dictionary to verify source_group returns a valid dictionary of dictionary items @@ -55,6 +56,7 @@ def build_source_dict(): test_group[key[0]][key] = PJLINK_DEFAULT_CODES[key] return test_group + class ProjectorSourceFormTest(TestCase, TestMixin): """ Test class for the Projector Source Select form module From aadbce133e9c1e39e0759b7864e46f49fe857c98 Mon Sep 17 00:00:00 2001 From: Ken Roberts Date: Mon, 10 Nov 2014 16:14:17 -0800 Subject: [PATCH 3/9] Add missing tranlsate to text/fix select/edit title --- openlp/core/ui/projector/sourceselectform.py | 39 +++++++++++++------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/openlp/core/ui/projector/sourceselectform.py b/openlp/core/ui/projector/sourceselectform.py index 6c03473ad..e7e0c2201 100644 --- a/openlp/core/ui/projector/sourceselectform.py +++ b/openlp/core/ui/projector/sourceselectform.py @@ -152,13 +152,17 @@ def set_button_tooltip(bar): """ for button in bar.buttons(): if bar.standardButton(button) == QDialogButtonBox.Cancel: - button.setToolTip("Ignoring current changes and return to OpenLP") + button.setToolTip(translate('OpenLP.SourceSelectForm', + "Ignoring current changes and return to OpenLP")) elif bar.standardButton(button) == QDialogButtonBox.Reset: - button.setToolTip("Delete all user-defined text and revert to PJLink default text") + button.setToolTip(translate('OpenLP.SourceSelectForm', + "Delete all user-defined text and revert to PJLink default text")) elif bar.standardButton(button) == QDialogButtonBox.Discard: - button.setToolTip("Discard changes and reset to previous user-defined text") + button.setToolTip(translate('OpenLP.SourceSelectForm', + "Discard changes and reset to previous user-defined text")) elif bar.standardButton(button) == QDialogButtonBox.Ok: - button.setToolTip("Save changes and return to OpenLP") + button.setToolTip(translate('OpenLP.SourceSelectForm', + "Save changes and return to OpenLP")) else: log.debug('No tooltip for button {}'.format(button.text())) @@ -236,12 +240,13 @@ class SourceSelectTabs(QDialog): """ log.debug('Initializing SourceSelectTabs()') super(SourceSelectTabs, self).__init__(parent) + self.setMinimumWidth(350) self.projectordb = projectordb self.edit = edit if self.edit: - title = translate('OpenLP.SourceSelectForm', 'Select Projector Source') - else: title = translate('OpenLP.SourceSelectForm', 'Edit Projector Source Text') + else: + title = translate('OpenLP.SourceSelectForm', 'Select Projector Source') self.setWindowTitle(title) self.setObjectName('source_select_tabs') self.setWindowIcon(build_icon(':/icon/openlp-log-32x32.png')) @@ -332,9 +337,11 @@ class SourceSelectTabs(QDialog): def delete_sources(self): msg = QtGui.QMessageBox() - msg.setText('Delete entries for this projector') - msg.setInformativeText('Are you sure you want to delete ALL user-defined ' - 'source input text for this projector?') + msg.setText(translate('OpenLP.SourceSelectForm', 'Delete entries for this projector')) + msg.setInformativeText(translate('OpenLP.SourceSelectForm', + 'Are you sure you want to delete ALL user-defined '), + translate('OpenLP.SourceSelectForm', + 'source input text for this projector?')) msg.setStandardButtons(msg.Cancel | msg.Ok) msg.setDefaultButton(msg.Cancel) ans = msg.exec_() @@ -383,7 +390,11 @@ class SourceSelectSingle(QDialog): log.debug('Initializing SourceSelectSingle()') self.projectordb = projectordb super(SourceSelectSingle, self).__init__(parent) - self.setWindowTitle(translate('OpenLP.SourceSelectSingle', 'Select Projector Source')) + self.edit = edit + if self.edit: + title = translate('OpenLP.SourceSelectForm', 'Edit Projector Source Text') + else: + title = translate('OpenLP.SourceSelectForm', 'Select Projector Source') self.setObjectName('source_select_single') self.setWindowIcon(build_icon(':/icon/openlp-log-32x32.png')) self.setModal(True) @@ -465,9 +476,11 @@ class SourceSelectSingle(QDialog): def delete_sources(self): msg = QtGui.QMessageBox() - msg.setText('Delete entries for this projector') - msg.setInformativeText('Are you sure you want to delete ALL user-defined ' - 'source input text for this projector?') + msg.setText(translate('OpenLP.SourceSelectForm', 'Delete entries for this projector')) + msg.setInformativeText(translate('OpenLP.SourceSelectForm', + 'Are you sure you want to delete ALL user-defined '), + translate('OpenLP.SourceSelectForm', + 'source input text for this projector?')) msg.setStandardButtons(msg.Cancel | msg.Ok) msg.setDefaultButton(msg.Cancel) ans = msg.exec_() From ea14deaa873ceb2076ad5979e618764d907d06e2 Mon Sep 17 00:00:00 2001 From: Ken Roberts Date: Wed, 26 Nov 2014 09:24:05 -0800 Subject: [PATCH 4/9] Fix quotes --- .bzrignore | 42 ------------------- openlp/core/ui/projector/sourceselectform.py | 8 ++-- .../openlp_core_ui/test_projectormanager.py | 4 +- 3 files changed, 5 insertions(+), 49 deletions(-) delete mode 100644 .bzrignore diff --git a/.bzrignore b/.bzrignore deleted file mode 100644 index 6b7b989a6..000000000 --- a/.bzrignore +++ /dev/null @@ -1,42 +0,0 @@ -*.pyc -*.*~ -\#*\# -*.eric4project -*.eric5project -*.ropeproject -*.e4* -.eric4project -.komodotools -*.komodoproject -list -openlp.org 2.0.e4* -documentation/build/html -documentation/build/doctrees -*.log* -dist -OpenLP.egg-info -build -resources/innosetup/Output -_eric4project -.pylint.d -*.qm -openlp/core/resources.py.old -*.qm -resources/windows/warnOpenLP.txt -openlp.cfg -.idea -openlp.pro -.kdev4 -tests.kdev4 -*.nja -*.orig -__pycache__ -*.dll -.directory -*.kate-swp -# Git files -.git -.gitignore -# Rejected diff's -*.rej -*.~\?~ diff --git a/openlp/core/ui/projector/sourceselectform.py b/openlp/core/ui/projector/sourceselectform.py index e7e0c2201..244b7adef 100644 --- a/openlp/core/ui/projector/sourceselectform.py +++ b/openlp/core/ui/projector/sourceselectform.py @@ -153,16 +153,16 @@ def set_button_tooltip(bar): for button in bar.buttons(): if bar.standardButton(button) == QDialogButtonBox.Cancel: button.setToolTip(translate('OpenLP.SourceSelectForm', - "Ignoring current changes and return to OpenLP")) + 'Ignoring current changes and return to OpenLP')) elif bar.standardButton(button) == QDialogButtonBox.Reset: button.setToolTip(translate('OpenLP.SourceSelectForm', - "Delete all user-defined text and revert to PJLink default text")) + 'Delete all user-defined text and revert to PJLink default text')) elif bar.standardButton(button) == QDialogButtonBox.Discard: button.setToolTip(translate('OpenLP.SourceSelectForm', - "Discard changes and reset to previous user-defined text")) + 'Discard changes and reset to previous user-defined text')) elif bar.standardButton(button) == QDialogButtonBox.Ok: button.setToolTip(translate('OpenLP.SourceSelectForm', - "Save changes and return to OpenLP")) + 'Save changes and return to OpenLP')) else: log.debug('No tooltip for button {}'.format(button.text())) diff --git a/tests/interfaces/openlp_core_ui/test_projectormanager.py b/tests/interfaces/openlp_core_ui/test_projectormanager.py index a46b0b93c..58638458e 100644 --- a/tests/interfaces/openlp_core_ui/test_projectormanager.py +++ b/tests/interfaces/openlp_core_ui/test_projectormanager.py @@ -94,11 +94,9 @@ class TestProjectorManager(TestCase, TestMixin): self.projector_manager.bootstrap_initialise() self.projector_manager.bootstrap_post_set_up() - # THEN: verify calls to retrieve saved projectors + # THEN: verify calls to retrieve saved projectors and edit page initialized self.assertEqual(1, self.projector_manager._load_projectors.call_count, 'Initialization should have called load_projectors()') - - # THEN: Verify edit page is initialized self.assertEqual(type(self.projector_manager.projector_form), ProjectorEditForm, 'Initialization should have created a Projector Edit Form') self.assertIs(self.projector_manager.projectordb, From f9a052ac8527921c5e5dc9ebec23926514ac3de5 Mon Sep 17 00:00:00 2001 From: Ken Roberts Date: Mon, 1 Dec 2014 07:39:05 -0800 Subject: [PATCH 5/9] Add .bzrignore from trunk --- .bzrignore | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 .bzrignore diff --git a/.bzrignore b/.bzrignore new file mode 100644 index 000000000..6b7b989a6 --- /dev/null +++ b/.bzrignore @@ -0,0 +1,42 @@ +*.pyc +*.*~ +\#*\# +*.eric4project +*.eric5project +*.ropeproject +*.e4* +.eric4project +.komodotools +*.komodoproject +list +openlp.org 2.0.e4* +documentation/build/html +documentation/build/doctrees +*.log* +dist +OpenLP.egg-info +build +resources/innosetup/Output +_eric4project +.pylint.d +*.qm +openlp/core/resources.py.old +*.qm +resources/windows/warnOpenLP.txt +openlp.cfg +.idea +openlp.pro +.kdev4 +tests.kdev4 +*.nja +*.orig +__pycache__ +*.dll +.directory +*.kate-swp +# Git files +.git +.gitignore +# Rejected diff's +*.rej +*.~\?~ From 9d54d6351a9d094561f4e19d512a3fb0fddbb135 Mon Sep 17 00:00:00 2001 From: Phill Ridout Date: Sun, 7 Dec 2014 17:46:23 +0000 Subject: [PATCH 6/9] Tests --- openlp/core/utils/__init__.py | 1 + .../functional/openlp_core_utils/test_init.py | 75 ++++++++++++++++++- 2 files changed, 74 insertions(+), 2 deletions(-) diff --git a/openlp/core/utils/__init__.py b/openlp/core/utils/__init__.py index df9d57fef..dcf25a439 100644 --- a/openlp/core/utils/__init__.py +++ b/openlp/core/utils/__init__.py @@ -414,6 +414,7 @@ def get_uno_command(): raise FileNotFoundError('Command not found') OPTIONS = '--nologo --norestore --minimized --nodefault --nofirststartwizard' + print(UNO_CONNECTION_TYPE) if UNO_CONNECTION_TYPE == 'pipe': CONNECTION = '"--accept=pipe,name=openlp_pipe;urp;"' else: diff --git a/tests/functional/openlp_core_utils/test_init.py b/tests/functional/openlp_core_utils/test_init.py index 0931014ab..d805965d7 100644 --- a/tests/functional/openlp_core_utils/test_init.py +++ b/tests/functional/openlp_core_utils/test_init.py @@ -32,6 +32,7 @@ Package to test the openlp.core.utils.actions package. from unittest import TestCase from openlp.core.common.settings import Settings +from openlp.core import utils from openlp.core.utils import VersionThread, get_application_version from tests.functional import MagicMock, patch from tests.helpers.testmixin import TestMixin @@ -62,9 +63,79 @@ class TestInitFunctions(TestMixin, TestCase): # WHEN: We check to see if the version is different . with patch('PyQt4.QtCore.QThread'),\ patch('openlp.core.utils.get_application_version') as mocked_get_application_version: - mocked_get_application_version.return_value = \ - {'version': '1.0.0', 'build': '', 'full': '2.0.4'} + mocked_get_application_version.return_value = {'version': '1.0.0', 'build': '', 'full': '2.0.4'} version_thread = VersionThread(mocked_main_window) version_thread.run() # THEN: If the version has changed the main window is notified self.assertTrue(mocked_main_window.emit.called, 'The main windows should have been notified') + + def get_uno_command_libreoffice_command_exists_test(self): + """ + Test the ``get_uno_command`` function uses the libreoffice command when available. + :return: + """ + + # GIVEN: A patched 'which' method which returns a path when called with 'libreoffice' + with patch('openlp.core.utils.which', + **{'side_effect': lambda command: {'libreoffice': '/usr/bin/libreoffice'}[command]}): + + # WHEN: Calling get_uno_command + result = utils.get_uno_command() + + # THEN: The command 'libreoffice' should be called with the appropriate parameters + self.assertEquals(result, 'libreoffice --nologo --norestore --minimized --nodefault --nofirststartwizard' + ' "--accept=pipe,name=openlp_pipe;urp;"') + + def get_uno_command_only_soffice_command_exists_test(self): + """ + Test the ``get_uno_command`` function uses the soffice command when the libreoffice command is not available. + :return: + """ + + # GIVEN: A patched 'which' method which returns None when called with 'libreoffice' and a path when called with + # 'soffice' + with patch('openlp.core.utils.which', + **{'side_effect': lambda command: {'libreoffice': None, 'soffice': '/usr/bin/soffice'}[command]}): + + # WHEN: Calling get_uno_command + result = utils.get_uno_command() + + # THEN: The command 'soffice' should be called with the appropriate parameters + self.assertEquals(result, 'soffice --nologo --norestore --minimized --nodefault --nofirststartwizard' + ' "--accept=pipe,name=openlp_pipe;urp;"') + + def get_uno_command_when_no_command_exists_test(self): + """ + Test the ``get_uno_command`` function raises an FileNotFoundError when neither the libreoffice or soffice + commands are available. + :return: + """ + + # GIVEN: A patched 'which' method which returns None + with patch('openlp.core.utils.which', **{'return_value': None}): + + # WHEN: Calling get_uno_command + + # THEN: The command 'soffice' should be called with the appropriate parameters + self.assertRaises(FileNotFoundError, utils.get_uno_command) + + def get_uno_command_connection_type_test(self): + """ + Test the ``get_uno_command`` function when the connection type is anything other than pipe. + :return: + """ + + original_type = utils.UNO_CONNECTION_TYPE + + # GIVEN: A patched 'which' method which returns 'libreoffice' + with patch('openlp.core.utils.which', **{'return_value': 'libreoffice'}): + + # WHEN: Calling get_uno_command + utils.UNO_CONNECTION_TYPE = 'socket' + result = utils.get_uno_command() + + # THEN: The command 'soffice' should be called with the appropriate parameters + self.assertEqual(result, 'libreoffice --nologo --norestore --minimized --nodefault --nofirststartwizard' + ' "--accept=socket,host=localhost,port=2002;urp;"') + + utils.UNO_CONNECTION_TYPE = original_type From 2dd7a6e77652d198d74cbcb036efa6e45098276b Mon Sep 17 00:00:00 2001 From: Phill Ridout Date: Sun, 7 Dec 2014 17:53:32 +0000 Subject: [PATCH 7/9] remove print statment --- openlp/core/utils/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/openlp/core/utils/__init__.py b/openlp/core/utils/__init__.py index efe005f34..aa03006c5 100644 --- a/openlp/core/utils/__init__.py +++ b/openlp/core/utils/__init__.py @@ -434,7 +434,6 @@ def get_uno_command(): raise FileNotFoundError('Command not found') OPTIONS = '--nologo --norestore --minimized --nodefault --nofirststartwizard' - print(UNO_CONNECTION_TYPE) if UNO_CONNECTION_TYPE == 'pipe': CONNECTION = '"--accept=pipe,name=openlp_pipe;urp;"' else: From 6fd061274864311b4859c5078f54530b99a49783 Mon Sep 17 00:00:00 2001 From: Phill Ridout Date: Sun, 7 Dec 2014 19:13:21 +0000 Subject: [PATCH 8/9] set connection type for each test --- .../functional/openlp_core_utils/test_init.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/tests/functional/openlp_core_utils/test_init.py b/tests/functional/openlp_core_utils/test_init.py index d805965d7..e8842ea5f 100644 --- a/tests/functional/openlp_core_utils/test_init.py +++ b/tests/functional/openlp_core_utils/test_init.py @@ -79,7 +79,8 @@ class TestInitFunctions(TestMixin, TestCase): with patch('openlp.core.utils.which', **{'side_effect': lambda command: {'libreoffice': '/usr/bin/libreoffice'}[command]}): - # WHEN: Calling get_uno_command + # WHEN: Calling get_uno_command with a pipe connection type + utils.UNO_CONNECTION_TYPE = 'pipe' result = utils.get_uno_command() # THEN: The command 'libreoffice' should be called with the appropriate parameters @@ -97,7 +98,8 @@ class TestInitFunctions(TestMixin, TestCase): with patch('openlp.core.utils.which', **{'side_effect': lambda command: {'libreoffice': None, 'soffice': '/usr/bin/soffice'}[command]}): - # WHEN: Calling get_uno_command + # WHEN: Calling get_uno_command with a pipe connection type + utils.UNO_CONNECTION_TYPE = 'pipe' result = utils.get_uno_command() # THEN: The command 'soffice' should be called with the appropriate parameters @@ -114,9 +116,10 @@ class TestInitFunctions(TestMixin, TestCase): # GIVEN: A patched 'which' method which returns None with patch('openlp.core.utils.which', **{'return_value': None}): - # WHEN: Calling get_uno_command + # WHEN: Calling get_uno_command with a pipe connection type + utils.UNO_CONNECTION_TYPE = 'pipe' - # THEN: The command 'soffice' should be called with the appropriate parameters + # THEN: a FileNotFoundError exception should be raised self.assertRaises(FileNotFoundError, utils.get_uno_command) def get_uno_command_connection_type_test(self): @@ -125,17 +128,13 @@ class TestInitFunctions(TestMixin, TestCase): :return: """ - original_type = utils.UNO_CONNECTION_TYPE - # GIVEN: A patched 'which' method which returns 'libreoffice' with patch('openlp.core.utils.which', **{'return_value': 'libreoffice'}): - # WHEN: Calling get_uno_command + # WHEN: Calling get_uno_command with a connection type other than pipe utils.UNO_CONNECTION_TYPE = 'socket' result = utils.get_uno_command() - # THEN: The command 'soffice' should be called with the appropriate parameters + # THEN: The connection parameters should be set for socket self.assertEqual(result, 'libreoffice --nologo --norestore --minimized --nodefault --nofirststartwizard' ' "--accept=socket,host=localhost,port=2002;urp;"') - - utils.UNO_CONNECTION_TYPE = original_type From 2642a21d530dffe72ee453152a685149c6fb202e Mon Sep 17 00:00:00 2001 From: Phill Ridout Date: Mon, 8 Dec 2014 07:19:51 +0000 Subject: [PATCH 9/9] Refactor get_uno_command & get_uno_instance --- openlp/core/utils/__init__.py | 9 ++++---- .../functional/openlp_core_utils/test_init.py | 21 +++++++------------ 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/openlp/core/utils/__init__.py b/openlp/core/utils/__init__.py index aa03006c5..0510c832b 100644 --- a/openlp/core/utils/__init__.py +++ b/openlp/core/utils/__init__.py @@ -64,7 +64,6 @@ log = logging.getLogger(__name__ + '.__init__') APPLICATION_VERSION = {} IMAGES_FILTER = None ICU_COLLATOR = None -UNO_CONNECTION_TYPE = 'pipe' CONTROL_CHARS = re.compile(r'[\x00-\x1F\x7F-\x9F]', re.UNICODE) INVALID_FILE_CHARS = re.compile(r'[\\/:\*\?"<>\|\+\[\]%]', re.UNICODE) DIGITS_OR_NONDIGITS = re.compile(r'\d+|\D+', re.UNICODE) @@ -423,7 +422,7 @@ def get_web_page(url, header=None, update_openlp=False): return page -def get_uno_command(): +def get_uno_command(connection_type='pipe'): """ Returns the UNO command to launch an openoffice.org instance. """ @@ -434,21 +433,21 @@ def get_uno_command(): raise FileNotFoundError('Command not found') OPTIONS = '--nologo --norestore --minimized --nodefault --nofirststartwizard' - if UNO_CONNECTION_TYPE == 'pipe': + if connection_type == 'pipe': CONNECTION = '"--accept=pipe,name=openlp_pipe;urp;"' else: CONNECTION = '"--accept=socket,host=localhost,port=2002;urp;"' return '%s %s %s' % (command, OPTIONS, CONNECTION) -def get_uno_instance(resolver): +def get_uno_instance(resolver, connection_type='pipe'): """ Returns a running openoffice.org instance. :param resolver: The UNO resolver to use to find a running instance. """ log.debug('get UNO Desktop Openoffice - resolve') - if UNO_CONNECTION_TYPE == 'pipe': + if connection_type == 'pipe': return resolver.resolve('uno:pipe,name=openlp_pipe;urp;StarOffice.ComponentContext') else: return resolver.resolve('uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext') diff --git a/tests/functional/openlp_core_utils/test_init.py b/tests/functional/openlp_core_utils/test_init.py index e8842ea5f..563f0dc5b 100644 --- a/tests/functional/openlp_core_utils/test_init.py +++ b/tests/functional/openlp_core_utils/test_init.py @@ -32,8 +32,7 @@ Package to test the openlp.core.utils.actions package. from unittest import TestCase from openlp.core.common.settings import Settings -from openlp.core import utils -from openlp.core.utils import VersionThread, get_application_version +from openlp.core.utils import VersionThread, get_application_version, get_uno_command from tests.functional import MagicMock, patch from tests.helpers.testmixin import TestMixin @@ -79,9 +78,8 @@ class TestInitFunctions(TestMixin, TestCase): with patch('openlp.core.utils.which', **{'side_effect': lambda command: {'libreoffice': '/usr/bin/libreoffice'}[command]}): - # WHEN: Calling get_uno_command with a pipe connection type - utils.UNO_CONNECTION_TYPE = 'pipe' - result = utils.get_uno_command() + # WHEN: Calling get_uno_command + result = get_uno_command() # THEN: The command 'libreoffice' should be called with the appropriate parameters self.assertEquals(result, 'libreoffice --nologo --norestore --minimized --nodefault --nofirststartwizard' @@ -98,9 +96,8 @@ class TestInitFunctions(TestMixin, TestCase): with patch('openlp.core.utils.which', **{'side_effect': lambda command: {'libreoffice': None, 'soffice': '/usr/bin/soffice'}[command]}): - # WHEN: Calling get_uno_command with a pipe connection type - utils.UNO_CONNECTION_TYPE = 'pipe' - result = utils.get_uno_command() + # WHEN: Calling get_uno_command + result = get_uno_command() # THEN: The command 'soffice' should be called with the appropriate parameters self.assertEquals(result, 'soffice --nologo --norestore --minimized --nodefault --nofirststartwizard' @@ -116,11 +113,10 @@ class TestInitFunctions(TestMixin, TestCase): # GIVEN: A patched 'which' method which returns None with patch('openlp.core.utils.which', **{'return_value': None}): - # WHEN: Calling get_uno_command with a pipe connection type - utils.UNO_CONNECTION_TYPE = 'pipe' + # WHEN: Calling get_uno_command # THEN: a FileNotFoundError exception should be raised - self.assertRaises(FileNotFoundError, utils.get_uno_command) + self.assertRaises(FileNotFoundError, get_uno_command) def get_uno_command_connection_type_test(self): """ @@ -132,8 +128,7 @@ class TestInitFunctions(TestMixin, TestCase): with patch('openlp.core.utils.which', **{'return_value': 'libreoffice'}): # WHEN: Calling get_uno_command with a connection type other than pipe - utils.UNO_CONNECTION_TYPE = 'socket' - result = utils.get_uno_command() + result = get_uno_command('socket') # THEN: The connection parameters should be set for socket self.assertEqual(result, 'libreoffice --nologo --norestore --minimized --nodefault --nofirststartwizard'