From 31ee1b43a6d50275272d4e5cce779164f4c3cdaf Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Wed, 12 Mar 2014 17:41:52 +0000 Subject: [PATCH 1/8] first view --- openlp/core/common/__init__.py | 1 + openlp/core/common/registryproperties.py | 124 +++++++++++++++++++++++ openlp/core/ui/mainwindow.py | 26 ++--- openlp/core/ui/slidecontroller.py | 65 +----------- 4 files changed, 135 insertions(+), 81 deletions(-) create mode 100644 openlp/core/common/registryproperties.py diff --git a/openlp/core/common/__init__.py b/openlp/core/common/__init__.py index c6f96a616..1f252e50d 100644 --- a/openlp/core/common/__init__.py +++ b/openlp/core/common/__init__.py @@ -131,6 +131,7 @@ def de_hump(name): from .openlpmixin import OpenLPMixin from .registry import Registry from .registrymixin import RegistryMixin +from .registryproperties import RegistryProperties from .uistrings import UiStrings from .settings import Settings from .applocation import AppLocation diff --git a/openlp/core/common/registryproperties.py b/openlp/core/common/registryproperties.py new file mode 100644 index 000000000..8cf8a6930 --- /dev/null +++ b/openlp/core/common/registryproperties.py @@ -0,0 +1,124 @@ +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 + +############################################################################### +# OpenLP - Open Source Lyrics Projection # +# --------------------------------------------------------------------------- # +# Copyright (c) 2008-2014 Raoul Snyman # +# Portions copyright (c) 2008-2014 Tim Bentley, Gerald Britton, Jonathan # +# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, # +# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. # +# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, # +# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, # +# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, # +# Frode Woldsund, Martin Zibricky, Patrick Zimmermann # +# --------------------------------------------------------------------------- # +# This program is free software; you can redistribute it and/or modify it # +# under the terms of the GNU General Public License as published by the Free # +# Software Foundation; version 2 of the License. # +# # +# This program is distributed in the hope that it will be useful, but WITHOUT # +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # +# more details. # +# # +# You should have received a copy of the GNU General Public License along # +# with this program; if not, write to the Free Software Foundation, Inc., 59 # +# Temple Place, Suite 330, Boston, MA 02111-1307 USA # +############################################################################### +""" +Provide Registry values for adding to classes +""" +import os + +from openlp.core.common import Registry + + +class RegistryProperties(object): + """ + This adds registry components to classes to use at run time. + """ + + def _get_application(self): + """ + Adds the openlp to the class dynamically. + Windows needs to access the application in a dynamic manner. + """ + if os.name == 'nt': + return Registry().get('application') + else: + if not hasattr(self, '_application') or not self._application: + self._application = Registry().get('application') + return self._application + + application = property(_get_application) + + def _get_plugin_manager(self): + """ + Adds the plugin manager to the class dynamically + """ + if not hasattr(self, '_plugin_manager') or not self._plugin_manager: + self._plugin_manager = Registry().get('plugin_manager') + return self._plugin_manager + + plugin_manager = property(_get_plugin_manager) + + def _get_image_manager(self): + """ + Adds the image manager to the class dynamically + """ + if not hasattr(self, '_image_manager') or not self._image_manager: + self._image_manager = Registry().get('image_manager') + return self._image_manager + + image_manager = property(_get_image_manager) + + def _get_media_controller(self): + """ + Adds the media controller to the class dynamically + """ + if not hasattr(self, '_media_controller') or not self._media_controller: + self._media_controller = Registry().get('media_controller') + return self._media_controller + + media_controller = property(_get_media_controller) + + def _get_service_manager(self): + """ + Adds the service manager to the class dynamically + """ + if not hasattr(self, '_service_manager') or not self._service_manager: + self._service_manager = Registry().get('service_manager') + return self._service_manager + + service_manager = property(_get_service_manager) + + def _get_preview_controller(self): + """ + Adds the live controller to the class dynamically + """ + if not hasattr(self, '_preview_controller') or not self._preview_controller: + self._preview_controller = Registry().get('preview_controller') + return self._preview_controller + + preview_controller = property(_get_preview_controller) + + def _get_live_controller(self): + """ + Adds the live controller to the class dynamically + """ + if not hasattr(self, '_live_controller') or not self._live_controller: + self._live_controller = Registry().get('live_controller') + return self._live_controller + + live_controller = property(_get_live_controller) + + def _get_main_window(self): + """ + Adds the main window to the class dynamically + """ + if not hasattr(self, '_main_window') or not self._main_window: + self._main_window = Registry().get('main_window') + return self._main_window + + main_window = property(_get_main_window) diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index 67f75f953..664b1ec6d 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -41,7 +41,7 @@ from datetime import datetime from PyQt4 import QtCore, QtGui -from openlp.core.common import Registry, AppLocation, Settings, check_directory_exists, translate +from openlp.core.common import Registry, RegistryProperties, AppLocation, Settings, check_directory_exists, translate from openlp.core.lib import Renderer, OpenLPDockWidget, PluginManager, ImageManager, PluginStatus, ScreenList, \ build_icon from openlp.core.lib.ui import UiStrings, create_action @@ -106,8 +106,8 @@ class Ui_MainWindow(object): self.control_splitter.setObjectName('control_splitter') self.main_content_layout.addWidget(self.control_splitter) # Create slide controllers - self.preview_controller = PreviewController(self) - self.live_controller = LiveController(self) + PreviewController(self) + LiveController(self) preview_visible = Settings().value('user interface/preview panel') live_visible = Settings().value('user interface/live panel') panel_locked = Settings().value('user interface/lock panel') @@ -460,7 +460,7 @@ class Ui_MainWindow(object): self.mode_live_item.setStatusTip(translate('OpenLP.MainWindow', 'Set the view mode to Live.')) -class MainWindow(QtGui.QMainWindow, Ui_MainWindow): +class MainWindow(RegistryProperties, QtGui.QMainWindow, Ui_MainWindow): """ The main window. """ @@ -492,13 +492,13 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): self.copy_data = False Settings().set_up_default_values() self.about_form = AboutForm(self) - self.media_controller = MediaController() + MediaController() self.settings_form = SettingsForm(self) self.formatting_tag_form = FormattingTagForm(self) self.shortcut_form = ShortcutListForm(self) # Set up the path with plugins - self.plugin_manager = PluginManager(self) - self.image_manager = ImageManager() + PluginManager(self) + ImageManager() self.renderer = Renderer() # Set up the interface self.setupUi(self) @@ -1380,16 +1380,4 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): settings.remove('advanced/data path') self.application.set_normal_cursor() - def _get_application(self): - """ - Adds the openlp to the class dynamically. - Windows needs to access the application in a dynamic manner. - """ - if os.name == 'nt': - return Registry().get('application') - else: - if not hasattr(self, '_application'): - self._application = Registry().get('application') - return self._application - application = property(_get_application) diff --git a/openlp/core/ui/slidecontroller.py b/openlp/core/ui/slidecontroller.py index 34a2df909..432234f5b 100644 --- a/openlp/core/ui/slidecontroller.py +++ b/openlp/core/ui/slidecontroller.py @@ -36,7 +36,8 @@ from collections import deque from PyQt4 import QtCore, QtGui -from openlp.core.common import Registry, Settings, SlideLimits, UiStrings, translate, RegistryMixin, OpenLPMixin +from openlp.core.common import Registry, RegistryProperties, Settings, SlideLimits, UiStrings, translate, \ + RegistryMixin, OpenLPMixin from openlp.core.lib import OpenLPToolbar, ItemCapabilities, ServiceItem, ImageSource, ServiceItemAction, \ ScreenList, build_icon, build_html from openlp.core.ui import HideMode, MainDisplay, Display, DisplayControllerType @@ -101,7 +102,7 @@ class DisplayController(QtGui.QWidget): Registry().execute('%s' % sender, [controller, args]) -class SlideController(DisplayController): +class SlideController(RegistryProperties, DisplayController): """ SlideController is the slide controller widget. This widget is what the user uses to control the displaying of verses/slides/etc on the screen. @@ -1338,66 +1339,6 @@ class SlideController(DisplayController): action = self.sender() self.display.audio_player.go_to(action.data()) - def _get_plugin_manager(self): - """ - Adds the plugin manager to the class dynamically - """ - if not hasattr(self, '_plugin_manager'): - self._plugin_manager = Registry().get('plugin_manager') - return self._plugin_manager - - plugin_manager = property(_get_plugin_manager) - - def _get_image_manager(self): - """ - Adds the image manager to the class dynamically - """ - if not hasattr(self, '_image_manager'): - self._image_manager = Registry().get('image_manager') - return self._image_manager - - image_manager = property(_get_image_manager) - - def _get_media_controller(self): - """ - Adds the media controller to the class dynamically - """ - if not hasattr(self, '_media_controller'): - self._media_controller = Registry().get('media_controller') - return self._media_controller - - media_controller = property(_get_media_controller) - - def _get_service_manager(self): - """ - Adds the service manager to the class dynamically - """ - if not hasattr(self, '_service_manager') or not self._service_manager: - self._service_manager = Registry().get('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, '_live_controller'): - self._live_controller = Registry().get('live_controller') - return self._live_controller - - live_controller = property(_get_live_controller) - - def _get_main_window(self): - """ - Adds the main window to the class dynamically - """ - if not hasattr(self, '_main_window'): - self._main_window = Registry().get('main_window') - return self._main_window - - main_window = property(_get_main_window) - class PreviewController(RegistryMixin, OpenLPMixin, SlideController): """ From 5e6f97d74e572c8eb470bd95fa0af3d81f89541d Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Thu, 13 Mar 2014 20:08:47 +0000 Subject: [PATCH 2/8] fix order and comment --- openlp/core/common/registryproperties.py | 2 +- openlp/core/ui/mainwindow.py | 2 +- openlp/core/ui/slidecontroller.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/openlp/core/common/registryproperties.py b/openlp/core/common/registryproperties.py index 8cf8a6930..f180ed1a0 100644 --- a/openlp/core/common/registryproperties.py +++ b/openlp/core/common/registryproperties.py @@ -95,7 +95,7 @@ class RegistryProperties(object): def _get_preview_controller(self): """ - Adds the live controller to the class dynamically + Adds the preview controller to the class dynamically """ if not hasattr(self, '_preview_controller') or not self._preview_controller: self._preview_controller = Registry().get('preview_controller') diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index 664b1ec6d..29213c2af 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -460,7 +460,7 @@ class Ui_MainWindow(object): self.mode_live_item.setStatusTip(translate('OpenLP.MainWindow', 'Set the view mode to Live.')) -class MainWindow(RegistryProperties, QtGui.QMainWindow, Ui_MainWindow): +class MainWindow(QtGui.QMainWindow, Ui_MainWindow, RegistryProperties): """ The main window. """ diff --git a/openlp/core/ui/slidecontroller.py b/openlp/core/ui/slidecontroller.py index 432234f5b..80835b97f 100644 --- a/openlp/core/ui/slidecontroller.py +++ b/openlp/core/ui/slidecontroller.py @@ -102,7 +102,7 @@ class DisplayController(QtGui.QWidget): Registry().execute('%s' % sender, [controller, args]) -class SlideController(RegistryProperties, DisplayController): +class SlideController(DisplayController, RegistryProperties): """ SlideController is the slide controller widget. This widget is what the user uses to control the displaying of verses/slides/etc on the screen. From ea99cbb08dcaaea0add21b75a174d1887e65ee36 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Thu, 13 Mar 2014 20:20:42 +0000 Subject: [PATCH 3/8] use decorator --- openlp/core/common/registryproperties.py | 39 ++++++++++-------------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/openlp/core/common/registryproperties.py b/openlp/core/common/registryproperties.py index f180ed1a0..2564947a8 100644 --- a/openlp/core/common/registryproperties.py +++ b/openlp/core/common/registryproperties.py @@ -39,7 +39,8 @@ class RegistryProperties(object): This adds registry components to classes to use at run time. """ - def _get_application(self): + @property + def application(self): """ Adds the openlp to the class dynamically. Windows needs to access the application in a dynamic manner. @@ -51,9 +52,8 @@ class RegistryProperties(object): self._application = Registry().get('application') return self._application - application = property(_get_application) - - def _get_plugin_manager(self): + @property + def plugin_manager(self): """ Adds the plugin manager to the class dynamically """ @@ -61,9 +61,8 @@ class RegistryProperties(object): self._plugin_manager = Registry().get('plugin_manager') return self._plugin_manager - plugin_manager = property(_get_plugin_manager) - - def _get_image_manager(self): + @property + def image_manager(self): """ Adds the image manager to the class dynamically """ @@ -71,9 +70,8 @@ class RegistryProperties(object): self._image_manager = Registry().get('image_manager') return self._image_manager - image_manager = property(_get_image_manager) - - def _get_media_controller(self): + @property + def media_controller(self): """ Adds the media controller to the class dynamically """ @@ -81,9 +79,8 @@ class RegistryProperties(object): self._media_controller = Registry().get('media_controller') return self._media_controller - media_controller = property(_get_media_controller) - - def _get_service_manager(self): + @property + def service_manager(self): """ Adds the service manager to the class dynamically """ @@ -91,9 +88,8 @@ class RegistryProperties(object): self._service_manager = Registry().get('service_manager') return self._service_manager - service_manager = property(_get_service_manager) - - def _get_preview_controller(self): + @property + def preview_controller(self): """ Adds the preview controller to the class dynamically """ @@ -101,9 +97,8 @@ class RegistryProperties(object): self._preview_controller = Registry().get('preview_controller') return self._preview_controller - preview_controller = property(_get_preview_controller) - - def _get_live_controller(self): + @property + def live_controller(self): """ Adds the live controller to the class dynamically """ @@ -111,9 +106,8 @@ class RegistryProperties(object): self._live_controller = Registry().get('live_controller') return self._live_controller - live_controller = property(_get_live_controller) - - def _get_main_window(self): + @property + def main_window(self): """ Adds the main window to the class dynamically """ @@ -121,4 +115,3 @@ class RegistryProperties(object): self._main_window = Registry().get('main_window') return self._main_window - main_window = property(_get_main_window) From 9051692dba53dbb2c667ca0a7dad8506f64d9e52 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Thu, 13 Mar 2014 20:34:46 +0000 Subject: [PATCH 4/8] Mixin for tests --- tests/helpers/testmixin.py | 54 +++++++++++++++++++ .../openlp_core_ui/test_filerenamedialog.py | 10 ++-- .../openlp_core_ui/test_thememanager.py | 12 ++--- 3 files changed, 62 insertions(+), 14 deletions(-) create mode 100644 tests/helpers/testmixin.py diff --git a/tests/helpers/testmixin.py b/tests/helpers/testmixin.py new file mode 100644 index 000000000..a087bd475 --- /dev/null +++ b/tests/helpers/testmixin.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 + +############################################################################### +# OpenLP - Open Source Lyrics Projection # +# --------------------------------------------------------------------------- # +# Copyright (c) 2008-2014 Raoul Snyman # +# Portions copyright (c) 2008-2014 Tim Bentley, Gerald Britton, Jonathan # +# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, # +# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. # +# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, # +# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, # +# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, # +# Frode Woldsund, Martin Zibricky, Patrick Zimmermann # +# --------------------------------------------------------------------------- # +# This program is free software; you can redistribute it and/or modify it # +# under the terms of the GNU General Public License as published by the Free # +# Software Foundation; version 2 of the License. # +# # +# This program is distributed in the hope that it will be useful, but WITHOUT # +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # +# more details. # +# # +# You should have received a copy of the GNU General Public License along # +# with this program; if not, write to the Free Software Foundation, Inc., 59 # +# Temple Place, Suite 330, Boston, MA 02111-1307 USA # +############################################################################### +""" +Mixin class with helpers +""" +import os +from tempfile import mkstemp + +from PyQt4 import QtCore, QtGui +from openlp.core.common import Settings + + +class TestMixin(object): + + def get_application(self): + old_app_instance = QtCore.QCoreApplication.instance() + if old_app_instance is None: + self.app = QtGui.QApplication([]) + else: + self.app = old_app_instance + + def build_settings(self): + Settings.setDefaultFormat(Settings.IniFormat) + fd, self.ini_file = mkstemp('.ini') + Settings().set_filename(self.ini_file) + + def destroy_settings(self): + os.unlink(Settings().fileName()) \ No newline at end of file diff --git a/tests/interfaces/openlp_core_ui/test_filerenamedialog.py b/tests/interfaces/openlp_core_ui/test_filerenamedialog.py index 8fac36213..3ddf48f28 100644 --- a/tests/interfaces/openlp_core_ui/test_filerenamedialog.py +++ b/tests/interfaces/openlp_core_ui/test_filerenamedialog.py @@ -8,20 +8,16 @@ from PyQt4 import QtCore, QtGui, QtTest from openlp.core.common import Registry from openlp.core.ui import filerenameform from tests.interfaces import MagicMock, patch +from tests.helpers.testmixin import TestMixin - -class TestStartFileRenameForm(TestCase): +class TestStartFileRenameForm(TestCase, TestMixin): def setUp(self): """ Create the UI """ Registry.create() - old_app_instance = QtCore.QCoreApplication.instance() - if old_app_instance is None: - self.app = QtGui.QApplication([]) - else: - self.app = old_app_instance + self.get_application() self.main_window = QtGui.QMainWindow() Registry().register('main_window', self.main_window) self.form = filerenameform.FileRenameForm() diff --git a/tests/interfaces/openlp_core_ui/test_thememanager.py b/tests/interfaces/openlp_core_ui/test_thememanager.py index 6bffcf4eb..a539d4e44 100644 --- a/tests/interfaces/openlp_core_ui/test_thememanager.py +++ b/tests/interfaces/openlp_core_ui/test_thememanager.py @@ -29,18 +29,17 @@ """ Interface tests to test the themeManager class and related methods. """ -import os from unittest import TestCase -from tempfile import mkstemp from PyQt4 import QtGui, QtCore from openlp.core.common import Registry, Settings from openlp.core.ui import ThemeManager from tests.functional import patch, MagicMock +from tests.helpers.testmixin import TestMixin -class TestThemeManager(TestCase): +class TestThemeManager(TestCase, TestMixin): """ Test the functions in the ThemeManager module """ @@ -48,9 +47,8 @@ class TestThemeManager(TestCase): """ Create the UI """ - Settings.setDefaultFormat(Settings.IniFormat) - fd, self.ini_file = mkstemp('.ini') - Settings().set_filename(self.ini_file) + self.build_settings() + self.get_application() old_app_instance = QtCore.QCoreApplication.instance() if old_app_instance is None: self.app = QtGui.QApplication([]) @@ -63,7 +61,7 @@ class TestThemeManager(TestCase): """ Delete all the C++ objects at the end so that we don't have a segfault """ - os.unlink(Settings().fileName()) + self.destroy_settings() def initialise_test(self): """ From 17f33712db18f348a3d567e25543a29beb6b87fd Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Thu, 13 Mar 2014 20:37:02 +0000 Subject: [PATCH 5/8] minor fixes --- tests/helpers/testmixin.py | 2 +- tests/interfaces/openlp_core_ui/test_thememanager.py | 9 +-------- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/tests/helpers/testmixin.py b/tests/helpers/testmixin.py index a087bd475..9a8070952 100644 --- a/tests/helpers/testmixin.py +++ b/tests/helpers/testmixin.py @@ -51,4 +51,4 @@ class TestMixin(object): Settings().set_filename(self.ini_file) def destroy_settings(self): - os.unlink(Settings().fileName()) \ No newline at end of file + os.unlink(Settings().fileName()) diff --git a/tests/interfaces/openlp_core_ui/test_thememanager.py b/tests/interfaces/openlp_core_ui/test_thememanager.py index a539d4e44..8f5b52147 100644 --- a/tests/interfaces/openlp_core_ui/test_thememanager.py +++ b/tests/interfaces/openlp_core_ui/test_thememanager.py @@ -31,8 +31,6 @@ Interface tests to test the themeManager class and related methods. """ from unittest import TestCase -from PyQt4 import QtGui, QtCore - from openlp.core.common import Registry, Settings from openlp.core.ui import ThemeManager from tests.functional import patch, MagicMock @@ -49,11 +47,6 @@ class TestThemeManager(TestCase, TestMixin): """ self.build_settings() self.get_application() - old_app_instance = QtCore.QCoreApplication.instance() - if old_app_instance is None: - self.app = QtGui.QApplication([]) - else: - self.app = old_app_instance Registry.create() self.theme_manager = ThemeManager() @@ -72,7 +65,7 @@ class TestThemeManager(TestCase, TestMixin): self.theme_manager.load_first_time_themes = MagicMock() Settings().setValue('themes/global theme', 'my_theme') - # WHEN: the initialistion is run + # WHEN: the initialisation is run self.theme_manager.bootstrap_initialise() # THEN: From c2a429c52dcc0d56b6b9e8a371efc8105f3ccffe Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Fri, 14 Mar 2014 17:35:00 +0000 Subject: [PATCH 6/8] Space --- tests/interfaces/openlp_core_ui/test_filerenamedialog.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/interfaces/openlp_core_ui/test_filerenamedialog.py b/tests/interfaces/openlp_core_ui/test_filerenamedialog.py index 3ddf48f28..2bd3fc889 100644 --- a/tests/interfaces/openlp_core_ui/test_filerenamedialog.py +++ b/tests/interfaces/openlp_core_ui/test_filerenamedialog.py @@ -10,6 +10,7 @@ from openlp.core.ui import filerenameform from tests.interfaces import MagicMock, patch from tests.helpers.testmixin import TestMixin + class TestStartFileRenameForm(TestCase, TestMixin): def setUp(self): From 9dd4669f13b527d6f9e7eb0bbafc88b562e9395d Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Fri, 14 Mar 2014 17:38:57 +0000 Subject: [PATCH 7/8] test fixes --- tests/helpers/testmixin.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/helpers/testmixin.py b/tests/helpers/testmixin.py index 54507c937..69b5704e7 100644 --- a/tests/helpers/testmixin.py +++ b/tests/helpers/testmixin.py @@ -51,5 +51,6 @@ class TestMixin(object): Settings().set_filename(self.ini_file) def destroy_settings(self): - os.close(self.fd) + if hasattr(self, 'fd'): + os.close(self.fd) os.unlink(Settings().fileName()) From 1fa0d58f85965137cef3e8af5329dad093070e7c Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Fri, 14 Mar 2014 20:06:24 +0000 Subject: [PATCH 8/8] Tests --- .../test_registryproperties.py | 60 +++++++++++++++++++ .../openlp_core_ui/test_filerenamedialog.py | 28 +++++++++ .../openlp_core_ui/test_servicenotedialog.py | 28 +++++++++ .../openlp_core_ui/test_settings_form.py | 28 +++++++++ 4 files changed, 144 insertions(+) create mode 100644 tests/functional/openlp_core_common/test_registryproperties.py diff --git a/tests/functional/openlp_core_common/test_registryproperties.py b/tests/functional/openlp_core_common/test_registryproperties.py new file mode 100644 index 000000000..d12975f43 --- /dev/null +++ b/tests/functional/openlp_core_common/test_registryproperties.py @@ -0,0 +1,60 @@ +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 + +############################################################################### +# OpenLP - Open Source Lyrics Projection # +# --------------------------------------------------------------------------- # +# Copyright (c) 2008-2014 Raoul Snyman # +# Portions copyright (c) 2008-2014 Tim Bentley, Gerald Britton, Jonathan # +# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, # +# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. # +# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, # +# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, # +# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, # +# Frode Woldsund, Martin Zibricky, Patrick Zimmermann # +# --------------------------------------------------------------------------- # +# This program is free software; you can redistribute it and/or modify it # +# under the terms of the GNU General Public License as published by the Free # +# Software Foundation; version 2 of the License. # +# # +# This program is distributed in the hope that it will be useful, but WITHOUT # +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # +# more details. # +# # +# You should have received a copy of the GNU General Public License along # +# with this program; if not, write to the Free Software Foundation, Inc., 59 # +# Temple Place, Suite 330, Boston, MA 02111-1307 USA # +############################################################################### +""" +Test the registry properties +""" +from unittest import TestCase + +from openlp.core.common import Registry, RegistryProperties +from tests.functional import MagicMock + + +class TestRegistryProperties(TestCase, RegistryProperties): + """ + Test the functions in the ThemeManager module + """ + def setUp(self): + """ + Create the UI + """ + Registry.create() + + def no_application_test(self): + # GIVEN an Empty Registry + # WHEN there is no Application + # THEN the application should be none + self.assertEquals(self.application, None, 'The application value should be None') + + def application_test(self): + # GIVEN an Empty Registry + application = MagicMock() + # WHEN the application is registered + Registry().register('application', application) + # THEN the application should be none + self.assertEquals(self.application, application, 'The application value should match') \ No newline at end of file diff --git a/tests/interfaces/openlp_core_ui/test_filerenamedialog.py b/tests/interfaces/openlp_core_ui/test_filerenamedialog.py index 2bd3fc889..3bba2b19b 100644 --- a/tests/interfaces/openlp_core_ui/test_filerenamedialog.py +++ b/tests/interfaces/openlp_core_ui/test_filerenamedialog.py @@ -1,3 +1,31 @@ +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 + +############################################################################### +# OpenLP - Open Source Lyrics Projection # +# --------------------------------------------------------------------------- # +# Copyright (c) 2008-2014 Raoul Snyman # +# Portions copyright (c) 2008-2014 Tim Bentley, Gerald Britton, Jonathan # +# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, # +# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. # +# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, # +# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, # +# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, # +# Frode Woldsund, Martin Zibricky, Patrick Zimmermann # +# --------------------------------------------------------------------------- # +# This program is free software; you can redistribute it and/or modify it # +# under the terms of the GNU General Public License as published by the Free # +# Software Foundation; version 2 of the License. # +# # +# This program is distributed in the hope that it will be useful, but WITHOUT # +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # +# more details. # +# # +# You should have received a copy of the GNU General Public License along # +# with this program; if not, write to the Free Software Foundation, Inc., 59 # +# Temple Place, Suite 330, Boston, MA 02111-1307 USA # +############################################################################### """ Package to test the openlp.core.ui package. """ diff --git a/tests/interfaces/openlp_core_ui/test_servicenotedialog.py b/tests/interfaces/openlp_core_ui/test_servicenotedialog.py index 4a0f0acff..c085d82b7 100644 --- a/tests/interfaces/openlp_core_ui/test_servicenotedialog.py +++ b/tests/interfaces/openlp_core_ui/test_servicenotedialog.py @@ -1,3 +1,31 @@ +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 + +############################################################################### +# OpenLP - Open Source Lyrics Projection # +# --------------------------------------------------------------------------- # +# Copyright (c) 2008-2014 Raoul Snyman # +# Portions copyright (c) 2008-2014 Tim Bentley, Gerald Britton, Jonathan # +# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, # +# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. # +# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, # +# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, # +# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, # +# Frode Woldsund, Martin Zibricky, Patrick Zimmermann # +# --------------------------------------------------------------------------- # +# This program is free software; you can redistribute it and/or modify it # +# under the terms of the GNU General Public License as published by the Free # +# Software Foundation; version 2 of the License. # +# # +# This program is distributed in the hope that it will be useful, but WITHOUT # +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # +# more details. # +# # +# You should have received a copy of the GNU General Public License along # +# with this program; if not, write to the Free Software Foundation, Inc., 59 # +# Temple Place, Suite 330, Boston, MA 02111-1307 USA # +############################################################################### """ Package to test the openlp.core.ui package. """ diff --git a/tests/interfaces/openlp_core_ui/test_settings_form.py b/tests/interfaces/openlp_core_ui/test_settings_form.py index 904f7d5dd..83e02cb3c 100644 --- a/tests/interfaces/openlp_core_ui/test_settings_form.py +++ b/tests/interfaces/openlp_core_ui/test_settings_form.py @@ -1,3 +1,31 @@ +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 + +############################################################################### +# OpenLP - Open Source Lyrics Projection # +# --------------------------------------------------------------------------- # +# Copyright (c) 2008-2014 Raoul Snyman # +# Portions copyright (c) 2008-2014 Tim Bentley, Gerald Britton, Jonathan # +# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, # +# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. # +# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, # +# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, # +# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, # +# Frode Woldsund, Martin Zibricky, Patrick Zimmermann # +# --------------------------------------------------------------------------- # +# This program is free software; you can redistribute it and/or modify it # +# under the terms of the GNU General Public License as published by the Free # +# Software Foundation; version 2 of the License. # +# # +# This program is distributed in the hope that it will be useful, but WITHOUT # +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # +# more details. # +# # +# You should have received a copy of the GNU General Public License along # +# with this program; if not, write to the Free Software Foundation, Inc., 59 # +# Temple Place, Suite 330, Boston, MA 02111-1307 USA # +############################################################################### """ Package to test the openlp.core.lib.settingsform package. """