From ede9bb70d93984927dd2c88e772fb26358403ec4 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Tue, 5 Feb 2013 18:36:43 +0100 Subject: [PATCH 01/57] attempt to fix bug #1100277 Fixes: https://launchpad.net/bugs/1100277 --- openlp/core/lib/__init__.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/openlp/core/lib/__init__.py b/openlp/core/lib/__init__.py index c34c824db..ca8a46126 100644 --- a/openlp/core/lib/__init__.py +++ b/openlp/core/lib/__init__.py @@ -373,16 +373,15 @@ def create_separated_list(stringlist): elif len(stringlist) == 1: return stringlist[0] elif len(stringlist) == 2: - return translate('OpenLP.core.lib', '%1 and %2', + return translate('OpenLP.core.lib', '%s and %s', 'Locale list separator: 2 items') % (stringlist[0], stringlist[1]) else: - merged = translate('OpenLP.core.lib', '%1, and %2', + merged = translate('OpenLP.core.lib', '%s, and %s', u'Locale list separator: end') % (stringlist[-2], stringlist[-1]) for index in reversed(range(1, len(stringlist) - 2)): - merged = translate('OpenLP.core.lib', '%1, %2', - u'Locale list separator: middle') % (stringlist[index], merged) - return translate('OpenLP.core.lib', '%1, %2', - u'Locale list separator: start') % (stringlist[0], merged) + merged = translate('OpenLP.core.lib', '%s, %s', + u'Locale list separator: middle') % (stringlist[index], merged) + return translate('OpenLP.core.lib', '%s, %s', u'Locale list separator: start') % (stringlist[0], merged) from registry import Registry From 6e17ff9d9e4d4e1239dd48e06434b5ce1ffd6b29 Mon Sep 17 00:00:00 2001 From: phill-ridout Date: Tue, 5 Feb 2013 19:57:08 +0000 Subject: [PATCH 02/57] Set lineEdit focus when displaying form --- openlp/core/ui/filerenameform.py | 1 + 1 file changed, 1 insertion(+) diff --git a/openlp/core/ui/filerenameform.py b/openlp/core/ui/filerenameform.py index 0743578a1..ccdca9928 100644 --- a/openlp/core/ui/filerenameform.py +++ b/openlp/core/ui/filerenameform.py @@ -56,4 +56,5 @@ class FileRenameForm(QtGui.QDialog, Ui_FileRenameDialog): self.setWindowTitle(translate('OpenLP.FileRenameForm', 'File Copy')) else: self.setWindowTitle(translate('OpenLP.FileRenameForm', 'File Rename')) + self.fileNameEdit.setFocus() return QtGui.QDialog.exec_(self) From bf01c2f0a813026a86fa9efbe84fb07537e4c14b Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Wed, 6 Feb 2013 10:56:41 +0100 Subject: [PATCH 03/57] use own ScreenList() call instead of using parents to access it --- openlp/plugins/presentations/lib/impresscontroller.py | 3 ++- openlp/plugins/presentations/lib/powerpointcontroller.py | 4 ++-- openlp/plugins/presentations/lib/pptviewcontroller.py | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/openlp/plugins/presentations/lib/impresscontroller.py b/openlp/plugins/presentations/lib/impresscontroller.py index c19653b78..dfb8ad955 100644 --- a/openlp/plugins/presentations/lib/impresscontroller.py +++ b/openlp/plugins/presentations/lib/impresscontroller.py @@ -58,6 +58,7 @@ else: from PyQt4 import QtCore +from openlp.core.lib import ScreenList from openlp.core.utils import delete_file, get_uno_command, get_uno_instance from presentationcontroller import PresentationController, PresentationDocument @@ -254,7 +255,7 @@ class ImpressDocument(PresentationDocument): window = self.document.getCurrentController().getFrame().getContainerWindow() window.setVisible(False) self.presentation = self.document.getPresentation() - self.presentation.Display = self.controller.plugin.renderer.screens.current[u'number'] + 1 + self.presentation.Display = ScreenList().current[u'number'] + 1 self.control = None self.create_thumbnails() return True diff --git a/openlp/plugins/presentations/lib/powerpointcontroller.py b/openlp/plugins/presentations/lib/powerpointcontroller.py index d62465ee7..7a9f548ee 100644 --- a/openlp/plugins/presentations/lib/powerpointcontroller.py +++ b/openlp/plugins/presentations/lib/powerpointcontroller.py @@ -36,6 +36,7 @@ if os.name == u'nt': import win32ui import pywintypes +from openlp.core.lib import ScreenList from presentationcontroller import PresentationController, PresentationDocument log = logging.getLogger(__name__) @@ -252,8 +253,7 @@ class PowerpointDocument(PresentationDocument): dpi = win32ui.GetForegroundWindow().GetDC().GetDeviceCaps(88) except win32ui.error: dpi = 96 - renderer = self.controller.plugin.renderer - rect = renderer.screens.current[u'size'] + rect = ScreenList().current[u'size'] ppt_window = self.presentation.SlideShowSettings.Run() if not ppt_window: return diff --git a/openlp/plugins/presentations/lib/pptviewcontroller.py b/openlp/plugins/presentations/lib/pptviewcontroller.py index ec3adebe4..af66f623d 100644 --- a/openlp/plugins/presentations/lib/pptviewcontroller.py +++ b/openlp/plugins/presentations/lib/pptviewcontroller.py @@ -34,6 +34,7 @@ if os.name == u'nt': from ctypes import cdll from ctypes.wintypes import RECT +from openlp.core.lib import ScreenList from presentationcontroller import PresentationController, PresentationDocument log = logging.getLogger(__name__) @@ -120,8 +121,7 @@ class PptviewDocument(PresentationDocument): PptView task started earlier. """ log.debug(u'LoadPresentation') - renderer = self.controller.plugin.renderer - rect = renderer.screens.current[u'size'] + rect = ScreenList().current[u'size'] rect = RECT(rect.x(), rect.y(), rect.right(), rect.bottom()) filepath = str(self.filepath.replace(u'/', u'\\')) if not os.path.isdir(self.get_temp_folder()): From 022f0e0184b7f689ba598e1deb90dea203dc1d1f Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Wed, 6 Feb 2013 18:36:36 +0100 Subject: [PATCH 04/57] started with tests --- tests/functional/openlp_core_lib/test_lib.py | 98 +++++++++++++++++++- 1 file changed, 93 insertions(+), 5 deletions(-) diff --git a/tests/functional/openlp_core_lib/test_lib.py b/tests/functional/openlp_core_lib/test_lib.py index 176197e24..8c1f87852 100644 --- a/tests/functional/openlp_core_lib/test_lib.py +++ b/tests/functional/openlp_core_lib/test_lib.py @@ -7,7 +7,7 @@ from datetime import datetime, timedelta from mock import MagicMock, patch from openlp.core.lib import str_to_bool, translate, check_directory_exists, get_text_file_string, build_icon, \ - image_to_byte, check_item_selected, validate_thumb + image_to_byte, check_item_selected, validate_thumb, create_separated_list class TestLib(TestCase): @@ -308,14 +308,14 @@ class TestLib(TestCase): file_path = u'path/to/file' thumb_path = u'path/to/thumb' mocked_os.path.exists.return_value = False - + # WHEN: we run the validate_thumb() function result = validate_thumb(file_path, thumb_path) - + # THEN: we should have called a few functions, and the result should be False mocked_os.path.exists.assert_called_with(thumb_path) assert result is False, u'The result should be False' - + def validate_thumb_file_exists_and_newer_test(self): """ Test the validate_thumb() function when the thumbnail exists and has a newer timestamp than the file @@ -350,7 +350,7 @@ class TestLib(TestCase): thumb_mocked_stat.st_mtime = datetime.now() - timedelta(seconds=10) mocked_os.path.exists.return_value = True mocked_os.stat.side_effect = lambda fname: file_mocked_stat if fname == file_path else thumb_mocked_stat - + # WHEN: we run the validate_thumb() function result = validate_thumb(file_path, thumb_path) @@ -359,3 +359,91 @@ class TestLib(TestCase): mocked_os.stat.assert_any_call(file_path) mocked_os.stat.assert_any_call(thumb_path) assert result is False, u'The result should be False' + + def create_separated_list_qlocate_test(self): + """ + """ + with patch(u'openlp.core.lib.Qt.PYQT_VERSION_STR') as pyqt_version, \ + patch(u'openlp.core.lib.Qt.qVersion') as qt_version: + pyqt_version.return_value = u'4.9' + qt_version.return_value = u'4.8' + # GIVEN: A list of strings. + string_list = [u'Author 1', u'Author 2', u'Author 3'] + + # WHEN: We get a string build from the entries it the list and a seperator. + string_result = create_separated_list(string_list) + + # THEN: + assert string_result == u'Author 1, Author 2, and Author 3', u'The string should be u\'Author 1, ' \ + 'Author 2, and Author 3\'.' + + def create_separated_list_empty_list_test(self): + """ + """ + with patch(u'openlp.core.lib.Qt.PYQT_VERSION_STR') as pyqt_version, \ + patch(u'openlp.core.lib.Qt.qVersion') as qt_version: + pyqt_version.return_value = u'3.0' + qt_version.return_value = u'3.0' + # GIVEN: A list of strings. + string_list = [] + + # WHEN: We get a string build from the entries it the list and a seperator. + string_result = create_separated_list(string_list) + + # THEN: + assert string_result == u'', u'The string sould be empty.' + + def create_separated_list_with_one_item_test(self): + """ + """ + with patch(u'openlp.core.lib.Qt.PYQT_VERSION_STR') as pyqt_version, \ + patch(u'openlp.core.lib.Qt.qVersion') as qt_version: + pyqt_version.return_value = u'3.0' + qt_version.return_value = u'3.0' + # GIVEN: A list of strings. + string_list = [u'Author 1'] + + # WHEN: We get a string build from the entries it the list and a seperator. + string_result = create_separated_list(string_list) + + # THEN: + assert string_result == u'Author 1', u'The string should be u\'Author 1\'.' + + def create_separated_list_with_two_items_test(self): + """ + """ + with patch(u'openlp.core.lib.Qt.PYQT_VERSION_STR') as pyqt_version, \ + patch(u'openlp.core.lib.Qt.qVersion') as qt_version, \ + patch(u'openlp.core.lib.translate') as mocked_translate: + pyqt_version.return_value = u'3.0' + qt_version.return_value = u'3.0' + mocked_translate.return_value = u'%s and %s' + # GIVEN: A list of strings. + string_list = [u'Author 1', u'Author 2'] + + # WHEN: We get a string build from the entries it the list and a seperator. + string_result = create_separated_list(string_list) + + # THEN: + assert string_result == u'Author 1 and Author 2', u'The string should be u\'Author 1 and Author 2\'.' + + def create_separated_list_with_three_items_test(self): + """ + """ + with patch(u'openlp.core.lib.Qt.PYQT_VERSION_STR') as pyqt_version, \ + patch(u'openlp.core.lib.Qt.qVersion') as qt_version, \ + patch(u'openlp.core.lib.translate') as mocked_translate: + # I need two translate functions returning two different things! + mocked_translate.return_value = u'' + pyqt_version.return_value = u'3.0' + qt_version.return_value = u'3.0' + # GIVEN: A list of strings. + string_list = [u'Author 1', u'Author 2', u'Author 3'] + + # WHEN: We get a string build from the entries it the list and a seperator. + string_result = create_separated_list(string_list) + + # THEN: + assert string_result == u'Author 1, Author 2 and Author 3', u'The string should be u\'Author 1, ' \ + 'Author 2 and Author 3\'.' + From 2c8f0e66b2887680e1128a52b92d728769f01e4e Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Wed, 6 Feb 2013 20:45:11 +0100 Subject: [PATCH 05/57] comleted tests --- tests/functional/openlp_core_lib/test_lib.py | 54 ++++++++++---------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/tests/functional/openlp_core_lib/test_lib.py b/tests/functional/openlp_core_lib/test_lib.py index 8c1f87852..aa3291d78 100644 --- a/tests/functional/openlp_core_lib/test_lib.py +++ b/tests/functional/openlp_core_lib/test_lib.py @@ -363,16 +363,20 @@ class TestLib(TestCase): def create_separated_list_qlocate_test(self): """ """ - with patch(u'openlp.core.lib.Qt.PYQT_VERSION_STR') as pyqt_version, \ - patch(u'openlp.core.lib.Qt.qVersion') as qt_version: - pyqt_version.return_value = u'4.9' - qt_version.return_value = u'4.8' + with patch(u'openlp.core.lib.Qt') as mocked_QT, \ + patch(u'openlp.core.lib.QtCore.QLocale.createSeparatedList') as mocked_createSeparatedList: + mocked_QT.PYQT_VERSION_STR = u'4.9' + mocked_QT.qVersion.return_value = u'4.8' + mocked_createSeparatedList.return_value = u'Author 1, Author 2, and Author 3' + # GIVEN: A list of strings. string_list = [u'Author 1', u'Author 2', u'Author 3'] # WHEN: We get a string build from the entries it the list and a seperator. string_result = create_separated_list(string_list) + print string_result + # THEN: assert string_result == u'Author 1, Author 2, and Author 3', u'The string should be u\'Author 1, ' \ 'Author 2, and Author 3\'.' @@ -380,10 +384,10 @@ class TestLib(TestCase): def create_separated_list_empty_list_test(self): """ """ - with patch(u'openlp.core.lib.Qt.PYQT_VERSION_STR') as pyqt_version, \ - patch(u'openlp.core.lib.Qt.qVersion') as qt_version: - pyqt_version.return_value = u'3.0' - qt_version.return_value = u'3.0' + with patch(u'openlp.core.lib.Qt') as mocked_QT: + mocked_QT.PYQT_VERSION_STR = u'4.8' + mocked_QT.qVersion.return_value = u'4.7' + # GIVEN: A list of strings. string_list = [] @@ -396,10 +400,10 @@ class TestLib(TestCase): def create_separated_list_with_one_item_test(self): """ """ - with patch(u'openlp.core.lib.Qt.PYQT_VERSION_STR') as pyqt_version, \ - patch(u'openlp.core.lib.Qt.qVersion') as qt_version: - pyqt_version.return_value = u'3.0' - qt_version.return_value = u'3.0' + with patch(u'openlp.core.lib.Qt') as mocked_QT: + mocked_QT.PYQT_VERSION_STR = u'4.8' + mocked_QT.qVersion.return_value = u'4.7' + # GIVEN: A list of strings. string_list = [u'Author 1'] @@ -412,12 +416,11 @@ class TestLib(TestCase): def create_separated_list_with_two_items_test(self): """ """ - with patch(u'openlp.core.lib.Qt.PYQT_VERSION_STR') as pyqt_version, \ - patch(u'openlp.core.lib.Qt.qVersion') as qt_version, \ - patch(u'openlp.core.lib.translate') as mocked_translate: - pyqt_version.return_value = u'3.0' - qt_version.return_value = u'3.0' + with patch(u'openlp.core.lib.Qt') as mocked_QT, patch(u'openlp.core.lib.translate') as mocked_translate: + mocked_QT.PYQT_VERSION_STR = u'4.8' + mocked_QT.qVersion.return_value = u'4.7' mocked_translate.return_value = u'%s and %s' + # GIVEN: A list of strings. string_list = [u'Author 1', u'Author 2'] @@ -430,13 +433,11 @@ class TestLib(TestCase): def create_separated_list_with_three_items_test(self): """ """ - with patch(u'openlp.core.lib.Qt.PYQT_VERSION_STR') as pyqt_version, \ - patch(u'openlp.core.lib.Qt.qVersion') as qt_version, \ - patch(u'openlp.core.lib.translate') as mocked_translate: - # I need two translate functions returning two different things! - mocked_translate.return_value = u'' - pyqt_version.return_value = u'3.0' - qt_version.return_value = u'3.0' + with patch(u'openlp.core.lib.Qt') as mocked_QT, patch(u'openlp.core.lib.translate') as mocked_translate: + mocked_translate.side_effect = lambda module, string_to_translate, comment: string_to_translate + mocked_QT.PYQT_VERSION_STR = u'4.8' + mocked_QT.qVersion.return_value = u'4.7' + # GIVEN: A list of strings. string_list = [u'Author 1', u'Author 2', u'Author 3'] @@ -444,6 +445,5 @@ class TestLib(TestCase): string_result = create_separated_list(string_list) # THEN: - assert string_result == u'Author 1, Author 2 and Author 3', u'The string should be u\'Author 1, ' \ - 'Author 2 and Author 3\'.' - + assert string_result == u'Author 1, Author 2, and Author 3', u'The string should be u\'Author 1, ' \ + 'Author 2, and Author 3\'.' From 818bd4a4353553aedb036ecebee880031f66ff33 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Wed, 6 Feb 2013 20:49:39 +0100 Subject: [PATCH 06/57] fixed version number compare --- openlp/core/lib/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/openlp/core/lib/__init__.py b/openlp/core/lib/__init__.py index ca8a46126..d7b5ef8b5 100644 --- a/openlp/core/lib/__init__.py +++ b/openlp/core/lib/__init__.py @@ -30,6 +30,7 @@ The :mod:`lib` module contains most of the components and libraries that make OpenLP work. """ +from distutils.version import LooseVersion import logging import os @@ -366,7 +367,8 @@ def create_separated_list(stringlist): ``stringlist`` List of unicode strings """ - if Qt.PYQT_VERSION_STR >= u'4.9' and Qt.qVersion() >= u'4.8': + if LooseVersion(Qt.PYQT_VERSION_STR) >= LooseVersion(u'4.9') and \ + LooseVersion(Qt.qVersion()) >= LooseVersion(u'4.8'): return QtCore.QLocale().createSeparatedList(stringlist) if not stringlist: return u'' From fe74e66400695264febd743f791b588d58fe0ac0 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Wed, 6 Feb 2013 20:55:28 +0100 Subject: [PATCH 07/57] docs ;) --- tests/functional/openlp_core_lib/test_lib.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/functional/openlp_core_lib/test_lib.py b/tests/functional/openlp_core_lib/test_lib.py index aa3291d78..e78f78c0d 100644 --- a/tests/functional/openlp_core_lib/test_lib.py +++ b/tests/functional/openlp_core_lib/test_lib.py @@ -362,6 +362,7 @@ class TestLib(TestCase): def create_separated_list_qlocate_test(self): """ + Test the create_separated_list function using the Qt provided method. """ with patch(u'openlp.core.lib.Qt') as mocked_QT, \ patch(u'openlp.core.lib.QtCore.QLocale.createSeparatedList') as mocked_createSeparatedList: @@ -383,6 +384,7 @@ class TestLib(TestCase): def create_separated_list_empty_list_test(self): """ + Test the create_separated_list function with an empty list. """ with patch(u'openlp.core.lib.Qt') as mocked_QT: mocked_QT.PYQT_VERSION_STR = u'4.8' @@ -399,6 +401,7 @@ class TestLib(TestCase): def create_separated_list_with_one_item_test(self): """ + Test the create_separated_list function with a list consisting of only one entry. """ with patch(u'openlp.core.lib.Qt') as mocked_QT: mocked_QT.PYQT_VERSION_STR = u'4.8' @@ -415,6 +418,7 @@ class TestLib(TestCase): def create_separated_list_with_two_items_test(self): """ + Test the create_separated_list function with a list of two entries. """ with patch(u'openlp.core.lib.Qt') as mocked_QT, patch(u'openlp.core.lib.translate') as mocked_translate: mocked_QT.PYQT_VERSION_STR = u'4.8' @@ -432,6 +436,7 @@ class TestLib(TestCase): def create_separated_list_with_three_items_test(self): """ + Test the create_separated_list function with a list of three items. """ with patch(u'openlp.core.lib.Qt') as mocked_QT, patch(u'openlp.core.lib.translate') as mocked_translate: mocked_translate.side_effect = lambda module, string_to_translate, comment: string_to_translate From 4c2bc4667375e06f4feefadd9b66d5e5cd90afcc Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Wed, 6 Feb 2013 21:36:59 +0100 Subject: [PATCH 08/57] added nose to checkdependencies script --- scripts/check_dependencies.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/scripts/check_dependencies.py b/scripts/check_dependencies.py index be15414b4..4b56acb63 100755 --- a/scripts/check_dependencies.py +++ b/scripts/check_dependencies.py @@ -40,6 +40,12 @@ import os import sys from distutils.version import LooseVersion +# If we import uno before nose this will greate a warning. Just try to import nose first to supress the warning. +try: + import nose +except ImportError: + pass + is_win = sys.platform.startswith('win') VERS = { @@ -85,6 +91,7 @@ OPTIONAL_MODULES = [ ('MySQLdb', ' (MySQL support)'), ('psycopg2', ' (PostgreSQL support)'), ('pytest', ' (testing framework)'), + ('nose', ' (testing framework)'), ] w = sys.stdout.write From 1fc779e8ed3faf8cdc390fb0e42eb1c2c39e0e08 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Wed, 6 Feb 2013 21:37:30 +0100 Subject: [PATCH 09/57] use CAPS --- scripts/check_dependencies.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/check_dependencies.py b/scripts/check_dependencies.py index 4b56acb63..2035d1bb0 100755 --- a/scripts/check_dependencies.py +++ b/scripts/check_dependencies.py @@ -46,7 +46,7 @@ try: except ImportError: pass -is_win = sys.platform.startswith('win') +IS_WIN = sys.platform.startswith('win') VERS = { 'Python': '2.6', @@ -54,7 +54,7 @@ VERS = { 'Qt4': '4.6', 'sqlalchemy': '0.5', # pyenchant 1.6 required on Windows - 'enchant': '1.6' if is_win else '1.3' + 'enchant': '1.6' if IS_WIN else '1.3' } # pywin32 @@ -183,7 +183,7 @@ def main(): for m in OPTIONAL_MODULES: check_module(m[0], text=m[1]) - if is_win: + if IS_WIN: print('Checking for Windows specific modules...') for m in WIN32_MODULES: check_module(m) From 47fa8209ba9c5e9d47cc124e95e811f7188070c7 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Wed, 6 Feb 2013 21:42:09 +0100 Subject: [PATCH 10/57] changed wording --- scripts/check_dependencies.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/check_dependencies.py b/scripts/check_dependencies.py index 2035d1bb0..52b832c48 100755 --- a/scripts/check_dependencies.py +++ b/scripts/check_dependencies.py @@ -40,7 +40,7 @@ import os import sys from distutils.version import LooseVersion -# If we import uno before nose this will greate a warning. Just try to import nose first to supress the warning. +# If we try to import uno before nose this will greate a warning. Just try to import nose first to supress the warning. try: import nose except ImportError: From ed38ba35192763c36728a2eb01ea613516b52254 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Wed, 6 Feb 2013 21:47:57 +0100 Subject: [PATCH 11/57] fixed comments --- tests/functional/openlp_core_lib/test_lib.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/functional/openlp_core_lib/test_lib.py b/tests/functional/openlp_core_lib/test_lib.py index e78f78c0d..b05eb8da6 100644 --- a/tests/functional/openlp_core_lib/test_lib.py +++ b/tests/functional/openlp_core_lib/test_lib.py @@ -378,7 +378,7 @@ class TestLib(TestCase): print string_result - # THEN: + # THEN: We should have "Author 1, Author 2, and Author 3" assert string_result == u'Author 1, Author 2, and Author 3', u'The string should be u\'Author 1, ' \ 'Author 2, and Author 3\'.' @@ -396,7 +396,7 @@ class TestLib(TestCase): # WHEN: We get a string build from the entries it the list and a seperator. string_result = create_separated_list(string_list) - # THEN: + # THEN: We shoud have an emptry string. assert string_result == u'', u'The string sould be empty.' def create_separated_list_with_one_item_test(self): @@ -413,7 +413,7 @@ class TestLib(TestCase): # WHEN: We get a string build from the entries it the list and a seperator. string_result = create_separated_list(string_list) - # THEN: + # THEN: We should have "Author 1" assert string_result == u'Author 1', u'The string should be u\'Author 1\'.' def create_separated_list_with_two_items_test(self): @@ -431,7 +431,7 @@ class TestLib(TestCase): # WHEN: We get a string build from the entries it the list and a seperator. string_result = create_separated_list(string_list) - # THEN: + # THEN: We should have "Author 1 and Author 2" assert string_result == u'Author 1 and Author 2', u'The string should be u\'Author 1 and Author 2\'.' def create_separated_list_with_three_items_test(self): @@ -449,6 +449,6 @@ class TestLib(TestCase): # WHEN: We get a string build from the entries it the list and a seperator. string_result = create_separated_list(string_list) - # THEN: + # THEN: We should have "Author 1, Author 2, and Author 3" assert string_result == u'Author 1, Author 2, and Author 3', u'The string should be u\'Author 1, ' \ 'Author 2, and Author 3\'.' From 396d0b1cd20a0e79017a44b00d458d0747f36d9b Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Wed, 6 Feb 2013 22:39:52 +0100 Subject: [PATCH 12/57] remove pytest and renamed mocked function --- scripts/check_dependencies.py | 1 - tests/functional/openlp_core_lib/test_lib.py | 30 ++++++++++---------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/scripts/check_dependencies.py b/scripts/check_dependencies.py index 52b832c48..3485b8505 100755 --- a/scripts/check_dependencies.py +++ b/scripts/check_dependencies.py @@ -90,7 +90,6 @@ OPTIONAL_MODULES = [ ('sqlite', ' (SQLite 2 support)'), ('MySQLdb', ' (MySQL support)'), ('psycopg2', ' (PostgreSQL support)'), - ('pytest', ' (testing framework)'), ('nose', ' (testing framework)'), ] diff --git a/tests/functional/openlp_core_lib/test_lib.py b/tests/functional/openlp_core_lib/test_lib.py index b05eb8da6..6035085e4 100644 --- a/tests/functional/openlp_core_lib/test_lib.py +++ b/tests/functional/openlp_core_lib/test_lib.py @@ -364,10 +364,10 @@ class TestLib(TestCase): """ Test the create_separated_list function using the Qt provided method. """ - with patch(u'openlp.core.lib.Qt') as mocked_QT, \ + with patch(u'openlp.core.lib.Qt') as mocked_qt, \ patch(u'openlp.core.lib.QtCore.QLocale.createSeparatedList') as mocked_createSeparatedList: - mocked_QT.PYQT_VERSION_STR = u'4.9' - mocked_QT.qVersion.return_value = u'4.8' + mocked_qt.PYQT_VERSION_STR = u'4.9' + mocked_qt.qVersion.return_value = u'4.8' mocked_createSeparatedList.return_value = u'Author 1, Author 2, and Author 3' # GIVEN: A list of strings. @@ -386,9 +386,9 @@ class TestLib(TestCase): """ Test the create_separated_list function with an empty list. """ - with patch(u'openlp.core.lib.Qt') as mocked_QT: - mocked_QT.PYQT_VERSION_STR = u'4.8' - mocked_QT.qVersion.return_value = u'4.7' + with patch(u'openlp.core.lib.Qt') as mocked_qt: + mocked_qt.PYQT_VERSION_STR = u'4.8' + mocked_qt.qVersion.return_value = u'4.7' # GIVEN: A list of strings. string_list = [] @@ -403,9 +403,9 @@ class TestLib(TestCase): """ Test the create_separated_list function with a list consisting of only one entry. """ - with patch(u'openlp.core.lib.Qt') as mocked_QT: - mocked_QT.PYQT_VERSION_STR = u'4.8' - mocked_QT.qVersion.return_value = u'4.7' + with patch(u'openlp.core.lib.Qt') as mocked_qt: + mocked_qt.PYQT_VERSION_STR = u'4.8' + mocked_qt.qVersion.return_value = u'4.7' # GIVEN: A list of strings. string_list = [u'Author 1'] @@ -420,9 +420,9 @@ class TestLib(TestCase): """ Test the create_separated_list function with a list of two entries. """ - with patch(u'openlp.core.lib.Qt') as mocked_QT, patch(u'openlp.core.lib.translate') as mocked_translate: - mocked_QT.PYQT_VERSION_STR = u'4.8' - mocked_QT.qVersion.return_value = u'4.7' + with patch(u'openlp.core.lib.Qt') as mocked_qt, patch(u'openlp.core.lib.translate') as mocked_translate: + mocked_qt.PYQT_VERSION_STR = u'4.8' + mocked_qt.qVersion.return_value = u'4.7' mocked_translate.return_value = u'%s and %s' # GIVEN: A list of strings. @@ -438,10 +438,10 @@ class TestLib(TestCase): """ Test the create_separated_list function with a list of three items. """ - with patch(u'openlp.core.lib.Qt') as mocked_QT, patch(u'openlp.core.lib.translate') as mocked_translate: + with patch(u'openlp.core.lib.Qt') as mocked_qt, patch(u'openlp.core.lib.translate') as mocked_translate: mocked_translate.side_effect = lambda module, string_to_translate, comment: string_to_translate - mocked_QT.PYQT_VERSION_STR = u'4.8' - mocked_QT.qVersion.return_value = u'4.7' + mocked_qt.PYQT_VERSION_STR = u'4.8' + mocked_qt.qVersion.return_value = u'4.7' # GIVEN: A list of strings. string_list = [u'Author 1', u'Author 2', u'Author 3'] From 947cfce93184e9d748c8f456fc2588f6a166bf83 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Wed, 6 Feb 2013 22:50:55 +0100 Subject: [PATCH 13/57] cough... --- tests/functional/openlp_core_lib/test_lib.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/functional/openlp_core_lib/test_lib.py b/tests/functional/openlp_core_lib/test_lib.py index 6035085e4..568051980 100644 --- a/tests/functional/openlp_core_lib/test_lib.py +++ b/tests/functional/openlp_core_lib/test_lib.py @@ -376,8 +376,6 @@ class TestLib(TestCase): # WHEN: We get a string build from the entries it the list and a seperator. string_result = create_separated_list(string_list) - print string_result - # THEN: We should have "Author 1, Author 2, and Author 3" assert string_result == u'Author 1, Author 2, and Author 3', u'The string should be u\'Author 1, ' \ 'Author 2, and Author 3\'.' From 589d335d3941a6b3b43c6e68a482cc8c055a112c Mon Sep 17 00:00:00 2001 From: phill-ridout Date: Thu, 7 Feb 2013 21:55:22 +0000 Subject: [PATCH 14/57] Changed filerenamefor to registry. Started on test for filerenameform --- openlp/core/ui/filerenameform.py | 16 +++++++++++++--- openlp/core/ui/thememanager.py | 2 +- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/openlp/core/ui/filerenameform.py b/openlp/core/ui/filerenameform.py index ccdca9928..934a8dee8 100644 --- a/openlp/core/ui/filerenameform.py +++ b/openlp/core/ui/filerenameform.py @@ -34,18 +34,18 @@ from PyQt4 import QtGui from filerenamedialog import Ui_FileRenameDialog -from openlp.core.lib import translate +from openlp.core.lib import translate, Registry class FileRenameForm(QtGui.QDialog, Ui_FileRenameDialog): """ The file rename dialog """ - def __init__(self, parent): + def __init__(self): """ Constructor """ - QtGui.QDialog.__init__(self, parent) + QtGui.QDialog.__init__(self, self.main_window) self.setupUi(self) def exec_(self, copy=False): @@ -58,3 +58,13 @@ class FileRenameForm(QtGui.QDialog, Ui_FileRenameDialog): self.setWindowTitle(translate('OpenLP.FileRenameForm', 'File Rename')) self.fileNameEdit.setFocus() return QtGui.QDialog.exec_(self) + + def _get_main_window(self): + """ + Adds the main window to the class dynamically + """ + if not hasattr(self, u'_main_window'): + self._main_window = Registry().get(u'main_window') + return self._main_window + + main_window = property(_get_main_window) diff --git a/openlp/core/ui/thememanager.py b/openlp/core/ui/thememanager.py index a482a3c44..666f80dbe 100644 --- a/openlp/core/ui/thememanager.py +++ b/openlp/core/ui/thememanager.py @@ -62,7 +62,7 @@ class ThemeManager(QtGui.QWidget): Registry().register(u'theme_manager', self) self.settingsSection = u'themes' self.themeForm = ThemeForm(self) - self.fileRenameForm = FileRenameForm(self) + self.fileRenameForm = FileRenameForm() # start with the layout self.layout = QtGui.QVBoxLayout(self) self.layout.setSpacing(0) From e1552ddce19c23acd957de4aa58042e869041526 Mon Sep 17 00:00:00 2001 From: phill-ridout Date: Fri, 8 Feb 2013 19:13:18 +0000 Subject: [PATCH 15/57] actually added test file --- .../openlp_core_ui/test_filerenamedialog.py | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 tests/interfaces/openlp_core_ui/test_filerenamedialog.py diff --git a/tests/interfaces/openlp_core_ui/test_filerenamedialog.py b/tests/interfaces/openlp_core_ui/test_filerenamedialog.py new file mode 100644 index 000000000..cc4f2b1c5 --- /dev/null +++ b/tests/interfaces/openlp_core_ui/test_filerenamedialog.py @@ -0,0 +1,83 @@ +""" + Package to test the openlp.core.ui package. +""" +from unittest import TestCase + +from mock import patch +from openlp.core.lib import Registry +from openlp.core.ui import filerenameform +from PyQt4 import QtCore, QtGui, QtTest + +class TestStartFileRenameForm(TestCase): + + def setUp(self): + """ + Create the UI + """ + registry = Registry.create() + self.app = QtGui.QApplication([]) + self.main_window = QtGui.QMainWindow() + Registry().register(u'main_window', self.main_window) + self.form = filerenameform.FileRenameForm() + + def tearDown(self): + """ + Delete all the C++ objects at the end so that we don't have a segfault + """ + del self.form + del self.main_window + del self.app + + def basic_display_test(self): + """ + Test FileRenameForm functionality + """ + # GIVEN: FileRenameForm with no ARGS + + # WHEN displaying the UI + with patch(u'PyQt4.QtGui.QDialog') as mocked_exec: + self.form.exec_() + + # THEN the window title is set as + self.assertEqual(self.form.windowTitle(), u'File Rename', u'The window title should be "File Rename"') + + # GIVEN: FileRenameForm with False ARG + false_arg = False + + # WHEN displaying the UI + with patch(u'PyQt4.QtGui.QDialog') as mocked_exec: + self.form.exec_(false_arg) + + # THEN the window title is set as + self.assertEqual(self.form.windowTitle(), u'File Rename', u'The window title should be "File Rename"') + + # GIVEN: FileRenameForm with False ARG + true_arg = True + + # WHEN displaying the UI and pressing enter + with patch(u'PyQt4.QtGui.QDialog') as mocked_exec: + self.form.exec_(true_arg) + + # THEN the window title is set as + self.assertEqual(self.form.windowTitle(), u'File Copy', u'The window title should be "File Copy"') + + # GIVEN: FileRenameForm with defaults + + # WHEN displaying the UI + with patch(u'PyQt4.QtGui.QDialog') as mocked_exec: + self.form.exec_() + + # THEN the lineEdit should have focus + self.assertEqual(self.form.fileNameEdit.hasFocus(), True, u'fileNameEdit should have focus.') + + + + # Regression test for bug1067251 + # GIVEN: FileRenameForm with defaults + + # WHEN displaying the UI + # with patch(u'PyQt4.QtGui.QDialog') as mocked_exec: + # self.form.exec_() + + # THEN the lineEdit should have focus + #self.assertEqual(self.form.fileNameEdit.hasFocus(), u'File Rename', u'The window title should be "File Rename"') \ No newline at end of file From 7d7da00848bedb375f2557b611b0e2fc00079b4f Mon Sep 17 00:00:00 2001 From: phill-ridout Date: Fri, 8 Feb 2013 21:49:26 +0000 Subject: [PATCH 16/57] made changes according to Superfly's instructions. --- tests/interfaces/openlp_core_ui/test_filerenamedialog.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/interfaces/openlp_core_ui/test_filerenamedialog.py b/tests/interfaces/openlp_core_ui/test_filerenamedialog.py index cc4f2b1c5..0f5cfb9cf 100644 --- a/tests/interfaces/openlp_core_ui/test_filerenamedialog.py +++ b/tests/interfaces/openlp_core_ui/test_filerenamedialog.py @@ -35,7 +35,7 @@ class TestStartFileRenameForm(TestCase): # GIVEN: FileRenameForm with no ARGS # WHEN displaying the UI - with patch(u'PyQt4.QtGui.QDialog') as mocked_exec: + with patch(u'PyQt4.QtGui.QDialog.exec_') as mocked_exec: self.form.exec_() # THEN the window title is set as @@ -45,7 +45,7 @@ class TestStartFileRenameForm(TestCase): false_arg = False # WHEN displaying the UI - with patch(u'PyQt4.QtGui.QDialog') as mocked_exec: + with patch(u'PyQt4.QtGui.QDialog.exec_') as mocked_exec: self.form.exec_(false_arg) # THEN the window title is set as @@ -55,7 +55,7 @@ class TestStartFileRenameForm(TestCase): true_arg = True # WHEN displaying the UI and pressing enter - with patch(u'PyQt4.QtGui.QDialog') as mocked_exec: + with patch(u'PyQt4.QtGui.QDialog.exec_') as mocked_exec: self.form.exec_(true_arg) # THEN the window title is set as @@ -64,7 +64,7 @@ class TestStartFileRenameForm(TestCase): # GIVEN: FileRenameForm with defaults # WHEN displaying the UI - with patch(u'PyQt4.QtGui.QDialog') as mocked_exec: + with patch(u'PyQt4.QtGui.QDialog.exec_') as mocked_exec: self.form.exec_() # THEN the lineEdit should have focus From 7f3c18f0a04e2c55b8b8f87f215034b7ecbe5464 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Sat, 9 Feb 2013 16:20:29 +0100 Subject: [PATCH 17/57] fixed regression --- openlp/plugins/alerts/lib/alertsmanager.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/openlp/plugins/alerts/lib/alertsmanager.py b/openlp/plugins/alerts/lib/alertsmanager.py index ab0f7c1d9..42a28eee1 100644 --- a/openlp/plugins/alerts/lib/alertsmanager.py +++ b/openlp/plugins/alerts/lib/alertsmanager.py @@ -35,7 +35,7 @@ import logging from PyQt4 import QtCore -from openlp.core.lib import Receiver, translate +from openlp.core.lib import Receiver, translate, Registry log = logging.getLogger(__name__) @@ -87,7 +87,7 @@ class AlertsManager(QtCore.QObject): return text = self.alertList.pop(0) alertTab = self.parent().settingsTab - self.parent().liveController.display.alert(text, alertTab.location) + self.live_controller.display.alert(text, alertTab.location) # Check to see if we have a timer running. if self.timer_id == 0: self.timer_id = self.startTimer(int(alertTab.timeout) * 1000) @@ -103,7 +103,18 @@ class AlertsManager(QtCore.QObject): log.debug(u'timer event') if event.timerId() == self.timer_id: alertTab = self.parent().settingsTab - self.parent().liveController.display.alert(u'', alertTab.location) + self.live_controller.display.alert(u'', alertTab.location) self.killTimer(self.timer_id) self.timer_id = 0 self.generateAlert() + + + def _get_live_controller(self): + """ + Adds the live controller to the class dynamically + """ + if not hasattr(self, u'_live_controller'): + self._live_controller = Registry().get(u'live_controller') + return self._live_controller + + live_controller = property(_get_live_controller) From 17200d85fc94f51f2accf73aa69ea94f14989c87 Mon Sep 17 00:00:00 2001 From: phill-ridout Date: Sat, 9 Feb 2013 21:23:43 +0000 Subject: [PATCH 18/57] some more changes to the test --- .../openlp_core_ui/test_filerenamedialog.py | 66 ++++++++----------- 1 file changed, 26 insertions(+), 40 deletions(-) diff --git a/tests/interfaces/openlp_core_ui/test_filerenamedialog.py b/tests/interfaces/openlp_core_ui/test_filerenamedialog.py index 0f5cfb9cf..9e242f0d5 100644 --- a/tests/interfaces/openlp_core_ui/test_filerenamedialog.py +++ b/tests/interfaces/openlp_core_ui/test_filerenamedialog.py @@ -28,56 +28,42 @@ class TestStartFileRenameForm(TestCase): del self.main_window del self.app - def basic_display_test(self): + def window_title_test(self): """ - Test FileRenameForm functionality + Test the windowTitle of the FileRenameDialog """ - # GIVEN: FileRenameForm with no ARGS - - # WHEN displaying the UI + # GIVEN: A mocked QDialog.exec_() method with patch(u'PyQt4.QtGui.QDialog.exec_') as mocked_exec: + + # WHEN: The form is executed with no args self.form.exec_() - # THEN the window title is set as - self.assertEqual(self.form.windowTitle(), u'File Rename', u'The window title should be "File Rename"') + # THEN: the window title is set correctly + self.assertEqual(self.form.windowTitle(), u'File Rename', u'The window title should be "File Rename"') - # GIVEN: FileRenameForm with False ARG - false_arg = False + # WHEN: The form is executed with False arg + self.form.exec_(False) - # WHEN displaying the UI - with patch(u'PyQt4.QtGui.QDialog.exec_') as mocked_exec: - self.form.exec_(false_arg) + # THEN: the window title is set correctly + self.assertEqual(self.form.windowTitle(), u'File Rename', u'The window title should be "File Rename"') - # THEN the window title is set as - self.assertEqual(self.form.windowTitle(), u'File Rename', u'The window title should be "File Rename"') + # WHEN: The form is executed with True arg + self.form.exec_(True) - # GIVEN: FileRenameForm with False ARG - true_arg = True + # THEN: the window title is set correctly + self.assertEqual(self.form.windowTitle(), u'File Copy', u'The window title should be "File Copy"') - # WHEN displaying the UI and pressing enter - with patch(u'PyQt4.QtGui.QDialog.exec_') as mocked_exec: - self.form.exec_(true_arg) + def line_edit_focus_test(self): + """ + Regression test for bug1067251 + Test that the fileNameEdit setFocus has called with True when executed + """ + # GIVEN: A mocked QLineEdit class + with patch(u'PyQt4.QtGui.QDialog.exec_') as mocked_exec, \ + patch(u'PyQt4.QtGui.QLineEdit') as mocked_line_edit: - # THEN the window title is set as - self.assertEqual(self.form.windowTitle(), u'File Copy', u'The window title should be "File Copy"') - - # GIVEN: FileRenameForm with defaults - - # WHEN displaying the UI - with patch(u'PyQt4.QtGui.QDialog.exec_') as mocked_exec: + # WHEN: The form is executed with no args self.form.exec_() - # THEN the lineEdit should have focus - self.assertEqual(self.form.fileNameEdit.hasFocus(), True, u'fileNameEdit should have focus.') - - - - # Regression test for bug1067251 - # GIVEN: FileRenameForm with defaults - - # WHEN displaying the UI - # with patch(u'PyQt4.QtGui.QDialog') as mocked_exec: - # self.form.exec_() - - # THEN the lineEdit should have focus - #self.assertEqual(self.form.fileNameEdit.hasFocus(), u'File Rename', u'The window title should be "File Rename"') \ No newline at end of file + # THEN: the setFocus method of the fileNameEdit has been called with True + mocked_line_edit.setFocus.assert_called_with() From d0104bf7954b89238544dcf6c96e31b7691d88e6 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Sun, 10 Feb 2013 19:59:00 +0100 Subject: [PATCH 19/57] fixed comments --- tests/functional/openlp_core_lib/test_lib.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/tests/functional/openlp_core_lib/test_lib.py b/tests/functional/openlp_core_lib/test_lib.py index 568051980..8527373dc 100644 --- a/tests/functional/openlp_core_lib/test_lib.py +++ b/tests/functional/openlp_core_lib/test_lib.py @@ -366,11 +366,10 @@ class TestLib(TestCase): """ with patch(u'openlp.core.lib.Qt') as mocked_qt, \ patch(u'openlp.core.lib.QtCore.QLocale.createSeparatedList') as mocked_createSeparatedList: + # GIVEN: A list of strings and the mocked Qt module. mocked_qt.PYQT_VERSION_STR = u'4.9' mocked_qt.qVersion.return_value = u'4.8' mocked_createSeparatedList.return_value = u'Author 1, Author 2, and Author 3' - - # GIVEN: A list of strings. string_list = [u'Author 1', u'Author 2', u'Author 3'] # WHEN: We get a string build from the entries it the list and a seperator. @@ -385,10 +384,9 @@ class TestLib(TestCase): Test the create_separated_list function with an empty list. """ with patch(u'openlp.core.lib.Qt') as mocked_qt: + # GIVEN: An empty list and the mocked Qt module. mocked_qt.PYQT_VERSION_STR = u'4.8' mocked_qt.qVersion.return_value = u'4.7' - - # GIVEN: A list of strings. string_list = [] # WHEN: We get a string build from the entries it the list and a seperator. @@ -402,10 +400,9 @@ class TestLib(TestCase): Test the create_separated_list function with a list consisting of only one entry. """ with patch(u'openlp.core.lib.Qt') as mocked_qt: + # GIVEN: A list with a string and the mocked Qt module. mocked_qt.PYQT_VERSION_STR = u'4.8' mocked_qt.qVersion.return_value = u'4.7' - - # GIVEN: A list of strings. string_list = [u'Author 1'] # WHEN: We get a string build from the entries it the list and a seperator. @@ -419,11 +416,10 @@ class TestLib(TestCase): Test the create_separated_list function with a list of two entries. """ with patch(u'openlp.core.lib.Qt') as mocked_qt, patch(u'openlp.core.lib.translate') as mocked_translate: + # GIVEN: A list of strings and the mocked Qt module. mocked_qt.PYQT_VERSION_STR = u'4.8' mocked_qt.qVersion.return_value = u'4.7' mocked_translate.return_value = u'%s and %s' - - # GIVEN: A list of strings. string_list = [u'Author 1', u'Author 2'] # WHEN: We get a string build from the entries it the list and a seperator. @@ -437,11 +433,11 @@ class TestLib(TestCase): Test the create_separated_list function with a list of three items. """ with patch(u'openlp.core.lib.Qt') as mocked_qt, patch(u'openlp.core.lib.translate') as mocked_translate: - mocked_translate.side_effect = lambda module, string_to_translate, comment: string_to_translate + # GIVEN: A list with a string and the mocked Qt module. mocked_qt.PYQT_VERSION_STR = u'4.8' mocked_qt.qVersion.return_value = u'4.7' - - # GIVEN: A list of strings. + # Always return the untranslated string. + mocked_translate.side_effect = lambda module, string_to_translate, comment: string_to_translate string_list = [u'Author 1', u'Author 2', u'Author 3'] # WHEN: We get a string build from the entries it the list and a seperator. From 75b8ed55fa130fbc317ca597fd02d38153cce957 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Mon, 11 Feb 2013 09:31:46 +0100 Subject: [PATCH 20/57] fixed bug 1047995 by reimplementing the keyPressEvent Fixes: https://launchpad.net/bugs/1047995 --- openlp/plugins/songs/forms/editsongform.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/openlp/plugins/songs/forms/editsongform.py b/openlp/plugins/songs/forms/editsongform.py index 46ea0029c..87f948aa0 100644 --- a/openlp/plugins/songs/forms/editsongform.py +++ b/openlp/plugins/songs/forms/editsongform.py @@ -116,6 +116,23 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): self.findVerseSplit = re.compile(u'---\[\]---\n', re.UNICODE) self.whitespace = re.compile(r'\W+', re.UNICODE) + def keyPressEvent(self, event): + """ + Reimplement the keyPressEvent to react on Return/Enter keys. When some combo boxes have focus we do not want + dialog's default action be triggered but instead our own. + + ``event`` + A QtGui.QKeyEvent event. + """ + if event.key() in (QtCore.Qt.Key_Enter, QtCore.Qt.Key_Return): + if self.authorsComboBox.hasFocus() and self.authorsComboBox.currentText(): + self.onAuthorAddButtonClicked() + return + if self.topicsComboBox.hasFocus() and self.topicsComboBox.currentText(): + self.onTopicAddButtonClicked() + return + QtGui.QDialog.keyPressEvent(self, event) + def initialise(self): """ Set up the form for when it is displayed. From 230c06c83ccc23b7fa06e8bebb20343e9f583d71 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Mon, 11 Feb 2013 11:34:24 +0200 Subject: [PATCH 21/57] Change the importing of plugins to use the "imp" module in an effort to get around the UNO import errors. --- openlp/core/lib/pluginmanager.py | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/openlp/core/lib/pluginmanager.py b/openlp/core/lib/pluginmanager.py index a6fd2a848..be171be21 100644 --- a/openlp/core/lib/pluginmanager.py +++ b/openlp/core/lib/pluginmanager.py @@ -32,6 +32,7 @@ Provide plugin management import os import sys import logging +import imp from openlp.core.lib import Plugin, PluginStatus, Registry @@ -55,11 +56,8 @@ class PluginManager(object): """ log.info(u'Plugin manager Initialising') Registry().register(u'plugin_manager', self) - if not plugin_dir in sys.path: - log.debug(u'Inserting %s into sys.path', plugin_dir) - sys.path.insert(0, plugin_dir) - self.basepath = os.path.abspath(plugin_dir) - log.debug(u'Base path %s ', self.basepath) + self.base_path = os.path.abspath(plugin_dir) + log.debug(u'Base path %s ', self.base_path) self.plugins = [] log.info(u'Plugin manager Initialised') @@ -73,9 +71,8 @@ class PluginManager(object): """ log.info(u'Finding plugins') - startdepth = len(os.path.abspath(plugin_dir).split(os.sep)) - log.debug(u'finding plugins in %s at depth %d', - unicode(plugin_dir), startdepth) + start_depth = len(os.path.abspath(plugin_dir).split(os.sep)) + log.debug(u'finding plugins in %s at depth %d', unicode(plugin_dir), start_depth) for root, dirs, files in os.walk(plugin_dir): # TODO Presentation plugin is not yet working on Mac OS X. # For now just ignore it. The following code will hide it @@ -88,22 +85,20 @@ class PluginManager(object): for name in files: if name.endswith(u'.py') and not name.startswith(u'__'): path = os.path.abspath(os.path.join(root, name)) - thisdepth = len(path.split(os.sep)) - if thisdepth - startdepth > 2: + this_depth = len(path.split(os.sep)) + if this_depth - start_depth > 2: # skip anything lower down break - modulename = os.path.splitext(path)[0] - prefix = os.path.commonprefix([self.basepath, path]) - # hack off the plugin base path - modulename = modulename[len(prefix) + 1:] - modulename = modulename.replace(os.path.sep, '.') + module_name = name[:-3] # import the modules - log.debug(u'Importing %s from %s. Depth %d', modulename, path, thisdepth) + log.debug(u'Importing %s from %s. Depth %d', module_name, root, this_depth) try: - __import__(modulename, globals(), locals(), []) + fp, path_name, description = imp.find_module(module_name, [root]) + imp.load_module(module_name, fp, path_name, description) + #__import__(module_name, globals(), locals(), []) except ImportError, e: log.exception(u'Failed to import module %s on path %s for reason %s', - modulename, path, e.args[0]) + module_name, path, e.args[0]) plugin_classes = Plugin.__subclasses__() plugin_objects = [] for p in plugin_classes: From a2125e09543fd08a656693096d9f04f037e10510 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Mon, 11 Feb 2013 11:43:26 +0200 Subject: [PATCH 22/57] Add some comments to make things clearer. --- openlp/core/lib/pluginmanager.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/openlp/core/lib/pluginmanager.py b/openlp/core/lib/pluginmanager.py index be171be21..6dba74998 100644 --- a/openlp/core/lib/pluginmanager.py +++ b/openlp/core/lib/pluginmanager.py @@ -93,9 +93,12 @@ class PluginManager(object): # import the modules log.debug(u'Importing %s from %s. Depth %d', module_name, root, this_depth) try: + # Use the "imp" library to try to get around a problem with the PyUNO library which + # monkey-patches the __import__ function to do some magic. This causes issues with our tests. + # First, try to find the module we want to import, searching the directory in ``root`` fp, path_name, description = imp.find_module(module_name, [root]) + # Then load the module (do the actual import) using the details from ``find_module()`` imp.load_module(module_name, fp, path_name, description) - #__import__(module_name, globals(), locals(), []) except ImportError, e: log.exception(u'Failed to import module %s on path %s for reason %s', module_name, path, e.args[0]) From f822aed40fd84446216c323365489da86607002e Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Mon, 11 Feb 2013 15:22:13 +0200 Subject: [PATCH 23/57] Add some tests around the PluginManager class. --- openlp/core/lib/pluginmanager.py | 3 +- .../openlp_core_lib/test_pluginmanager.py | 373 ++++++++++++++++++ .../openlp_core_lib/test_registry.py | 8 +- 3 files changed, 380 insertions(+), 4 deletions(-) create mode 100644 tests/functional/openlp_core_lib/test_pluginmanager.py diff --git a/openlp/core/lib/pluginmanager.py b/openlp/core/lib/pluginmanager.py index 6dba74998..cdd99a9e0 100644 --- a/openlp/core/lib/pluginmanager.py +++ b/openlp/core/lib/pluginmanager.py @@ -140,7 +140,8 @@ class PluginManager(object): for plugin in self.plugins: if plugin.status is not PluginStatus.Disabled: plugin.createSettingsTab(settings_form) - settings_form.plugins = self.plugins + if settings_form: + settings_form.plugins = self.plugins def hook_import_menu(self, import_menu): """ diff --git a/tests/functional/openlp_core_lib/test_pluginmanager.py b/tests/functional/openlp_core_lib/test_pluginmanager.py new file mode 100644 index 000000000..3539373e0 --- /dev/null +++ b/tests/functional/openlp_core_lib/test_pluginmanager.py @@ -0,0 +1,373 @@ +""" +Package to test the openlp.core.lib.pluginmanager package. +""" +from unittest import TestCase + +from mock import MagicMock + +from openlp.core.lib.pluginmanager import PluginManager +from openlp.core.lib import Registry, PluginStatus + + +class TestPluginManager(TestCase): + """ + Test the PluginManager class + """ + + def setUp(self): + """ + Some pre-test setup required. + """ + Registry.create() + Registry().register(u'service_list', MagicMock()) + + def hook_media_manager_with_disabled_plugin_test(self): + """ + Test running the hook_media_manager() method with a disabled plugin + """ + # GIVEN: A PluginManager instance and a list with a mocked up plugin whose status is set to Disabled + mocked_plugin = MagicMock() + mocked_plugin.status = PluginStatus.Disabled + plugin_manager = PluginManager('') + plugin_manager.plugins = [mocked_plugin] + + # WHEN: We run hook_media_manager() + plugin_manager.hook_media_manager() + + # THEN: The createMediaManagerItem() method should have been called + assert mocked_plugin.createMediaManagerItem.call_count == 0, \ + u'The createMediaManagerItem() method should not have been called.' + + def hook_media_manager_with_active_plugin_test(self): + """ + Test running the hook_media_manager() method with an active plugin + """ + # GIVEN: A PluginManager instance and a list with a mocked up plugin whose status is set to Active + mocked_plugin = MagicMock() + mocked_plugin.status = PluginStatus.Active + plugin_manager = PluginManager('') + plugin_manager.plugins = [mocked_plugin] + + # WHEN: We run hook_media_manager() + plugin_manager.hook_media_manager() + + # THEN: The createMediaManagerItem() method should have been called + mocked_plugin.createMediaManagerItem.assert_called_with() + + def hook_settings_tabs_with_disabled_plugin_and_no_form_test(self): + """ + Test running the hook_settings_tabs() method with a disabled plugin and no form + """ + # GIVEN: A PluginManager instance and a list with a mocked up plugin whose status is set to Disabled + mocked_plugin = MagicMock() + mocked_plugin.status = PluginStatus.Disabled + plugin_manager = PluginManager('') + plugin_manager.plugins = [mocked_plugin] + + # WHEN: We run hook_settings_tabs() + plugin_manager.hook_settings_tabs() + + # THEN: The createSettingsTab() method should have been called + assert mocked_plugin.createMediaManagerItem.call_count == 0, \ + u'The createMediaManagerItem() method should not have been called.' + + def hook_settings_tabs_with_disabled_plugin_and_mocked_form_test(self): + """ + Test running the hook_settings_tabs() method with a disabled plugin and a mocked form + """ + # GIVEN: A PluginManager instance and a list with a mocked up plugin whose status is set to Disabled + mocked_plugin = MagicMock() + mocked_plugin.status = PluginStatus.Disabled + mocked_settings_form = MagicMock() + plugin_manager = PluginManager('') + plugin_manager.plugins = [mocked_plugin] + + # WHEN: We run hook_settings_tabs() + plugin_manager.hook_settings_tabs(mocked_settings_form) + + # THEN: The createSettingsTab() method should not have been called, but the plugins lists should be the same + assert mocked_plugin.createSettingsTab.call_count == 0, \ + u'The createMediaManagerItem() method should not have been called.' + self.assertEqual(mocked_settings_form.plugins, plugin_manager.plugins, + u'The plugins on the settings form should be the same as the plugins in the plugin manager') + + def hook_settings_tabs_with_active_plugin_and_no_form_test(self): + """ + Test running the hook_settings_tabs() method with an active plugin and no settings form + """ + # GIVEN: A PluginManager instance and a list with a mocked up plugin whose status is set to Active + mocked_plugin = MagicMock() + mocked_plugin.status = PluginStatus.Active + plugin_manager = PluginManager('') + plugin_manager.plugins = [mocked_plugin] + + # WHEN: We run hook_settings_tabs() + plugin_manager.hook_settings_tabs() + + # THEN: The createSettingsTab() method should have been called + mocked_plugin.createSettingsTab.assert_called_with(None) + + def hook_settings_tabs_with_active_plugin_and_mocked_form_test(self): + """ + Test running the hook_settings_tabs() method with an active plugin and a mocked settings form + """ + # GIVEN: A PluginManager instance and a list with a mocked up plugin whose status is set to Active + mocked_plugin = MagicMock() + mocked_plugin.status = PluginStatus.Active + mocked_settings_form = MagicMock() + plugin_manager = PluginManager('') + plugin_manager.plugins = [mocked_plugin] + + # WHEN: We run hook_settings_tabs() + plugin_manager.hook_settings_tabs(mocked_settings_form) + + # THEN: The createMediaManagerItem() method should have been called with the mocked settings form + mocked_plugin.createSettingsTab.assert_called_with(mocked_settings_form) + self.assertEqual(mocked_settings_form.plugins, plugin_manager.plugins, + u'The plugins on the settings form should be the same as the plugins in the plugin manager') + + def hook_import_menu_with_disabled_plugin_test(self): + """ + Test running the hook_import_menu() method with a disabled plugin + """ + # GIVEN: A PluginManager instance and a list with a mocked up plugin whose status is set to Disabled + mocked_plugin = MagicMock() + mocked_plugin.status = PluginStatus.Disabled + mocked_import_menu = MagicMock() + plugin_manager = PluginManager('') + plugin_manager.plugins = [mocked_plugin] + + # WHEN: We run hook_import_menu() + plugin_manager.hook_import_menu(mocked_import_menu) + + # THEN: The createMediaManagerItem() method should have been called + assert mocked_plugin.addImportMenuItem.call_count == 0, \ + u'The addImportMenuItem() method should not have been called.' + + def hook_import_menu_with_active_plugin_test(self): + """ + Test running the hook_import_menu() method with an active plugin + """ + # GIVEN: A PluginManager instance and a list with a mocked up plugin whose status is set to Active + mocked_plugin = MagicMock() + mocked_plugin.status = PluginStatus.Active + mocked_import_menu = MagicMock() + plugin_manager = PluginManager('') + plugin_manager.plugins = [mocked_plugin] + + # WHEN: We run hook_import_menu() + plugin_manager.hook_import_menu(mocked_import_menu) + + # THEN: The addImportMenuItem() method should have been called + mocked_plugin.addImportMenuItem.assert_called_with(mocked_import_menu) + + def hook_export_menu_with_disabled_plugin_test(self): + """ + Test running the hook_export_menu() method with a disabled plugin + """ + # GIVEN: A PluginManager instance and a list with a mocked up plugin whose status is set to Disabled + mocked_plugin = MagicMock() + mocked_plugin.status = PluginStatus.Disabled + mocked_export_menu = MagicMock() + plugin_manager = PluginManager('') + plugin_manager.plugins = [mocked_plugin] + + # WHEN: We run hook_export_menu() + plugin_manager.hook_export_menu(mocked_export_menu) + + # THEN: The addExportMenuItem() method should have been called + assert mocked_plugin.addExportMenuItem.call_count == 0, \ + u'The addExportMenuItem() method should not have been called.' + + def hook_export_menu_with_active_plugin_test(self): + """ + Test running the hook_export_menu() method with an active plugin + """ + # GIVEN: A PluginManager instance and a list with a mocked up plugin whose status is set to Active + mocked_plugin = MagicMock() + mocked_plugin.status = PluginStatus.Active + mocked_export_menu = MagicMock() + plugin_manager = PluginManager('') + plugin_manager.plugins = [mocked_plugin] + + # WHEN: We run hook_export_menu() + plugin_manager.hook_export_menu(mocked_export_menu) + + # THEN: The addExportMenuItem() method should have been called + mocked_plugin.addExportMenuItem.assert_called_with(mocked_export_menu) + + def hook_tools_menu_with_disabled_plugin_test(self): + """ + Test running the hook_tools_menu() method with a disabled plugin + """ + # GIVEN: A PluginManager instance and a list with a mocked up plugin whose status is set to Disabled + mocked_plugin = MagicMock() + mocked_plugin.status = PluginStatus.Disabled + mocked_tools_menu = MagicMock() + plugin_manager = PluginManager('') + plugin_manager.plugins = [mocked_plugin] + + # WHEN: We run hook_tools_menu() + plugin_manager.hook_tools_menu(mocked_tools_menu) + + # THEN: The addToolsMenuItem() method should have been called + assert mocked_plugin.addToolsMenuItem.call_count == 0, \ + u'The addToolsMenuItem() method should not have been called.' + + def hook_tools_menu_with_active_plugin_test(self): + """ + Test running the hook_tools_menu() method with an active plugin + """ + # GIVEN: A PluginManager instance and a list with a mocked up plugin whose status is set to Active + mocked_plugin = MagicMock() + mocked_plugin.status = PluginStatus.Active + mocked_tools_menu = MagicMock() + plugin_manager = PluginManager('') + plugin_manager.plugins = [mocked_plugin] + + # WHEN: We run hook_tools_menu() + plugin_manager.hook_tools_menu(mocked_tools_menu) + + # THEN: The addToolsMenuItem() method should have been called + mocked_plugin.addToolsMenuItem.assert_called_with(mocked_tools_menu) + + def initialise_plugins_with_disabled_plugin_test(self): + """ + Test running the initialise_plugins() method with a disabled plugin + """ + # GIVEN: A PluginManager instance and a list with a mocked up plugin whose status is set to Disabled + mocked_plugin = MagicMock() + mocked_plugin.status = PluginStatus.Disabled + mocked_plugin.isActive.return_value = False + plugin_manager = PluginManager('') + plugin_manager.plugins = [mocked_plugin] + + # WHEN: We run initialise_plugins() + plugin_manager.initialise_plugins() + + # THEN: The isActive() method should have been called, and initialise() method should NOT have been called + mocked_plugin.isActive.assert_called_with() + assert mocked_plugin.initialise.call_count == 0, u'The initialise() method should not have been called.' + + def initialise_plugins_with_active_plugin_test(self): + """ + Test running the initialise_plugins() method with an active plugin + """ + # GIVEN: A PluginManager instance and a list with a mocked up plugin whose status is set to Active + mocked_plugin = MagicMock() + mocked_plugin.status = PluginStatus.Active + mocked_plugin.isActive.return_value = True + plugin_manager = PluginManager('') + plugin_manager.plugins = [mocked_plugin] + + # WHEN: We run initialise_plugins() + plugin_manager.initialise_plugins() + + # THEN: The isActive() and initialise() methods should have been called + mocked_plugin.isActive.assert_called_with() + mocked_plugin.initialise.assert_called_with() + + def finalise_plugins_with_disabled_plugin_test(self): + """ + Test running the finalise_plugins() method with a disabled plugin + """ + # GIVEN: A PluginManager instance and a list with a mocked up plugin whose status is set to Disabled + mocked_plugin = MagicMock() + mocked_plugin.status = PluginStatus.Disabled + mocked_plugin.isActive.return_value = False + plugin_manager = PluginManager('') + plugin_manager.plugins = [mocked_plugin] + + # WHEN: We run finalise_plugins() + plugin_manager.finalise_plugins() + + # THEN: The isActive() method should have been called, and initialise() method should NOT have been called + mocked_plugin.isActive.assert_called_with() + assert mocked_plugin.finalise.call_count == 0, u'The finalise() method should not have been called.' + + def finalise_plugins_with_active_plugin_test(self): + """ + Test running the finalise_plugins() method with an active plugin + """ + # GIVEN: A PluginManager instance and a list with a mocked up plugin whose status is set to Active + mocked_plugin = MagicMock() + mocked_plugin.status = PluginStatus.Active + mocked_plugin.isActive.return_value = True + plugin_manager = PluginManager('') + plugin_manager.plugins = [mocked_plugin] + + # WHEN: We run finalise_plugins() + plugin_manager.finalise_plugins() + + # THEN: The isActive() and finalise() methods should have been called + mocked_plugin.isActive.assert_called_with() + mocked_plugin.finalise.assert_called_with() + + def get_plugin_by_name_does_not_exist_test(self): + """ + Test running the get_plugin_by_name() method to find a plugin that does not exist + """ + # GIVEN: A PluginManager instance and a list with a mocked up plugin whose status is set to Active + mocked_plugin = MagicMock() + mocked_plugin.name = 'Mocked Plugin' + plugin_manager = PluginManager('') + plugin_manager.plugins = [mocked_plugin] + + # WHEN: We run finalise_plugins() + result = plugin_manager.get_plugin_by_name('Missing Plugin') + + # THEN: The isActive() and finalise() methods should have been called + self.assertIsNone(result, u'The result for get_plugin_by_name should be None') + + def get_plugin_by_name_exists_test(self): + """ + Test running the get_plugin_by_name() method to find a plugin that exists + """ + # GIVEN: A PluginManager instance and a list with a mocked up plugin whose status is set to Active + mocked_plugin = MagicMock() + mocked_plugin.name = 'Mocked Plugin' + plugin_manager = PluginManager('') + plugin_manager.plugins = [mocked_plugin] + + # WHEN: We run finalise_plugins() + result = plugin_manager.get_plugin_by_name('Mocked Plugin') + + # THEN: The isActive() and finalise() methods should have been called + self.assertEqual(result, mocked_plugin, u'The result for get_plugin_by_name should be the mocked plugin') + + def new_service_created_with_disabled_plugin_test(self): + """ + Test running the new_service_created() method with a disabled plugin + """ + # GIVEN: A PluginManager instance and a list with a mocked up plugin whose status is set to Disabled + mocked_plugin = MagicMock() + mocked_plugin.status = PluginStatus.Disabled + mocked_plugin.isActive.return_value = False + plugin_manager = PluginManager('') + plugin_manager.plugins = [mocked_plugin] + + # WHEN: We run finalise_plugins() + plugin_manager.new_service_created() + + # THEN: The isActive() method should have been called, and initialise() method should NOT have been called + mocked_plugin.isActive.assert_called_with() + assert mocked_plugin.new_service_created.call_count == 0,\ + u'The new_service_created() method should not have been called.' + + def new_service_created_with_active_plugin_test(self): + """ + Test running the new_service_created() method with an active plugin + """ + # GIVEN: A PluginManager instance and a list with a mocked up plugin whose status is set to Active + mocked_plugin = MagicMock() + mocked_plugin.status = PluginStatus.Active + mocked_plugin.isActive.return_value = True + plugin_manager = PluginManager('') + plugin_manager.plugins = [mocked_plugin] + + # WHEN: We run new_service_created() + plugin_manager.new_service_created() + + # THEN: The isActive() and finalise() methods should have been called + mocked_plugin.isActive.assert_called_with() + mocked_plugin.new_service_created.assert_called_with() diff --git a/tests/functional/openlp_core_lib/test_registry.py b/tests/functional/openlp_core_lib/test_registry.py index f27eef3d8..17fe561d7 100644 --- a/tests/functional/openlp_core_lib/test_registry.py +++ b/tests/functional/openlp_core_lib/test_registry.py @@ -1,13 +1,15 @@ """ - Package to test the openlp.core.lib package. +Package to test the openlp.core.lib package. """ import os - from unittest import TestCase + from mock import MagicMock + from openlp.core.lib import Registry -TESTPATH = os.path.abspath(os.path.join(os.path.dirname(__file__), u'..', u'..', u'resources')) +TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), u'..', u'..', u'resources')) + class TestRegistry(TestCase): From 42e0eea6e7ed96c6a6d0405dcb2c7879139afeca Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Mon, 11 Feb 2013 15:46:08 +0200 Subject: [PATCH 24/57] Tidy up a little. --- openlp/core/lib/pluginmanager.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/openlp/core/lib/pluginmanager.py b/openlp/core/lib/pluginmanager.py index cdd99a9e0..aefb11fc1 100644 --- a/openlp/core/lib/pluginmanager.py +++ b/openlp/core/lib/pluginmanager.py @@ -72,16 +72,14 @@ class PluginManager(object): """ log.info(u'Finding plugins') start_depth = len(os.path.abspath(plugin_dir).split(os.sep)) + present_plugin_dir = os.path.join(plugin_dir, 'presentations') log.debug(u'finding plugins in %s at depth %d', unicode(plugin_dir), start_depth) for root, dirs, files in os.walk(plugin_dir): - # TODO Presentation plugin is not yet working on Mac OS X. - # For now just ignore it. The following code will hide it - # in settings dialog. - if sys.platform == 'darwin': - present_plugin_dir = os.path.join(plugin_dir, 'presentations') - # Ignore files from the presentation plugin directory. - if root.startswith(present_plugin_dir): - continue + if sys.platform == 'darwin'and root.startswith(present_plugin_dir): + # TODO Presentation plugin is not yet working on Mac OS X. + # For now just ignore it. The following code will ignore files from the presentation plugin directory + # and thereby never import the plugin. + continue for name in files: if name.endswith(u'.py') and not name.startswith(u'__'): path = os.path.abspath(os.path.join(root, name)) From b5f3e46ad451296ee151b1b6dec641675f244897 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Mon, 11 Feb 2013 19:41:32 +0200 Subject: [PATCH 25/57] Pedantics. --- openlp/core/lib/pluginmanager.py | 7 +++---- tests/functional/openlp_core_lib/test_pluginmanager.py | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/openlp/core/lib/pluginmanager.py b/openlp/core/lib/pluginmanager.py index aefb11fc1..d248469c1 100644 --- a/openlp/core/lib/pluginmanager.py +++ b/openlp/core/lib/pluginmanager.py @@ -93,13 +93,12 @@ class PluginManager(object): try: # Use the "imp" library to try to get around a problem with the PyUNO library which # monkey-patches the __import__ function to do some magic. This causes issues with our tests. - # First, try to find the module we want to import, searching the directory in ``root`` + # First, try to find the module we want to import, searching the directory in root fp, path_name, description = imp.find_module(module_name, [root]) - # Then load the module (do the actual import) using the details from ``find_module()`` + # Then load the module (do the actual import) using the details from find_module() imp.load_module(module_name, fp, path_name, description) except ImportError, e: - log.exception(u'Failed to import module %s on path %s for reason %s', - module_name, path, e.args[0]) + log.exception(u'Failed to import module %s on path %s: %s', module_name, path, e.args[0]) plugin_classes = Plugin.__subclasses__() plugin_objects = [] for p in plugin_classes: diff --git a/tests/functional/openlp_core_lib/test_pluginmanager.py b/tests/functional/openlp_core_lib/test_pluginmanager.py index 3539373e0..bad38d721 100644 --- a/tests/functional/openlp_core_lib/test_pluginmanager.py +++ b/tests/functional/openlp_core_lib/test_pluginmanager.py @@ -89,7 +89,7 @@ class TestPluginManager(TestCase): assert mocked_plugin.createSettingsTab.call_count == 0, \ u'The createMediaManagerItem() method should not have been called.' self.assertEqual(mocked_settings_form.plugins, plugin_manager.plugins, - u'The plugins on the settings form should be the same as the plugins in the plugin manager') + u'The plugins on the settings form should be the same as the plugins in the plugin manager') def hook_settings_tabs_with_active_plugin_and_no_form_test(self): """ From 35eebb2a8eec6dd6f0807b1e793b528c7da334e2 Mon Sep 17 00:00:00 2001 From: phill-ridout Date: Mon, 11 Feb 2013 20:47:53 +0000 Subject: [PATCH 26/57] Added validator test --- .../openlp_core_ui/test_filerenamedialog.py | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/tests/interfaces/openlp_core_ui/test_filerenamedialog.py b/tests/interfaces/openlp_core_ui/test_filerenamedialog.py index 9e242f0d5..3e22b11e1 100644 --- a/tests/interfaces/openlp_core_ui/test_filerenamedialog.py +++ b/tests/interfaces/openlp_core_ui/test_filerenamedialog.py @@ -3,10 +3,10 @@ """ from unittest import TestCase -from mock import patch +from mock import MagicMock, patch from openlp.core.lib import Registry from openlp.core.ui import filerenameform -from PyQt4 import QtCore, QtGui, QtTest +from PyQt4 import QtGui, QtTest class TestStartFileRenameForm(TestCase): @@ -58,12 +58,26 @@ class TestStartFileRenameForm(TestCase): Regression test for bug1067251 Test that the fileNameEdit setFocus has called with True when executed """ - # GIVEN: A mocked QLineEdit class - with patch(u'PyQt4.QtGui.QDialog.exec_') as mocked_exec, \ - patch(u'PyQt4.QtGui.QLineEdit') as mocked_line_edit: + # GIVEN: A mocked QDialog.exec_() method and mocked fileNameEdit.setFocus() method. + with patch(u'PyQt4.QtGui.QDialog.exec_') as mocked_exec: + mocked_set_focus = MagicMock() + self.form.fileNameEdit.setFocus = mocked_set_focus - # WHEN: The form is executed with no args + # WHEN: The form is executed self.form.exec_() # THEN: the setFocus method of the fileNameEdit has been called with True - mocked_line_edit.setFocus.assert_called_with() + mocked_set_focus.assert_called_with() + + def file_name_validation_test(self): + """ + Test the fileNameEdit validation + """ + # GIVEN: QLineEdit with a validator set with illegal file name characters. + + # WHEN: 'Typing' a string containing invalid file characters. + QtTest.QTest.keyClicks(self.form.fileNameEdit, u'I/n\\v?a*l|i \F[i\l]e" :N+a%me') + + # THEN: The text in the QLineEdit should be the same as the input string with the invalid chatacters filtered + # out. + self.assertEqual(self.form.fileNameEdit.text(), u'Invalid File Name') From 98311d9ad1b03b5f584d0d4ee2ddac2dc382092d Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Mon, 11 Feb 2013 23:16:30 +0200 Subject: [PATCH 27/57] Add an interface test for the find_plugins method. Not sure if this should be an interface test or a scenario test, but it does very little mocking, tries to let the bits of OpenLP run for real, and checks that all the plugins are imported. Remove the superfluous argument to the find_plugins method. --- openlp/core/lib/pluginmanager.py | 19 +++--- openlp/core/ui/mainwindow.py | 2 +- tests/interfaces/__init__.py | 8 +++ tests/interfaces/openlp_core_lib/__init__.py | 0 .../openlp_core_lib/test_pluginmanager.py | 60 +++++++++++++++++++ 5 files changed, 76 insertions(+), 13 deletions(-) create mode 100644 tests/interfaces/__init__.py create mode 100644 tests/interfaces/openlp_core_lib/__init__.py create mode 100644 tests/interfaces/openlp_core_lib/test_pluginmanager.py diff --git a/openlp/core/lib/pluginmanager.py b/openlp/core/lib/pluginmanager.py index d248469c1..06f0e36eb 100644 --- a/openlp/core/lib/pluginmanager.py +++ b/openlp/core/lib/pluginmanager.py @@ -61,21 +61,16 @@ class PluginManager(object): self.plugins = [] log.info(u'Plugin manager Initialised') - def find_plugins(self, plugin_dir): + def find_plugins(self): """ - Scan the directory ``plugin_dir`` for objects inheriting from the - ``Plugin`` class. - - ``plugin_dir`` - The directory to scan. - + Scan a directory for objects inheriting from the ``Plugin`` class. """ log.info(u'Finding plugins') - start_depth = len(os.path.abspath(plugin_dir).split(os.sep)) - present_plugin_dir = os.path.join(plugin_dir, 'presentations') - log.debug(u'finding plugins in %s at depth %d', unicode(plugin_dir), start_depth) - for root, dirs, files in os.walk(plugin_dir): - if sys.platform == 'darwin'and root.startswith(present_plugin_dir): + start_depth = len(os.path.abspath(self.base_path).split(os.sep)) + present_plugin_dir = os.path.join(self.base_path, 'presentations') + log.debug(u'finding plugins in %s at depth %d', unicode(self.base_path), start_depth) + for root, dirs, files in os.walk(self.base_path): + if sys.platform == 'darwin' and root.startswith(present_plugin_dir): # TODO Presentation plugin is not yet working on Mac OS X. # For now just ignore it. The following code will ignore files from the presentation plugin directory # and thereby never import the plugin. diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index cb94a0914..cc5e4a617 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -551,7 +551,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): # Define the media Dock Manager self.mediaDockManager = MediaDockManager(self.mediaToolBox) log.info(u'Load Plugins') - self.plugin_manager.find_plugins(plugin_path) + self.plugin_manager.find_plugins() # hook methods have to happen after find_plugins. Find plugins needs # the controllers hence the hooks have moved from setupUI() to here # Find and insert settings tabs diff --git a/tests/interfaces/__init__.py b/tests/interfaces/__init__.py new file mode 100644 index 000000000..0157fb2f0 --- /dev/null +++ b/tests/interfaces/__init__.py @@ -0,0 +1,8 @@ +import sip +sip.setapi(u'QDate', 2) +sip.setapi(u'QDateTime', 2) +sip.setapi(u'QString', 2) +sip.setapi(u'QTextStream', 2) +sip.setapi(u'QTime', 2) +sip.setapi(u'QUrl', 2) +sip.setapi(u'QVariant', 2) diff --git a/tests/interfaces/openlp_core_lib/__init__.py b/tests/interfaces/openlp_core_lib/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/interfaces/openlp_core_lib/test_pluginmanager.py b/tests/interfaces/openlp_core_lib/test_pluginmanager.py new file mode 100644 index 000000000..609af01fb --- /dev/null +++ b/tests/interfaces/openlp_core_lib/test_pluginmanager.py @@ -0,0 +1,60 @@ +""" +Package to test the openlp.core.lib.pluginmanager package. +""" +import os +import sys +from tempfile import mkstemp +from unittest import TestCase + +from mock import MagicMock, patch +from PyQt4 import QtGui + +from openlp.core.lib.pluginmanager import PluginManager +from openlp.core.lib import Registry, Settings + + +class TestPluginManager(TestCase): + """ + Test the PluginManager class + """ + + def setUp(self): + """ + Some pre-test setup required. + """ + fd, self.ini_file = mkstemp(u'.ini') + Settings().set_filename(self.ini_file) + Registry.create() + Registry().register(u'service_list', MagicMock()) + self.app = QtGui.QApplication([]) + self.main_window = QtGui.QMainWindow() + Registry().register(u'main_window', self.main_window) + self.plugins_dir = os.path.abspath(os.path.join(os.path.basename(__file__), u'..', u'openlp', u'plugins')) + + def tearDown(self): + os.unlink(self.ini_file) + + def find_plugins_test(self): + """ + Test the find_plugins() method to ensure it imports the correct plugins. + """ + # GIVEN: A plugin manager + plugin_manager = PluginManager(self.plugins_dir) + + # WHEN: We mock out sys.platform to make it return "darwin" and then find the plugins + old_platform = sys.platform + sys.platform = u'darwin' + plugin_manager.find_plugins() + sys.platform = old_platform + + # THEN: We should find the "Songs", "Bibles", etc in the plugins list + plugin_names = [plugin.name for plugin in plugin_manager.plugins] + assert u'songs' in plugin_names, u'There should be a "songs" plugin.' + assert u'bibles' in plugin_names, u'There should be a "bibles" plugin.' + assert u'presentations' not in plugin_names, u'There should NOT be a "presentations" plugin.' + assert u'images' in plugin_names, u'There should be a "images" plugin.' + assert u'media' in plugin_names, u'There should be a "media" plugin.' + assert u'custom' in plugin_names, u'There should be a "custom" plugin.' + assert u'songusage' in plugin_names, u'There should be a "songusage" plugin.' + assert u'alerts' in plugin_names, u'There should be a "alerts" plugin.' + assert u'remotes' in plugin_names, u'There should be a "remotes" plugin.' From 6efe1bf602b7b8c1cbc8685adbf8907bbc79c29e Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Tue, 12 Feb 2013 08:49:01 +0100 Subject: [PATCH 28/57] image and remote plugin regression --- openlp/plugins/images/imageplugin.py | 14 ++++++- openlp/plugins/remotes/lib/httpserver.py | 53 ++++++++++++++++++------ 2 files changed, 53 insertions(+), 14 deletions(-) diff --git a/openlp/plugins/images/imageplugin.py b/openlp/plugins/images/imageplugin.py index 0f2829dbc..83c424e86 100644 --- a/openlp/plugins/images/imageplugin.py +++ b/openlp/plugins/images/imageplugin.py @@ -31,7 +31,7 @@ from PyQt4 import QtCore, QtGui import logging -from openlp.core.lib import Plugin, StringContent, Receiver, ImageSource, Settings, build_icon, translate +from openlp.core.lib import Plugin, StringContent, Receiver, ImageSource, Settings, Registry, build_icon, translate from openlp.plugins.images.lib import ImageMediaItem, ImageTab log = logging.getLogger(__name__) @@ -98,4 +98,14 @@ class ImagePlugin(Plugin): last part of saving the config. """ background = QtGui.QColor(Settings().value(self.settingsSection + u'/background color')) - self.liveController.imageManager.update_images_border(ImageSource.ImagePlugin, background) + self.image_manager.update_images_border(ImageSource.ImagePlugin, background) + + def _get_image_manager(self): + """ + Adds the image manager to the class dynamically + """ + if not hasattr(self, u'_image_manager'): + self._image_manager = Registry().get(u'image_manager') + return self._image_manager + + image_manager = property(_get_image_manager) diff --git a/openlp/plugins/remotes/lib/httpserver.py b/openlp/plugins/remotes/lib/httpserver.py index d444fc1c4..127c2c13b 100644 --- a/openlp/plugins/remotes/lib/httpserver.py +++ b/openlp/plugins/remotes/lib/httpserver.py @@ -123,7 +123,7 @@ import urlparse from PyQt4 import QtCore, QtNetwork from mako.template import Template -from openlp.core.lib import Receiver, Settings, PluginStatus, StringContent +from openlp.core.lib import Receiver, Settings, PluginStatus, StringContent, Registry from openlp.core.utils import AppLocation, translate log = logging.getLogger(__name__) @@ -252,12 +252,11 @@ class HttpConnection(object): def _get_service_items(self): service_items = [] - service_manager = self.parent.plugin.serviceManager if self.parent.current_item: current_unique_identifier = self.parent.current_item.unique_identifier else: current_unique_identifier = None - for item in service_manager.serviceItems: + for item in self.service_manager.serviceItems: service_item = item[u'service_item'] service_items.append({ u'id': unicode(service_item.unique_identifier), @@ -388,13 +387,13 @@ class HttpConnection(object): Poll OpenLP to determine the current slide number and item name. """ result = { - u'service': self.parent.plugin.serviceManager.service_id, + u'service': self.service_manager.service_id, u'slide': self.parent.current_slide or 0, u'item': self.parent.current_item.unique_identifier if self.parent.current_item else u'', u'twelve':Settings().value(u'remotes/twelve hour'), - u'blank': self.parent.plugin.liveController.blankScreen.isChecked(), - u'theme': self.parent.plugin.liveController.themeScreen.isChecked(), - u'display': self.parent.plugin.liveController.desktopScreen.isChecked() + u'blank': self.live_controller.blankScreen.isChecked(), + u'theme': self.live_controller.themeScreen.isChecked(), + u'display': self.live_controller.desktopScreen.isChecked() } return HttpResponse(json.dumps({u'results': result}), {u'Content-Type': u'application/json'}) @@ -414,7 +413,7 @@ class HttpConnection(object): """ Send an alert. """ - plugin = self.parent.plugin.pluginManager.get_plugin_by_name("alerts") + plugin = self.plugin_manager.get_plugin_by_name("alerts") if plugin.status == PluginStatus.Active: try: text = json.loads(self.url_params[u'data'][0])[u'request'][u'text'] @@ -506,7 +505,7 @@ class HttpConnection(object): """ if action == u'search': searches = [] - for plugin in self.parent.plugin.pluginManager.plugins: + for plugin in self.plugin_manager.plugins: if plugin.status == PluginStatus.Active and plugin.mediaItem and plugin.mediaItem.hasSearch: searches.append([plugin.name, unicode(plugin.textStrings[StringContent.Name][u'plural'])]) return HttpResponse( @@ -525,7 +524,7 @@ class HttpConnection(object): except KeyError, ValueError: return HttpResponse(code=u'400 Bad Request') text = urllib.unquote(text) - plugin = self.parent.plugin.pluginManager.get_plugin_by_name(type) + plugin = self.plugin_manager.get_plugin_by_name(type) if plugin.status == PluginStatus.Active and plugin.mediaItem and plugin.mediaItem.hasSearch: results = plugin.mediaItem.search(text, False) else: @@ -541,7 +540,7 @@ class HttpConnection(object): id = json.loads(self.url_params[u'data'][0])[u'request'][u'id'] except KeyError, ValueError: return HttpResponse(code=u'400 Bad Request') - plugin = self.parent.plugin.pluginManager.get_plugin_by_name(type) + plugin = self.plugin_manager.get_plugin_by_name(type) if plugin.status == PluginStatus.Active and plugin.mediaItem: plugin.mediaItem.goLive(id, remote=True) return HttpResponse(code=u'200 OK') @@ -554,7 +553,7 @@ class HttpConnection(object): id = json.loads(self.url_params[u'data'][0])[u'request'][u'id'] except KeyError, ValueError: return HttpResponse(code=u'400 Bad Request') - plugin = self.parent.plugin.pluginManager.get_plugin_by_name(type) + plugin = self.plugin_manager.get_plugin_by_name(type) if plugin.status == PluginStatus.Active and plugin.mediaItem: item_id = plugin.mediaItem.createItemFromId(id) plugin.mediaItem.addToService(item_id, remote=True) @@ -585,3 +584,33 @@ class HttpConnection(object): self.socket.close() self.socket = None self.parent.close_connection(self) + + def _get_service_manager(self): + """ + Adds the service manager to the class dynamically + """ + if not hasattr(self, u'_service_manager'): + self._service_manager = Registry().get(u'service_manager') + return self._service_manager + + service_manager = property(_get_service_manager) + + def _get_live_controller(self): + """ + Adds the live controller to the class dynamically + """ + if not hasattr(self, u'_live_controller'): + self._live_controller = Registry().get(u'live_controller') + return self._live_controller + + live_controller = property(_get_live_controller) + + def _get_plugin_manager(self): + """ + Adds the plugin manager to the class dynamically + """ + if not hasattr(self, u'_plugin_manager'): + self._plugin_manager = Registry().get(u'plugin_manager') + return self._plugin_manager + + plugin_manager = property(_get_plugin_manager) From ffe6bdb6b0cd735069a934105d300efbf980fdeb Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Tue, 12 Feb 2013 08:49:59 +0100 Subject: [PATCH 29/57] removed blank line --- openlp/plugins/alerts/lib/alertsmanager.py | 1 - 1 file changed, 1 deletion(-) diff --git a/openlp/plugins/alerts/lib/alertsmanager.py b/openlp/plugins/alerts/lib/alertsmanager.py index 42a28eee1..40910c67c 100644 --- a/openlp/plugins/alerts/lib/alertsmanager.py +++ b/openlp/plugins/alerts/lib/alertsmanager.py @@ -108,7 +108,6 @@ class AlertsManager(QtCore.QObject): self.timer_id = 0 self.generateAlert() - def _get_live_controller(self): """ Adds the live controller to the class dynamically From f419108e61440d018d97b2d0c351b42064f41c55 Mon Sep 17 00:00:00 2001 From: phill-ridout Date: Tue, 12 Feb 2013 19:26:19 +0000 Subject: [PATCH 30/57] Removed spacing from comments. --- tests/interfaces/openlp_core_ui/test_filerenamedialog.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/interfaces/openlp_core_ui/test_filerenamedialog.py b/tests/interfaces/openlp_core_ui/test_filerenamedialog.py index 3e22b11e1..74fe83b26 100644 --- a/tests/interfaces/openlp_core_ui/test_filerenamedialog.py +++ b/tests/interfaces/openlp_core_ui/test_filerenamedialog.py @@ -79,5 +79,5 @@ class TestStartFileRenameForm(TestCase): QtTest.QTest.keyClicks(self.form.fileNameEdit, u'I/n\\v?a*l|i \F[i\l]e" :N+a%me') # THEN: The text in the QLineEdit should be the same as the input string with the invalid chatacters filtered - # out. + # out. self.assertEqual(self.form.fileNameEdit.text(), u'Invalid File Name') From bc5334fa1ac9885480c62936bf4624518180daf8 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Wed, 13 Feb 2013 19:10:41 +0000 Subject: [PATCH 31/57] Add new tests to system --- tests/functional/openlp_core_lib/__init__.py | 8 +++ .../openlp_core_lib/test_image_manager.py | 49 +++++++++++++++++++ tests/interfaces/openlp_core_ui/__init__.py | 8 +++ .../openlp_core_ui/test_servicemanager.py | 41 ++++++++++++++++ 4 files changed, 106 insertions(+) create mode 100644 tests/functional/openlp_core_lib/test_image_manager.py create mode 100644 tests/interfaces/openlp_core_ui/test_servicemanager.py diff --git a/tests/functional/openlp_core_lib/__init__.py b/tests/functional/openlp_core_lib/__init__.py index e69de29bb..e0da50eb3 100644 --- a/tests/functional/openlp_core_lib/__init__.py +++ b/tests/functional/openlp_core_lib/__init__.py @@ -0,0 +1,8 @@ +import sip +sip.setapi(u'QDate', 2) +sip.setapi(u'QDateTime', 2) +sip.setapi(u'QString', 2) +sip.setapi(u'QTextStream', 2) +sip.setapi(u'QTime', 2) +sip.setapi(u'QUrl', 2) +sip.setapi(u'QVariant', 2) \ No newline at end of file diff --git a/tests/functional/openlp_core_lib/test_image_manager.py b/tests/functional/openlp_core_lib/test_image_manager.py new file mode 100644 index 000000000..2ab0ff1ce --- /dev/null +++ b/tests/functional/openlp_core_lib/test_image_manager.py @@ -0,0 +1,49 @@ +""" + Package to test the openlp.core.ui package. +""" + +import os + +from unittest import TestCase + +from mock import MagicMock +from openlp.core.lib import Registry, ImageManager, ScreenList +from PyQt4 import QtCore, QtGui, QtTest + +TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), u'..', u'..', u'resources')) + +class TestImageManager(TestCase): + + def setUp(self): + """ + Create the UI + """ + Registry.create() + self.app = QtGui.QApplication([]) + ScreenList.create(self.app.desktop()) + self.image_manager = ImageManager() + + def tearDown(self): + """ + Delete all the C++ objects at the end so that we don't have a segfault + """ + del self.app + + def basic_image_manager_test(self): + """ + Test the Image Manager setup basic functionality + """ + # GIVEN: the an image add to the image manager + self.image_manager.add_image(TEST_PATH, u'church.jpg', None) + + # WHEN the image is retrieved + image = self.image_manager.get_image(TEST_PATH, u'church.jpg') + + # THEN returned record is a type of image + self.assertEqual(isinstance(image, QtGui.QImage), True, u'The returned field is an image') + + # WHEN the image is retrieved has not been loaded + # THEN a KeyError is thrown + with self.assertRaises(KeyError) as context: + self.image_manager.get_image(TEST_PATH, u'church1.jpg') + self.assertNotEquals(context.exception[0], u'', u'KeyError exception should have been thrown for missing image') \ No newline at end of file diff --git a/tests/interfaces/openlp_core_ui/__init__.py b/tests/interfaces/openlp_core_ui/__init__.py index e69de29bb..e0da50eb3 100644 --- a/tests/interfaces/openlp_core_ui/__init__.py +++ b/tests/interfaces/openlp_core_ui/__init__.py @@ -0,0 +1,8 @@ +import sip +sip.setapi(u'QDate', 2) +sip.setapi(u'QDateTime', 2) +sip.setapi(u'QString', 2) +sip.setapi(u'QTextStream', 2) +sip.setapi(u'QTime', 2) +sip.setapi(u'QUrl', 2) +sip.setapi(u'QVariant', 2) \ No newline at end of file diff --git a/tests/interfaces/openlp_core_ui/test_servicemanager.py b/tests/interfaces/openlp_core_ui/test_servicemanager.py new file mode 100644 index 000000000..7883a5694 --- /dev/null +++ b/tests/interfaces/openlp_core_ui/test_servicemanager.py @@ -0,0 +1,41 @@ +""" + Package to test the openlp.core.ui package. +""" +from unittest import TestCase + +from mock import MagicMock +from openlp.core.lib import Registry, ScreenList +from openlp.core.ui.mainwindow import MainWindow +from PyQt4 import QtGui + + +class TestStartNoteDialog(TestCase): + + def setUp(self): + """ + Create the UI + """ + Registry.create() + self.app = QtGui.QApplication([]) + ScreenList.create(self.app.desktop()) + Registry().register(u'application', MagicMock()) + self.main_window = MainWindow() + self.service_manager = Registry().get(u'service_manager') + + def tearDown(self): + """ + Delete all the C++ objects at the end so that we don't have a segfault + """ + del self.main_window + del self.app + + def basic_service_manager_test(self): + """ + Test the Service Manager display functionality + """ + # GIVEN: A New Service Manager instance + + # WHEN I have an empty display + # THEN the count of items should be zero + self.assertEqual(self.service_manager.service_manager_list.topLevelItemCount(), 0, + u'There the service manager list is empty ') From 89856e0e9aa660b6300fd88fa7622dc93f976890 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Wed, 13 Feb 2013 19:22:43 +0000 Subject: [PATCH 32/57] Cleanup --- tests/functional/openlp_core_lib/test_image_manager.py | 6 +++--- tests/interfaces/openlp_core_ui/__init__.py | 2 +- tests/interfaces/openlp_core_ui/test_servicemanager.py | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/functional/openlp_core_lib/test_image_manager.py b/tests/functional/openlp_core_lib/test_image_manager.py index 2ab0ff1ce..3ee4abd90 100644 --- a/tests/functional/openlp_core_lib/test_image_manager.py +++ b/tests/functional/openlp_core_lib/test_image_manager.py @@ -6,12 +6,12 @@ import os from unittest import TestCase -from mock import MagicMock from openlp.core.lib import Registry, ImageManager, ScreenList -from PyQt4 import QtCore, QtGui, QtTest +from PyQt4 import QtGui TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), u'..', u'..', u'resources')) + class TestImageManager(TestCase): def setUp(self): @@ -46,4 +46,4 @@ class TestImageManager(TestCase): # THEN a KeyError is thrown with self.assertRaises(KeyError) as context: self.image_manager.get_image(TEST_PATH, u'church1.jpg') - self.assertNotEquals(context.exception[0], u'', u'KeyError exception should have been thrown for missing image') \ No newline at end of file + self.assertNotEquals(context.exception[0], u'', u'KeyError exception should have been thrown for missing image') diff --git a/tests/interfaces/openlp_core_ui/__init__.py b/tests/interfaces/openlp_core_ui/__init__.py index e0da50eb3..0157fb2f0 100644 --- a/tests/interfaces/openlp_core_ui/__init__.py +++ b/tests/interfaces/openlp_core_ui/__init__.py @@ -5,4 +5,4 @@ sip.setapi(u'QString', 2) sip.setapi(u'QTextStream', 2) sip.setapi(u'QTime', 2) sip.setapi(u'QUrl', 2) -sip.setapi(u'QVariant', 2) \ No newline at end of file +sip.setapi(u'QVariant', 2) diff --git a/tests/interfaces/openlp_core_ui/test_servicemanager.py b/tests/interfaces/openlp_core_ui/test_servicemanager.py index 7883a5694..b894db470 100644 --- a/tests/interfaces/openlp_core_ui/test_servicemanager.py +++ b/tests/interfaces/openlp_core_ui/test_servicemanager.py @@ -1,5 +1,5 @@ """ - Package to test the openlp.core.ui package. + Package to test the openlp.core.lib package. """ from unittest import TestCase @@ -38,4 +38,4 @@ class TestStartNoteDialog(TestCase): # WHEN I have an empty display # THEN the count of items should be zero self.assertEqual(self.service_manager.service_manager_list.topLevelItemCount(), 0, - u'There the service manager list is empty ') + u'There the service manager list is not empty ') From 6b2274645aa6c88421055d3cb3516f322416167b Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Thu, 14 Feb 2013 15:54:45 +0100 Subject: [PATCH 33/57] added test for UiStrings, started with FormattingTags tests --- openlp/core/lib/formattingtags.py | 27 +++----- .../openlp_core_lib/test_formattingtags.py | 66 +++++++++++++++++++ .../openlp_core_lib/test_uistrings.py | 22 +++++++ 3 files changed, 98 insertions(+), 17 deletions(-) create mode 100644 tests/functional/openlp_core_lib/test_formattingtags.py create mode 100644 tests/functional/openlp_core_lib/test_uistrings.py diff --git a/openlp/core/lib/formattingtags.py b/openlp/core/lib/formattingtags.py index b7bbd7322..b2d8f6ea7 100644 --- a/openlp/core/lib/formattingtags.py +++ b/openlp/core/lib/formattingtags.py @@ -36,8 +36,7 @@ from openlp.core.lib import Settings, translate class FormattingTags(object): """ - Static Class to HTML Tags to be access around the code the list is managed - by the Options Tab. + Static Class to HTML Tags to be access around the code the list is managed by the Options Tab. """ html_expands = [] @@ -56,12 +55,11 @@ class FormattingTags(object): tags = [] for tag in FormattingTags.html_expands: if not tag[u'protected'] and not tag.get(u'temporary'): - # Using dict ensures that copy is made and encoding of values - # a little later does not affect tags in the original list + # Using dict ensures that copy is made and encoding of values a little later does not affect tags in + # the original list tags.append(dict(tag)) tag = tags[-1] - # Remove key 'temporary' from tags. - # It is not needed to be saved. + # Remove key 'temporary' from tags. It is not needed to be saved. if u'temporary' in tag: del tag[u'temporary'] for element in tag: @@ -73,15 +71,12 @@ class FormattingTags(object): @staticmethod def load_tags(): """ - Load the Tags from store so can be used in the system or used to - update the display. + Load the Tags from store so can be used in the system or used to update the display. """ - temporary_tags = [tag for tag in FormattingTags.html_expands - if tag.get(u'temporary')] + temporary_tags = [tag for tag in FormattingTags.html_expands if tag.get(u'temporary')] FormattingTags.html_expands = [] base_tags = [] # Append the base tags. - # Hex Color tags from http://www.w3schools.com/html/html_colornames.asp base_tags.append({u'desc': translate('OpenLP.FormattingTags', 'Red'), u'start tag': u'{r}', u'start html': u'', @@ -195,19 +190,17 @@ class FormattingTags(object): The end tag, e. g. ``{/r}`` * start html - The start html tag. For instance ```` + The start html tag. For instance ```` * end html The end html tag. For example ```` * protected - A boolean stating whether this is a build-in tag or not. Should be - ``True`` in most cases. + A boolean stating whether this is a build-in tag or not. Should be ``True`` in most cases. * temporary - A temporary tag will not be saved, but is also considered when - displaying text containing the tag. It has to be a ``boolean``. + A temporary tag will not be saved, but is also considered when displaying text containing the tag. It has + to be a ``boolean``. """ FormattingTags.html_expands.extend(tags) diff --git a/tests/functional/openlp_core_lib/test_formattingtags.py b/tests/functional/openlp_core_lib/test_formattingtags.py new file mode 100644 index 000000000..5a95e195f --- /dev/null +++ b/tests/functional/openlp_core_lib/test_formattingtags.py @@ -0,0 +1,66 @@ +""" +Package to test the openlp.core.lib.formattingtags package. +""" + +from unittest import TestCase + +from mock import patch + +from openlp.core.lib import FormattingTags + +class TestFormattingTags(TestCase): + + def get_html_tags_no_user_tags_test(self): + """ + Test the get_html_tags static method. + """ + with patch(u'openlp.core.lib.translate') as mocked_translate, \ + patch(u'openlp.core.lib.settings') as mocked_settings, \ + patch(u'openlp.core.lib.formattingtags.cPickle') as mocked_cPickle: + # GIVEN: Our mocked modules and functions. + mocked_translate.side_effect = lambda module, string_to_translate: string_to_translate + mocked_settings.value.return_value = u'' + mocked_cPickle.load.return_value = [] + + # WHEN: Get the display tags. + FormattingTags.load_tags() + old_tags_list = FormattingTags.get_html_tags() + FormattingTags.load_tags() + new_tags_list = FormattingTags.get_html_tags() + + # THEN: Lists should be identically. + assert old_tags_list == new_tags_list, u'The formatting tag lists should be identically.' + + def get_html_tags_with_user_tags_test(self): + """ + Add a tag and check if it still exists after reloading the tags list. + """ + # FIXME: not working yet. + with patch(u'openlp.core.lib.translate') as mocked_translate, \ + patch(u'openlp.core.lib.settings') as mocked_settings, \ + patch(u'openlp.core.lib.formattingtags.cPickle') as mocked_cPickle: + # GIVEN: Our mocked modules and functions. + mocked_translate.side_effect = lambda module, string_to_translate: string_to_translate + mocked_settings.value.return_value = u'' + mocked_cPickle.load.return_value = [] + tags = [{ + u'end tag': '{/aa}', + u'start html': '', + u'start tag': '{aa}', + u'protected': False, + u'end html': '', + u'desc': 'name'} + ] + + # WHEN: Get the display tags. + FormattingTags.add_html_tags(tags) + FormattingTags.load_tags() + old_tags_list = FormattingTags.get_html_tags() + FormattingTags.load_tags() + new_tags_list = FormattingTags.get_html_tags() + + # THEN: Lists should be identically. + assert old_tags_list == new_tags_list, u'The formatting tag lists with user tags should be identically.' + + + diff --git a/tests/functional/openlp_core_lib/test_uistrings.py b/tests/functional/openlp_core_lib/test_uistrings.py new file mode 100644 index 000000000..e0d0fc485 --- /dev/null +++ b/tests/functional/openlp_core_lib/test_uistrings.py @@ -0,0 +1,22 @@ +""" +Package to test the openlp.core.lib.uistrings package. +""" + +from unittest import TestCase + +from openlp.core.lib import UiStrings + +class TestUiStrings(TestCase): + + def check_same_instance_test(self): + """ + Test if the always only one instance of the UiStrings is created. + """ + # WHEN: Create two instances of the UiStrings class. + first_instance = UiStrings() + second_instance = UiStrings() + + # THEN: Check if the instances are the same. + assert first_instance is second_instance, "They should be the same instance!" + + From a5b6b5fe90fc408514afc633977c07d82577193f Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Thu, 14 Feb 2013 17:30:28 +0000 Subject: [PATCH 34/57] Fix init methods --- tests/functional/__init__.py | 8 ++++++++ tests/functional/openlp_core_lib/__init__.py | 8 -------- tests/interfaces/__init__.py | 8 ++++++++ 3 files changed, 16 insertions(+), 8 deletions(-) create mode 100644 tests/functional/__init__.py create mode 100644 tests/interfaces/__init__.py diff --git a/tests/functional/__init__.py b/tests/functional/__init__.py new file mode 100644 index 000000000..e0da50eb3 --- /dev/null +++ b/tests/functional/__init__.py @@ -0,0 +1,8 @@ +import sip +sip.setapi(u'QDate', 2) +sip.setapi(u'QDateTime', 2) +sip.setapi(u'QString', 2) +sip.setapi(u'QTextStream', 2) +sip.setapi(u'QTime', 2) +sip.setapi(u'QUrl', 2) +sip.setapi(u'QVariant', 2) \ No newline at end of file diff --git a/tests/functional/openlp_core_lib/__init__.py b/tests/functional/openlp_core_lib/__init__.py index e0da50eb3..e69de29bb 100644 --- a/tests/functional/openlp_core_lib/__init__.py +++ b/tests/functional/openlp_core_lib/__init__.py @@ -1,8 +0,0 @@ -import sip -sip.setapi(u'QDate', 2) -sip.setapi(u'QDateTime', 2) -sip.setapi(u'QString', 2) -sip.setapi(u'QTextStream', 2) -sip.setapi(u'QTime', 2) -sip.setapi(u'QUrl', 2) -sip.setapi(u'QVariant', 2) \ No newline at end of file diff --git a/tests/interfaces/__init__.py b/tests/interfaces/__init__.py new file mode 100644 index 000000000..e0da50eb3 --- /dev/null +++ b/tests/interfaces/__init__.py @@ -0,0 +1,8 @@ +import sip +sip.setapi(u'QDate', 2) +sip.setapi(u'QDateTime', 2) +sip.setapi(u'QString', 2) +sip.setapi(u'QTextStream', 2) +sip.setapi(u'QTime', 2) +sip.setapi(u'QUrl', 2) +sip.setapi(u'QVariant', 2) \ No newline at end of file From 796a147ffe4dbb7601b9a152b055be32794d6bc8 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Thu, 14 Feb 2013 17:34:41 +0000 Subject: [PATCH 35/57] Remove one extra file --- tests/interfaces/openlp_core_ui/__init__.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/tests/interfaces/openlp_core_ui/__init__.py b/tests/interfaces/openlp_core_ui/__init__.py index 0157fb2f0..8b1378917 100644 --- a/tests/interfaces/openlp_core_ui/__init__.py +++ b/tests/interfaces/openlp_core_ui/__init__.py @@ -1,8 +1 @@ -import sip -sip.setapi(u'QDate', 2) -sip.setapi(u'QDateTime', 2) -sip.setapi(u'QString', 2) -sip.setapi(u'QTextStream', 2) -sip.setapi(u'QTime', 2) -sip.setapi(u'QUrl', 2) -sip.setapi(u'QVariant', 2) + From b77ae7a187d180b48ecdf5d17da3daad50e9f382 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Fri, 15 Feb 2013 12:09:51 +0100 Subject: [PATCH 36/57] fixed test --- .../openlp_core_lib/test_formattingtags.py | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/tests/functional/openlp_core_lib/test_formattingtags.py b/tests/functional/openlp_core_lib/test_formattingtags.py index 5a95e195f..0d3b8b6b6 100644 --- a/tests/functional/openlp_core_lib/test_formattingtags.py +++ b/tests/functional/openlp_core_lib/test_formattingtags.py @@ -10,6 +10,12 @@ from openlp.core.lib import FormattingTags class TestFormattingTags(TestCase): + def tearDown(self): + """ + Clean up the FormattingTags class. + """ + FormattingTags.html_expands = [] + def get_html_tags_no_user_tags_test(self): """ Test the get_html_tags static method. @@ -18,7 +24,7 @@ class TestFormattingTags(TestCase): patch(u'openlp.core.lib.settings') as mocked_settings, \ patch(u'openlp.core.lib.formattingtags.cPickle') as mocked_cPickle: # GIVEN: Our mocked modules and functions. - mocked_translate.side_effect = lambda module, string_to_translate: string_to_translate + mocked_translate.side_effect = lambda module, string_to_translate, comment: string_to_translate mocked_settings.value.return_value = u'' mocked_cPickle.load.return_value = [] @@ -35,32 +41,32 @@ class TestFormattingTags(TestCase): """ Add a tag and check if it still exists after reloading the tags list. """ - # FIXME: not working yet. with patch(u'openlp.core.lib.translate') as mocked_translate, \ patch(u'openlp.core.lib.settings') as mocked_settings, \ patch(u'openlp.core.lib.formattingtags.cPickle') as mocked_cPickle: # GIVEN: Our mocked modules and functions. mocked_translate.side_effect = lambda module, string_to_translate: string_to_translate mocked_settings.value.return_value = u'' - mocked_cPickle.load.return_value = [] tags = [{ u'end tag': '{/aa}', u'start html': '', u'start tag': '{aa}', u'protected': False, u'end html': '', - u'desc': 'name'} - ] + u'desc': 'name' + }] + mocked_cPickle.load.return_value = tags # WHEN: Get the display tags. - FormattingTags.add_html_tags(tags) FormattingTags.load_tags() old_tags_list = FormattingTags.get_html_tags() + + FormattingTags.add_html_tags(tags) FormattingTags.load_tags() new_tags_list = FormattingTags.get_html_tags() - # THEN: Lists should be identically. - assert old_tags_list == new_tags_list, u'The formatting tag lists with user tags should be identically.' + # THEN: Lists should not be identically. + assert len(old_tags_list) - 1 == len(new_tags_list), u'The lists should be different.' From cd83142d774a4dc1571c50bf9561af072df9936c Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Fri, 15 Feb 2013 12:55:47 +0100 Subject: [PATCH 37/57] fixed test --- .../openlp_core_lib/test_formattingtags.py | 20 +++++++++++-------- .../openlp_core_lib/test_serviceitem.py | 3 ++- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/tests/functional/openlp_core_lib/test_formattingtags.py b/tests/functional/openlp_core_lib/test_formattingtags.py index 0d3b8b6b6..db34dd8bd 100644 --- a/tests/functional/openlp_core_lib/test_formattingtags.py +++ b/tests/functional/openlp_core_lib/test_formattingtags.py @@ -1,13 +1,14 @@ """ Package to test the openlp.core.lib.formattingtags package. """ - +import copy from unittest import TestCase from mock import patch from openlp.core.lib import FormattingTags + class TestFormattingTags(TestCase): def tearDown(self): @@ -47,26 +48,29 @@ class TestFormattingTags(TestCase): # GIVEN: Our mocked modules and functions. mocked_translate.side_effect = lambda module, string_to_translate: string_to_translate mocked_settings.value.return_value = u'' - tags = [{ + tag = { u'end tag': '{/aa}', u'start html': '', u'start tag': '{aa}', u'protected': False, u'end html': '', u'desc': 'name' - }] - mocked_cPickle.load.return_value = tags + } + mocked_cPickle.loads.side_effect = [[], [tag]] # WHEN: Get the display tags. FormattingTags.load_tags() - old_tags_list = FormattingTags.get_html_tags() + old_tags_list = copy.deepcopy(FormattingTags.get_html_tags()) - FormattingTags.add_html_tags(tags) + # WHEN: Add our tag and get the tags again. FormattingTags.load_tags() + FormattingTags.add_html_tags([tag]) new_tags_list = FormattingTags.get_html_tags() # THEN: Lists should not be identically. - assert len(old_tags_list) - 1 == len(new_tags_list), u'The lists should be different.' - + assert old_tags_list != new_tags_list, u'The lists should be different.' + # THEN: Added tag and last tag should be the same. + new_tag = new_tags_list.pop() + assert tag == new_tag, u'Tags should be identically.' diff --git a/tests/functional/openlp_core_lib/test_serviceitem.py b/tests/functional/openlp_core_lib/test_serviceitem.py index a50752cce..8085d676a 100644 --- a/tests/functional/openlp_core_lib/test_serviceitem.py +++ b/tests/functional/openlp_core_lib/test_serviceitem.py @@ -210,4 +210,5 @@ class TestServiceItem(TestCase): first_line = items[0] except: first_line = u'' - return first_line \ No newline at end of file + return first_line + From 11dea519d2db5b726c9ccf92e764153c259af166 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Sat, 16 Feb 2013 06:51:25 +0000 Subject: [PATCH 38/57] Fix import order --- tests/functional/openlp_core_lib/test_image_manager.py | 5 +++-- tests/functional/openlp_core_lib/test_registry.py | 3 ++- tests/functional/openlp_core_lib/test_serviceitem.py | 3 +-- tests/interfaces/openlp_core_ui/test_servicemanager.py | 6 ++++-- tests/interfaces/openlp_core_ui/test_servicenotedialog.py | 6 ++++-- tests/interfaces/openlp_core_ui/test_starttimedialog.py | 6 ++++-- 6 files changed, 18 insertions(+), 11 deletions(-) diff --git a/tests/functional/openlp_core_lib/test_image_manager.py b/tests/functional/openlp_core_lib/test_image_manager.py index 3ee4abd90..a8fcdfa59 100644 --- a/tests/functional/openlp_core_lib/test_image_manager.py +++ b/tests/functional/openlp_core_lib/test_image_manager.py @@ -3,12 +3,13 @@ """ import os - from unittest import TestCase -from openlp.core.lib import Registry, ImageManager, ScreenList from PyQt4 import QtGui +from openlp.core.lib import Registry, ImageManager, ScreenList + + TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), u'..', u'..', u'resources')) diff --git a/tests/functional/openlp_core_lib/test_registry.py b/tests/functional/openlp_core_lib/test_registry.py index a2fe60627..7bb7c84cf 100644 --- a/tests/functional/openlp_core_lib/test_registry.py +++ b/tests/functional/openlp_core_lib/test_registry.py @@ -2,13 +2,14 @@ Package to test the openlp.core.lib package. """ import os - from unittest import TestCase from mock import MagicMock + from openlp.core.lib import Registry TESTPATH = os.path.abspath(os.path.join(os.path.dirname(__file__), u'..', u'..', u'resources')) + class TestRegistry(TestCase): def registry_service_test(self): diff --git a/tests/functional/openlp_core_lib/test_serviceitem.py b/tests/functional/openlp_core_lib/test_serviceitem.py index a50752cce..05952471d 100644 --- a/tests/functional/openlp_core_lib/test_serviceitem.py +++ b/tests/functional/openlp_core_lib/test_serviceitem.py @@ -3,10 +3,9 @@ """ import os import cPickle - from unittest import TestCase - from mock import MagicMock + from openlp.core.lib import ServiceItem, Registry diff --git a/tests/interfaces/openlp_core_ui/test_servicemanager.py b/tests/interfaces/openlp_core_ui/test_servicemanager.py index b894db470..8ecf3271d 100644 --- a/tests/interfaces/openlp_core_ui/test_servicemanager.py +++ b/tests/interfaces/openlp_core_ui/test_servicemanager.py @@ -1,12 +1,14 @@ """ Package to test the openlp.core.lib package. """ -from unittest import TestCase +from unittest import TestCase from mock import MagicMock + +from PyQt4 import QtGui + from openlp.core.lib import Registry, ScreenList from openlp.core.ui.mainwindow import MainWindow -from PyQt4 import QtGui class TestStartNoteDialog(TestCase): diff --git a/tests/interfaces/openlp_core_ui/test_servicenotedialog.py b/tests/interfaces/openlp_core_ui/test_servicenotedialog.py index f3694fdea..1cf3fef38 100644 --- a/tests/interfaces/openlp_core_ui/test_servicenotedialog.py +++ b/tests/interfaces/openlp_core_ui/test_servicenotedialog.py @@ -2,11 +2,13 @@ Package to test the openlp.core.ui package. """ from unittest import TestCase - from mock import patch + +from PyQt4 import QtCore, QtGui, QtTest + from openlp.core.lib import Registry from openlp.core.ui import servicenoteform -from PyQt4 import QtCore, QtGui, QtTest + class TestStartNoteDialog(TestCase): diff --git a/tests/interfaces/openlp_core_ui/test_starttimedialog.py b/tests/interfaces/openlp_core_ui/test_starttimedialog.py index a9b33a30c..888402235 100644 --- a/tests/interfaces/openlp_core_ui/test_starttimedialog.py +++ b/tests/interfaces/openlp_core_ui/test_starttimedialog.py @@ -2,11 +2,13 @@ Package to test the openlp.core.ui package. """ from unittest import TestCase - from mock import MagicMock, patch + +from PyQt4 import QtCore, QtGui, QtTest + from openlp.core.lib import Registry from openlp.core.ui import starttimeform -from PyQt4 import QtCore, QtGui, QtTest + class TestStartTimeDialog(TestCase): From 60eed1018f72da3d37c5181a2acdfe53784a4a14 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Sat, 16 Feb 2013 10:24:06 +0100 Subject: [PATCH 39/57] fixed merge errors --- openlp/plugins/alerts/forms/alertform.py | 2 +- openlp/plugins/alerts/lib/alertsmanager.py | 2 +- openlp/plugins/images/imageplugin.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/openlp/plugins/alerts/forms/alertform.py b/openlp/plugins/alerts/forms/alertform.py index c09180702..aba13ddb9 100644 --- a/openlp/plugins/alerts/forms/alertform.py +++ b/openlp/plugins/alerts/forms/alertform.py @@ -199,7 +199,7 @@ class AlertForm(QtGui.QDialog, Ui_AlertDialog): self.parameterEdit.setFocus() return False text = text.replace(u'<>', self.parameterEdit.text()) - self.plugin.alertsmanager.displayAlert(text) + self.plugin.alertsmanager.display_alert(text) return True def onCurrentRowChanged(self, row): diff --git a/openlp/plugins/alerts/lib/alertsmanager.py b/openlp/plugins/alerts/lib/alertsmanager.py index b4516cdd5..6db4f2d70 100644 --- a/openlp/plugins/alerts/lib/alertsmanager.py +++ b/openlp/plugins/alerts/lib/alertsmanager.py @@ -108,7 +108,7 @@ class AlertsManager(QtCore.QObject): self.live_controller.display.alert(u'', alertTab.location) self.killTimer(self.timer_id) self.timer_id = 0 - self.generateAlert() + self.generate_alert() def _get_live_controller(self): """ diff --git a/openlp/plugins/images/imageplugin.py b/openlp/plugins/images/imageplugin.py index 6b7705e48..61cc29e01 100644 --- a/openlp/plugins/images/imageplugin.py +++ b/openlp/plugins/images/imageplugin.py @@ -27,7 +27,7 @@ # Temple Place, Suite 330, Boston, MA 02111-1307 USA # ############################################################################### -from PyQt4 import QtCore, QtGui +from PyQt4 import QtGui import logging From 8ad83b52ba747de808440af5bf8a089e0958d39d Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Sat, 16 Feb 2013 10:15:49 +0000 Subject: [PATCH 40/57] Text fix --- tests/functional/openlp_core_lib/test_image_manager.py | 2 +- tests/interfaces/openlp_core_ui/test_servicemanager.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/functional/openlp_core_lib/test_image_manager.py b/tests/functional/openlp_core_lib/test_image_manager.py index a8fcdfa59..d13c82c04 100644 --- a/tests/functional/openlp_core_lib/test_image_manager.py +++ b/tests/functional/openlp_core_lib/test_image_manager.py @@ -41,7 +41,7 @@ class TestImageManager(TestCase): image = self.image_manager.get_image(TEST_PATH, u'church.jpg') # THEN returned record is a type of image - self.assertEqual(isinstance(image, QtGui.QImage), True, u'The returned field is an image') + self.assertEqual(isinstance(image, QtGui.QImage), True, u'The returned object should be a QImage') # WHEN the image is retrieved has not been loaded # THEN a KeyError is thrown diff --git a/tests/interfaces/openlp_core_ui/test_servicemanager.py b/tests/interfaces/openlp_core_ui/test_servicemanager.py index 8ecf3271d..778387ab1 100644 --- a/tests/interfaces/openlp_core_ui/test_servicemanager.py +++ b/tests/interfaces/openlp_core_ui/test_servicemanager.py @@ -40,4 +40,4 @@ class TestStartNoteDialog(TestCase): # WHEN I have an empty display # THEN the count of items should be zero self.assertEqual(self.service_manager.service_manager_list.topLevelItemCount(), 0, - u'There the service manager list is not empty ') + u'The service manager list is not empty ') From 454f42884507adfe01606f0de4fde2a38e867c64 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Sat, 16 Feb 2013 10:17:48 +0000 Subject: [PATCH 41/57] Text fix --- tests/interfaces/openlp_core_ui/test_servicemanager.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/interfaces/openlp_core_ui/test_servicemanager.py b/tests/interfaces/openlp_core_ui/test_servicemanager.py index 778387ab1..bb62bd6e6 100644 --- a/tests/interfaces/openlp_core_ui/test_servicemanager.py +++ b/tests/interfaces/openlp_core_ui/test_servicemanager.py @@ -40,4 +40,4 @@ class TestStartNoteDialog(TestCase): # WHEN I have an empty display # THEN the count of items should be zero self.assertEqual(self.service_manager.service_manager_list.topLevelItemCount(), 0, - u'The service manager list is not empty ') + u'The service manager list should be empty ') From 7e0ea578eee3e7c8a2750dbe6672ecd032ebf642 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Sat, 16 Feb 2013 11:28:37 +0100 Subject: [PATCH 42/57] started with screen tests --- .../openlp_core_lib/test_screenlist.py | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 tests/functional/openlp_core_lib/test_screenlist.py diff --git a/tests/functional/openlp_core_lib/test_screenlist.py b/tests/functional/openlp_core_lib/test_screenlist.py new file mode 100644 index 000000000..e61338d05 --- /dev/null +++ b/tests/functional/openlp_core_lib/test_screenlist.py @@ -0,0 +1,38 @@ +""" +Package to test the openlp.core.lib.screenlist package. +""" +from unittest import TestCase + +#from mock import MagicMock, patch + +from openlp.core.lib import ScreenList + +from PyQt4 import QtGui + +class TestScreenList(object): + + def setUp(self): + """ + Set up the components need for all tests. + """ + self.application = QtGui.QApplication([]) + print ScreenList.create(self.application.desktop()) + self.screen_list = ScreenList() + + def tearDown(self): + """ + Clean up the components needed for the tests. + """ + del self.application + + def basic_test(self): + """ + """ + print self.screen_list.get_screen_list() + + def add_desktop_test(self): + """ + Test to check if new monitors are detected by OpenLP (= plugged in while OpenLP is running). + """ + pass + From 434349b47d117d1eb0f909a1916da4517b2cc78b Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Sat, 16 Feb 2013 12:46:57 +0100 Subject: [PATCH 43/57] fixed test --- tests/functional/openlp_core_lib/test_formattingtags.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/functional/openlp_core_lib/test_formattingtags.py b/tests/functional/openlp_core_lib/test_formattingtags.py index db34dd8bd..6166d6197 100644 --- a/tests/functional/openlp_core_lib/test_formattingtags.py +++ b/tests/functional/openlp_core_lib/test_formattingtags.py @@ -31,7 +31,7 @@ class TestFormattingTags(TestCase): # WHEN: Get the display tags. FormattingTags.load_tags() - old_tags_list = FormattingTags.get_html_tags() + old_tags_list = copy.deepcopy(FormattingTags.get_html_tags()) FormattingTags.load_tags() new_tags_list = FormattingTags.get_html_tags() From f4a28550940aca42d17a97c919400412f5c9468c Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Sat, 16 Feb 2013 14:11:51 +0200 Subject: [PATCH 44/57] Removed an unecessary variable. --- openlp/core/ui/mainwindow.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index b0de61ea5..695c4073a 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -487,8 +487,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): self.timer_id = 0 self.timer_version_id = 0 # Set up the path with plugins - plugin_path = AppLocation.get_directory(AppLocation.PluginsDir) - self.plugin_manager = PluginManager(plugin_path) + self.plugin_manager = PluginManager(AppLocation.get_directory(AppLocation.PluginsDir)) self.imageManager = ImageManager() # Set up the interface self.setupUi(self) From b1ec7aa187337cdb18d2c6ea5eec29c5aa3b68f7 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Sat, 16 Feb 2013 13:27:13 +0100 Subject: [PATCH 45/57] completed screen list test --- openlp/core/__init__.py | 3 +- .../openlp_core_lib/test_image_manager.py | 3 +- .../openlp_core_lib/test_screenlist.py | 46 +++++++++++-------- 3 files changed, 32 insertions(+), 20 deletions(-) diff --git a/openlp/core/__init__.py b/openlp/core/__init__.py index 3ad0e1348..1898c361b 100644 --- a/openlp/core/__init__.py +++ b/openlp/core/__init__.py @@ -276,7 +276,8 @@ def main(args=None): qt_args.append('OpenLP') # Initialise the resources qInitResources() - # Now create and actually run the application. + # Now create and actually run the application.# + print qt_args application = OpenLP(qt_args) application.setOrganizationName(u'OpenLP') application.setOrganizationDomain(u'openlp.org') diff --git a/tests/functional/openlp_core_lib/test_image_manager.py b/tests/functional/openlp_core_lib/test_image_manager.py index d13c82c04..a257fec20 100644 --- a/tests/functional/openlp_core_lib/test_image_manager.py +++ b/tests/functional/openlp_core_lib/test_image_manager.py @@ -28,7 +28,8 @@ class TestImageManager(TestCase): """ Delete all the C++ objects at the end so that we don't have a segfault """ - del self.app + #del self.app + pass def basic_image_manager_test(self): """ diff --git a/tests/functional/openlp_core_lib/test_screenlist.py b/tests/functional/openlp_core_lib/test_screenlist.py index e61338d05..cb7635c71 100644 --- a/tests/functional/openlp_core_lib/test_screenlist.py +++ b/tests/functional/openlp_core_lib/test_screenlist.py @@ -1,38 +1,48 @@ """ Package to test the openlp.core.lib.screenlist package. """ +import copy from unittest import TestCase -#from mock import MagicMock, patch +from mock import MagicMock from openlp.core.lib import ScreenList -from PyQt4 import QtGui +from PyQt4 import QtGui, QtCore -class TestScreenList(object): +class TestScreenList(TestCase): def setUp(self): """ Set up the components need for all tests. """ - self.application = QtGui.QApplication([]) - print ScreenList.create(self.application.desktop()) - self.screen_list = ScreenList() - - def tearDown(self): - """ - Clean up the components needed for the tests. - """ - del self.application - - def basic_test(self): - """ - """ - print self.screen_list.get_screen_list() + self.application = QtGui.QApplication.instance() + self.screens = ScreenList.create(self.application.desktop()) def add_desktop_test(self): """ Test to check if new monitors are detected by OpenLP (= plugged in while OpenLP is running). """ - pass + # GIVEN: The screen list. + old_screens = copy.deepcopy(self.screens.screen_list) + + screen = { + u'primary': False, + u'number': 1, + u'size': QtCore.QRect(0, 0, 1024, 768) + } + # Mock the attributes. + self.screens.desktop.primaryScreen = MagicMock(return_value=screen[u'primary']) + self.screens.desktop.screenCount = MagicMock(return_value=screen[u'number'] + 1) + self.screens.desktop.screenGeometry = MagicMock(return_value=screen[u'size']) + + # WHEN: Add a new screen. + self.screens.screen_count_changed(len(old_screens)) + + # THEN: The screen should have been added. + new_screens = self.screens.screen_list + assert len(old_screens) + 1 == len(new_screens), u'The new_screens list should be bigger.' + + # THEN: The screens should be identically. + assert screen == new_screens.pop(), u'The new screen should be identically to the screen defined above.' From 9ecb575d5b1b2ea4a169a954f9c0c188dc56497c Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Sat, 16 Feb 2013 13:30:16 +0100 Subject: [PATCH 46/57] clean up --- openlp/core/__init__.py | 3 +-- tests/functional/openlp_core_lib/test_image_manager.py | 7 ------- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/openlp/core/__init__.py b/openlp/core/__init__.py index 1898c361b..3ad0e1348 100644 --- a/openlp/core/__init__.py +++ b/openlp/core/__init__.py @@ -276,8 +276,7 @@ def main(args=None): qt_args.append('OpenLP') # Initialise the resources qInitResources() - # Now create and actually run the application.# - print qt_args + # Now create and actually run the application. application = OpenLP(qt_args) application.setOrganizationName(u'OpenLP') application.setOrganizationDomain(u'openlp.org') diff --git a/tests/functional/openlp_core_lib/test_image_manager.py b/tests/functional/openlp_core_lib/test_image_manager.py index a257fec20..10402a808 100644 --- a/tests/functional/openlp_core_lib/test_image_manager.py +++ b/tests/functional/openlp_core_lib/test_image_manager.py @@ -24,13 +24,6 @@ class TestImageManager(TestCase): ScreenList.create(self.app.desktop()) self.image_manager = ImageManager() - def tearDown(self): - """ - Delete all the C++ objects at the end so that we don't have a segfault - """ - #del self.app - pass - def basic_image_manager_test(self): """ Test the Image Manager setup basic functionality From ce1d5b6539642b16d464f3bef012c3f6efbc9a53 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Sat, 16 Feb 2013 13:33:54 +0100 Subject: [PATCH 47/57] fixed import order --- tests/functional/openlp_core_lib/test_screenlist.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/functional/openlp_core_lib/test_screenlist.py b/tests/functional/openlp_core_lib/test_screenlist.py index cb7635c71..4164607de 100644 --- a/tests/functional/openlp_core_lib/test_screenlist.py +++ b/tests/functional/openlp_core_lib/test_screenlist.py @@ -4,11 +4,10 @@ Package to test the openlp.core.lib.screenlist package. import copy from unittest import TestCase -from mock import MagicMock +from PyQt4 import QtGui, QtCore from openlp.core.lib import ScreenList -from PyQt4 import QtGui, QtCore class TestScreenList(TestCase): From b76656420bc31f62183d1d6adf5f32cf23a46698 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Sat, 16 Feb 2013 13:40:19 +0100 Subject: [PATCH 48/57] moved file to match file name --- .../openlp_core_lib/{test_screenlist.py => test_screen.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/functional/openlp_core_lib/{test_screenlist.py => test_screen.py} (100%) diff --git a/tests/functional/openlp_core_lib/test_screenlist.py b/tests/functional/openlp_core_lib/test_screen.py similarity index 100% rename from tests/functional/openlp_core_lib/test_screenlist.py rename to tests/functional/openlp_core_lib/test_screen.py From 479244fde27a0616bd4eaed87d014e10cdd1679c Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Sat, 16 Feb 2013 13:42:25 +0100 Subject: [PATCH 49/57] fixed import I just removed :/ --- tests/functional/openlp_core_lib/test_screen.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/functional/openlp_core_lib/test_screen.py b/tests/functional/openlp_core_lib/test_screen.py index 4164607de..0b708dd94 100644 --- a/tests/functional/openlp_core_lib/test_screen.py +++ b/tests/functional/openlp_core_lib/test_screen.py @@ -4,6 +4,7 @@ Package to test the openlp.core.lib.screenlist package. import copy from unittest import TestCase +from mock import MagicMock from PyQt4 import QtGui, QtCore from openlp.core.lib import ScreenList From bea5fe25963d0b35adfb951b18720d0b7a2c63b2 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Sat, 16 Feb 2013 16:02:19 +0100 Subject: [PATCH 50/57] cleaned code --- tests/functional/__init__.py | 7 ++++++- tests/functional/openlp_core_lib/test_image_manager.py | 8 +++++++- tests/functional/openlp_core_lib/test_screen.py | 5 +++++ tests/interfaces/openlp_core_ui/test_filerenamedialog.py | 2 +- tests/interfaces/openlp_core_ui/test_servicemanager.py | 2 +- tests/interfaces/openlp_core_ui/test_servicenotedialog.py | 4 ++-- tests/interfaces/openlp_core_ui/test_starttimedialog.py | 4 ++-- 7 files changed, 24 insertions(+), 8 deletions(-) diff --git a/tests/functional/__init__.py b/tests/functional/__init__.py index e0da50eb3..0b5157b46 100644 --- a/tests/functional/__init__.py +++ b/tests/functional/__init__.py @@ -5,4 +5,9 @@ sip.setapi(u'QString', 2) sip.setapi(u'QTextStream', 2) sip.setapi(u'QTime', 2) sip.setapi(u'QUrl', 2) -sip.setapi(u'QVariant', 2) \ No newline at end of file +sip.setapi(u'QVariant', 2) + +from PyQt4 import QtGui + +# Only one QApplication can be created. Use QtGui.QApplication.instance() when you need to "create" a QApplication. +application = QtGui.QApplication([]) diff --git a/tests/functional/openlp_core_lib/test_image_manager.py b/tests/functional/openlp_core_lib/test_image_manager.py index 10402a808..3256ef86f 100644 --- a/tests/functional/openlp_core_lib/test_image_manager.py +++ b/tests/functional/openlp_core_lib/test_image_manager.py @@ -20,10 +20,16 @@ class TestImageManager(TestCase): Create the UI """ Registry.create() - self.app = QtGui.QApplication([]) + self.app = QtGui.QApplication.instance() ScreenList.create(self.app.desktop()) self.image_manager = ImageManager() + def tearDown(self): + """ + Delete all the C++ objects at the end so that we don't have a segfault + """ + del self.app + def basic_image_manager_test(self): """ Test the Image Manager setup basic functionality diff --git a/tests/functional/openlp_core_lib/test_screen.py b/tests/functional/openlp_core_lib/test_screen.py index 0b708dd94..8f6631043 100644 --- a/tests/functional/openlp_core_lib/test_screen.py +++ b/tests/functional/openlp_core_lib/test_screen.py @@ -19,6 +19,11 @@ class TestScreenList(TestCase): self.application = QtGui.QApplication.instance() self.screens = ScreenList.create(self.application.desktop()) + def tearDown(self): + """ + """ + del self.application + def add_desktop_test(self): """ Test to check if new monitors are detected by OpenLP (= plugged in while OpenLP is running). diff --git a/tests/interfaces/openlp_core_ui/test_filerenamedialog.py b/tests/interfaces/openlp_core_ui/test_filerenamedialog.py index 74fe83b26..941b1485a 100644 --- a/tests/interfaces/openlp_core_ui/test_filerenamedialog.py +++ b/tests/interfaces/openlp_core_ui/test_filerenamedialog.py @@ -15,7 +15,7 @@ class TestStartFileRenameForm(TestCase): Create the UI """ registry = Registry.create() - self.app = QtGui.QApplication([]) + self.app = QtGui.QApplication.instance() self.main_window = QtGui.QMainWindow() Registry().register(u'main_window', self.main_window) self.form = filerenameform.FileRenameForm() diff --git a/tests/interfaces/openlp_core_ui/test_servicemanager.py b/tests/interfaces/openlp_core_ui/test_servicemanager.py index bb62bd6e6..e06edd4a6 100644 --- a/tests/interfaces/openlp_core_ui/test_servicemanager.py +++ b/tests/interfaces/openlp_core_ui/test_servicemanager.py @@ -18,7 +18,7 @@ class TestStartNoteDialog(TestCase): Create the UI """ Registry.create() - self.app = QtGui.QApplication([]) + self.app = QtGui.QApplication.instance() ScreenList.create(self.app.desktop()) Registry().register(u'application', MagicMock()) self.main_window = MainWindow() diff --git a/tests/interfaces/openlp_core_ui/test_servicenotedialog.py b/tests/interfaces/openlp_core_ui/test_servicenotedialog.py index 1cf3fef38..ee0f842bd 100644 --- a/tests/interfaces/openlp_core_ui/test_servicenotedialog.py +++ b/tests/interfaces/openlp_core_ui/test_servicenotedialog.py @@ -17,7 +17,7 @@ class TestStartNoteDialog(TestCase): Create the UI """ Registry.create() - self.app = QtGui.QApplication([]) + self.app = QtGui.QApplication.instance() self.main_window = QtGui.QMainWindow() Registry().register(u'main_window', self.main_window) self.form = servicenoteform.ServiceNoteForm() @@ -66,4 +66,4 @@ class TestStartNoteDialog(TestCase): QtTest.QTest.mouseClick(okWidget, QtCore.Qt.LeftButton) # THEN the following text is returned - self.assertEqual(self.form.text_edit.toPlainText(), text, u'The new text should be returned') \ No newline at end of file + self.assertEqual(self.form.text_edit.toPlainText(), text, u'The new text should be returned') diff --git a/tests/interfaces/openlp_core_ui/test_starttimedialog.py b/tests/interfaces/openlp_core_ui/test_starttimedialog.py index 888402235..c09426a1f 100644 --- a/tests/interfaces/openlp_core_ui/test_starttimedialog.py +++ b/tests/interfaces/openlp_core_ui/test_starttimedialog.py @@ -17,7 +17,7 @@ class TestStartTimeDialog(TestCase): Create the UI """ Registry.create() - self.app = QtGui.QApplication([]) + self.app = QtGui.QApplication.instance() self.main_window = QtGui.QMainWindow() Registry().register(u'main_window', self.main_window) self.form = starttimeform.StartTimeForm() @@ -93,4 +93,4 @@ class TestStartTimeDialog(TestCase): self.assertEqual(self.form.hourSpinBox.value(), 0) self.assertEqual(self.form.minuteSpinBox.value(), 2) self.assertEqual(self.form.secondSpinBox.value(), 3) - self.assertEqual(self.form.item[u'service_item'].start_time, 123, u'The start time should have changed') \ No newline at end of file + self.assertEqual(self.form.item[u'service_item'].start_time, 123, u'The start time should have changed') From a24ff2a4a2ed8fcc763fd020ee382aa3458496f6 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Sat, 16 Feb 2013 17:05:39 +0100 Subject: [PATCH 51/57] added newline to end of file --- tests/interfaces/openlp_core_ui/test_servicenotedialog.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/interfaces/openlp_core_ui/test_servicenotedialog.py b/tests/interfaces/openlp_core_ui/test_servicenotedialog.py index ee0f842bd..e04f9975d 100644 --- a/tests/interfaces/openlp_core_ui/test_servicenotedialog.py +++ b/tests/interfaces/openlp_core_ui/test_servicenotedialog.py @@ -67,3 +67,4 @@ class TestStartNoteDialog(TestCase): # THEN the following text is returned self.assertEqual(self.form.text_edit.toPlainText(), text, u'The new text should be returned') + From fab327c89fd458302120943afdb8ea9741889092 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Sat, 16 Feb 2013 19:04:17 +0100 Subject: [PATCH 52/57] moved application creation --- tests/interfaces/__init__.py | 7 ++++++- tests/interfaces/openlp_core_lib/test_pluginmanager.py | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/interfaces/__init__.py b/tests/interfaces/__init__.py index e0da50eb3..0b5157b46 100644 --- a/tests/interfaces/__init__.py +++ b/tests/interfaces/__init__.py @@ -5,4 +5,9 @@ sip.setapi(u'QString', 2) sip.setapi(u'QTextStream', 2) sip.setapi(u'QTime', 2) sip.setapi(u'QUrl', 2) -sip.setapi(u'QVariant', 2) \ No newline at end of file +sip.setapi(u'QVariant', 2) + +from PyQt4 import QtGui + +# Only one QApplication can be created. Use QtGui.QApplication.instance() when you need to "create" a QApplication. +application = QtGui.QApplication([]) diff --git a/tests/interfaces/openlp_core_lib/test_pluginmanager.py b/tests/interfaces/openlp_core_lib/test_pluginmanager.py index 609af01fb..498803c44 100644 --- a/tests/interfaces/openlp_core_lib/test_pluginmanager.py +++ b/tests/interfaces/openlp_core_lib/test_pluginmanager.py @@ -26,7 +26,7 @@ class TestPluginManager(TestCase): Settings().set_filename(self.ini_file) Registry.create() Registry().register(u'service_list', MagicMock()) - self.app = QtGui.QApplication([]) + self.app = QtGui.QApplication.instance() self.main_window = QtGui.QMainWindow() Registry().register(u'main_window', self.main_window) self.plugins_dir = os.path.abspath(os.path.join(os.path.basename(__file__), u'..', u'openlp', u'plugins')) From 10f7a464b4abc797d911228c92da405def0fdc2b Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Sat, 16 Feb 2013 19:06:23 +0100 Subject: [PATCH 53/57] delete appliction in tearDown --- tests/interfaces/openlp_core_lib/test_pluginmanager.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/interfaces/openlp_core_lib/test_pluginmanager.py b/tests/interfaces/openlp_core_lib/test_pluginmanager.py index 498803c44..ca8ed3f07 100644 --- a/tests/interfaces/openlp_core_lib/test_pluginmanager.py +++ b/tests/interfaces/openlp_core_lib/test_pluginmanager.py @@ -33,6 +33,7 @@ class TestPluginManager(TestCase): def tearDown(self): os.unlink(self.ini_file) + del self.app def find_plugins_test(self): """ From db00a864fcf4aafd0fc94f671cb6703d73e5476a Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Sat, 16 Feb 2013 19:11:22 +0100 Subject: [PATCH 54/57] fixed test method descriptions; created costant --- .../openlp_core_lib/test_formattingtags.py | 28 ++++++++++--------- .../openlp_core_lib/test_uistrings.py | 2 +- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/tests/functional/openlp_core_lib/test_formattingtags.py b/tests/functional/openlp_core_lib/test_formattingtags.py index 6166d6197..335650112 100644 --- a/tests/functional/openlp_core_lib/test_formattingtags.py +++ b/tests/functional/openlp_core_lib/test_formattingtags.py @@ -9,6 +9,16 @@ from mock import patch from openlp.core.lib import FormattingTags +TAG = { + u'end tag': '{/aa}', + u'start html': '', + u'start tag': '{aa}', + u'protected': False, + u'end html': '', + u'desc': 'name' +} + + class TestFormattingTags(TestCase): def tearDown(self): @@ -19,7 +29,7 @@ class TestFormattingTags(TestCase): def get_html_tags_no_user_tags_test(self): """ - Test the get_html_tags static method. + Test the FormattingTags class' get_html_tags static method. """ with patch(u'openlp.core.lib.translate') as mocked_translate, \ patch(u'openlp.core.lib.settings') as mocked_settings, \ @@ -40,7 +50,7 @@ class TestFormattingTags(TestCase): def get_html_tags_with_user_tags_test(self): """ - Add a tag and check if it still exists after reloading the tags list. + Test the FormattingTags class' get_html_tags static method in combination with user tags. """ with patch(u'openlp.core.lib.translate') as mocked_translate, \ patch(u'openlp.core.lib.settings') as mocked_settings, \ @@ -48,15 +58,7 @@ class TestFormattingTags(TestCase): # GIVEN: Our mocked modules and functions. mocked_translate.side_effect = lambda module, string_to_translate: string_to_translate mocked_settings.value.return_value = u'' - tag = { - u'end tag': '{/aa}', - u'start html': '', - u'start tag': '{aa}', - u'protected': False, - u'end html': '', - u'desc': 'name' - } - mocked_cPickle.loads.side_effect = [[], [tag]] + mocked_cPickle.loads.side_effect = [[], [TAG]] # WHEN: Get the display tags. FormattingTags.load_tags() @@ -64,7 +66,7 @@ class TestFormattingTags(TestCase): # WHEN: Add our tag and get the tags again. FormattingTags.load_tags() - FormattingTags.add_html_tags([tag]) + FormattingTags.add_html_tags([TAG]) new_tags_list = FormattingTags.get_html_tags() # THEN: Lists should not be identically. @@ -72,5 +74,5 @@ class TestFormattingTags(TestCase): # THEN: Added tag and last tag should be the same. new_tag = new_tags_list.pop() - assert tag == new_tag, u'Tags should be identically.' + assert TAG == new_tag, u'Tags should be identically.' diff --git a/tests/functional/openlp_core_lib/test_uistrings.py b/tests/functional/openlp_core_lib/test_uistrings.py index e0d0fc485..3351657d1 100644 --- a/tests/functional/openlp_core_lib/test_uistrings.py +++ b/tests/functional/openlp_core_lib/test_uistrings.py @@ -10,7 +10,7 @@ class TestUiStrings(TestCase): def check_same_instance_test(self): """ - Test if the always only one instance of the UiStrings is created. + Test the UiStrings class - we always should have only one instance of the UiStrings class. """ # WHEN: Create two instances of the UiStrings class. first_instance = UiStrings() From 5b4e285782cb6d36cb09467027a3433754059938 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Sat, 16 Feb 2013 19:14:41 +0100 Subject: [PATCH 55/57] created constant; changed test method description --- .../functional/openlp_core_lib/test_screen.py | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/tests/functional/openlp_core_lib/test_screen.py b/tests/functional/openlp_core_lib/test_screen.py index 8f6631043..92dd48172 100644 --- a/tests/functional/openlp_core_lib/test_screen.py +++ b/tests/functional/openlp_core_lib/test_screen.py @@ -10,6 +10,13 @@ from PyQt4 import QtGui, QtCore from openlp.core.lib import ScreenList +SCREEN = { + u'primary': False, + u'number': 1, + u'size': QtCore.QRect(0, 0, 1024, 768) +} + + class TestScreenList(TestCase): def setUp(self): @@ -21,25 +28,20 @@ class TestScreenList(TestCase): def tearDown(self): """ + Delete QApplication. """ del self.application def add_desktop_test(self): """ - Test to check if new monitors are detected by OpenLP (= plugged in while OpenLP is running). + Test the ScreenList class' screen_count_changed method to check if new monitors are detected by OpenLP. """ # GIVEN: The screen list. old_screens = copy.deepcopy(self.screens.screen_list) - - screen = { - u'primary': False, - u'number': 1, - u'size': QtCore.QRect(0, 0, 1024, 768) - } # Mock the attributes. - self.screens.desktop.primaryScreen = MagicMock(return_value=screen[u'primary']) - self.screens.desktop.screenCount = MagicMock(return_value=screen[u'number'] + 1) - self.screens.desktop.screenGeometry = MagicMock(return_value=screen[u'size']) + self.screens.desktop.primaryScreen = MagicMock(return_value=SCREEN[u'primary']) + self.screens.desktop.screenCount = MagicMock(return_value=SCREEN[u'number'] + 1) + self.screens.desktop.screenGeometry = MagicMock(return_value=SCREEN[u'size']) # WHEN: Add a new screen. self.screens.screen_count_changed(len(old_screens)) @@ -49,5 +51,5 @@ class TestScreenList(TestCase): assert len(old_screens) + 1 == len(new_screens), u'The new_screens list should be bigger.' # THEN: The screens should be identically. - assert screen == new_screens.pop(), u'The new screen should be identically to the screen defined above.' + assert SCREEN == new_screens.pop(), u'The new screen should be identically to the screen defined above.' From 573f687d9efbc7354b35888c61182c2d97ba3ddb Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Sat, 16 Feb 2013 21:00:31 +0100 Subject: [PATCH 56/57] fixed spaces/lines --- tests/functional/openlp_core_lib/test_serviceitem.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/functional/openlp_core_lib/test_serviceitem.py b/tests/functional/openlp_core_lib/test_serviceitem.py index 05952471d..b731eaf00 100644 --- a/tests/functional/openlp_core_lib/test_serviceitem.py +++ b/tests/functional/openlp_core_lib/test_serviceitem.py @@ -17,7 +17,6 @@ VERSE = u'The Lord said to {r}Noah{/r}: \n'\ '{r}C{/r}{b}h{/b}{bl}i{/bl}{y}l{/y}{g}d{/g}{pk}'\ 'r{/pk}{o}e{/o}{pp}n{/pp} of the Lord\n' FOOTER = [u'Arky Arky (Unknown)', u'Public Domain', u'CCLI 123456'] - TESTPATH = os.path.abspath(os.path.join(os.path.dirname(__file__), u'..', u'..', u'resources')) @@ -39,7 +38,7 @@ class TestServiceItem(TestCase): """ # GIVEN: A new service item - # WHEN:A service item is created (without a plugin) + # WHEN: A service item is created (without a plugin) service_item = ServiceItem(None) # THEN: We should get back a valid service item @@ -209,4 +208,5 @@ class TestServiceItem(TestCase): first_line = items[0] except: first_line = u'' - return first_line \ No newline at end of file + return first_line + From ba37105bbfcad8fb8dfb83aae5ff68df813517cf Mon Sep 17 00:00:00 2001 From: phill-ridout Date: Sun, 17 Feb 2013 08:29:23 +0000 Subject: [PATCH 57/57] Fixed OpenLP not starting --- openlp/plugins/presentations/lib/pptviewcontroller.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openlp/plugins/presentations/lib/pptviewcontroller.py b/openlp/plugins/presentations/lib/pptviewcontroller.py index af66f623d..a2dc56f52 100644 --- a/openlp/plugins/presentations/lib/pptviewcontroller.py +++ b/openlp/plugins/presentations/lib/pptviewcontroller.py @@ -84,7 +84,7 @@ class PptviewController(PresentationController): if self.process: return log.debug(u'start PPTView') - dllpath = os.path.join(self.plugin_manager.basepath, u'presentations', u'lib', u'pptviewlib', + dllpath = os.path.join(self.plugin_manager.base_path, u'presentations', u'lib', u'pptviewlib', u'pptviewlib.dll') self.process = cdll.LoadLibrary(dllpath) if log.isEnabledFor(logging.DEBUG):