From 62b1653c465b64f8c37e26171285b2faa166143a Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Sun, 17 Feb 2013 07:54:43 +0000 Subject: [PATCH] Fix the unit test framework --- tests/functional/__init__.py | 4 ---- .../functional/openlp_core_lib/test_image_manager.py | 2 +- tests/functional/openlp_core_lib/test_registry.py | 1 - tests/functional/openlp_core_lib/test_screen.py | 11 +++++++---- tests/interfaces/__init__.py | 4 ---- .../interfaces/openlp_core_lib/test_pluginmanager.py | 5 +++-- .../openlp_core_ui/test_filerenamedialog.py | 6 +++--- .../interfaces/openlp_core_ui/test_servicemanager.py | 2 +- .../openlp_core_ui/test_servicenotedialog.py | 2 +- .../interfaces/openlp_core_ui/test_starttimedialog.py | 2 +- 10 files changed, 17 insertions(+), 22 deletions(-) diff --git a/tests/functional/__init__.py b/tests/functional/__init__.py index 0b5157b46..fa6ad34f6 100644 --- a/tests/functional/__init__.py +++ b/tests/functional/__init__.py @@ -7,7 +7,3 @@ sip.setapi(u'QTime', 2) sip.setapi(u'QUrl', 2) 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 3256ef86f..d13c82c04 100644 --- a/tests/functional/openlp_core_lib/test_image_manager.py +++ b/tests/functional/openlp_core_lib/test_image_manager.py @@ -20,7 +20,7 @@ class TestImageManager(TestCase): Create the UI """ Registry.create() - self.app = QtGui.QApplication.instance() + self.app = QtGui.QApplication([]) ScreenList.create(self.app.desktop()) self.image_manager = ImageManager() diff --git a/tests/functional/openlp_core_lib/test_registry.py b/tests/functional/openlp_core_lib/test_registry.py index f272010c5..6e9e8fe7f 100644 --- a/tests/functional/openlp_core_lib/test_registry.py +++ b/tests/functional/openlp_core_lib/test_registry.py @@ -11,7 +11,6 @@ from openlp.core.lib import Registry TEST_PATH = 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_screen.py b/tests/functional/openlp_core_lib/test_screen.py index 92dd48172..eb7d6d253 100644 --- a/tests/functional/openlp_core_lib/test_screen.py +++ b/tests/functional/openlp_core_lib/test_screen.py @@ -7,7 +7,7 @@ from unittest import TestCase from mock import MagicMock from PyQt4 import QtGui, QtCore -from openlp.core.lib import ScreenList +from openlp.core.lib import Registry, ScreenList SCREEN = { @@ -23,18 +23,22 @@ class TestScreenList(TestCase): """ Set up the components need for all tests. """ - self.application = QtGui.QApplication.instance() + Registry.create() + self.application = QtGui.QApplication([]) + self.application.setOrganizationName(u'OpenLP-tests') + self.application.setOrganizationDomain(u'openlp.org') self.screens = ScreenList.create(self.application.desktop()) def tearDown(self): """ Delete QApplication. """ + del self.screens del self.application def add_desktop_test(self): """ - Test the ScreenList class' screen_count_changed method to check if new monitors are detected by OpenLP. + 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) @@ -52,4 +56,3 @@ class TestScreenList(TestCase): # THEN: The screens should be identically. assert SCREEN == new_screens.pop(), u'The new screen should be identically to the screen defined above.' - diff --git a/tests/interfaces/__init__.py b/tests/interfaces/__init__.py index 0b5157b46..fa6ad34f6 100644 --- a/tests/interfaces/__init__.py +++ b/tests/interfaces/__init__.py @@ -7,7 +7,3 @@ sip.setapi(u'QTime', 2) sip.setapi(u'QUrl', 2) 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 ca8ed3f07..f0aac5113 100644 --- a/tests/interfaces/openlp_core_lib/test_pluginmanager.py +++ b/tests/interfaces/openlp_core_lib/test_pluginmanager.py @@ -6,7 +6,7 @@ import sys from tempfile import mkstemp from unittest import TestCase -from mock import MagicMock, patch +from mock import MagicMock from PyQt4 import QtGui from openlp.core.lib.pluginmanager import PluginManager @@ -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.instance() + 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')) @@ -34,6 +34,7 @@ class TestPluginManager(TestCase): def tearDown(self): os.unlink(self.ini_file) del self.app + del self.main_window def find_plugins_test(self): """ diff --git a/tests/interfaces/openlp_core_ui/test_filerenamedialog.py b/tests/interfaces/openlp_core_ui/test_filerenamedialog.py index 941b1485a..26c07a514 100644 --- a/tests/interfaces/openlp_core_ui/test_filerenamedialog.py +++ b/tests/interfaces/openlp_core_ui/test_filerenamedialog.py @@ -14,8 +14,8 @@ class TestStartFileRenameForm(TestCase): """ Create the UI """ - registry = Registry.create() - self.app = QtGui.QApplication.instance() + Registry.create() + self.app = QtGui.QApplication([]) self.main_window = QtGui.QMainWindow() Registry().register(u'main_window', self.main_window) self.form = filerenameform.FileRenameForm() @@ -78,6 +78,6 @@ class TestStartFileRenameForm(TestCase): # 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 + # THEN: The text in the QLineEdit should be the same as the input string with the invalid characters filtered # out. self.assertEqual(self.form.fileNameEdit.text(), u'Invalid File Name') diff --git a/tests/interfaces/openlp_core_ui/test_servicemanager.py b/tests/interfaces/openlp_core_ui/test_servicemanager.py index e06edd4a6..bb62bd6e6 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.instance() + self.app = QtGui.QApplication([]) 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 e04f9975d..54560f224 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.instance() + self.app = QtGui.QApplication([]) self.main_window = QtGui.QMainWindow() Registry().register(u'main_window', self.main_window) self.form = servicenoteform.ServiceNoteForm() diff --git a/tests/interfaces/openlp_core_ui/test_starttimedialog.py b/tests/interfaces/openlp_core_ui/test_starttimedialog.py index c09426a1f..d4b9e4fb9 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.instance() + self.app = QtGui.QApplication([]) self.main_window = QtGui.QMainWindow() Registry().register(u'main_window', self.main_window) self.form = starttimeform.StartTimeForm()