diff --git a/tests/interfaces/__init__.py b/tests/interfaces/__init__.py index 61c17dee3..7ba934446 100644 --- a/tests/interfaces/__init__.py +++ b/tests/interfaces/__init__.py @@ -1,3 +1,4 @@ + import sip sip.setapi('QDate', 2) sip.setapi('QDateTime', 2) @@ -7,7 +8,9 @@ sip.setapi('QTime', 2) sip.setapi('QUrl', 2) sip.setapi('QVariant', 2) -#from PyQt4 import QtGui +import sys -# Only one QApplication can be created. Use QtGui.QApplication.instance() when you need to "create" an QApplication. -#application = QtGui.QApplication([]) +if sys.version_info[1] >= 3: + from unittest.mock import patch, MagicMock +else: + from mock import patch, MagicMock diff --git a/tests/interfaces/openlp_core_lib/test_pluginmanager.py b/tests/interfaces/openlp_core_lib/test_pluginmanager.py index 184b04808..e0ee8bfec 100644 --- a/tests/interfaces/openlp_core_lib/test_pluginmanager.py +++ b/tests/interfaces/openlp_core_lib/test_pluginmanager.py @@ -7,12 +7,12 @@ import shutil from tempfile import mkstemp, mkdtemp from unittest import TestCase -from mock import MagicMock from PyQt4 import QtGui from openlp.core.common import Settings from openlp.core.lib.pluginmanager import PluginManager from openlp.core.lib import Registry +from tests.interfaces import MagicMock class TestPluginManager(TestCase): diff --git a/tests/interfaces/openlp_core_ui/test_filerenamedialog.py b/tests/interfaces/openlp_core_ui/test_filerenamedialog.py index 2c5948705..5e151da77 100644 --- a/tests/interfaces/openlp_core_ui/test_filerenamedialog.py +++ b/tests/interfaces/openlp_core_ui/test_filerenamedialog.py @@ -3,10 +3,11 @@ """ from unittest import TestCase -from mock import MagicMock, patch +from PyQt4 import QtGui, QtTest + from openlp.core.lib import Registry from openlp.core.ui import filerenameform -from PyQt4 import QtGui, QtTest +from tests.interfaces import MagicMock, patch class TestStartFileRenameForm(TestCase): diff --git a/tests/interfaces/openlp_core_ui/test_listpreviewwidget.py b/tests/interfaces/openlp_core_ui/test_listpreviewwidget.py index 4d7044424..49d376797 100644 --- a/tests/interfaces/openlp_core_ui/test_listpreviewwidget.py +++ b/tests/interfaces/openlp_core_ui/test_listpreviewwidget.py @@ -3,12 +3,12 @@ """ from unittest import TestCase -from mock import MagicMock, patch from PyQt4 import QtGui from openlp.core.lib import Registry, ServiceItem from openlp.core.ui import listpreviewwidget +from tests.interfaces import MagicMock, patch from tests.utils.osdinteraction import read_service_from_file diff --git a/tests/interfaces/openlp_core_ui/test_mainwindow.py b/tests/interfaces/openlp_core_ui/test_mainwindow.py index 299f5db6d..0a5c77361 100644 --- a/tests/interfaces/openlp_core_ui/test_mainwindow.py +++ b/tests/interfaces/openlp_core_ui/test_mainwindow.py @@ -2,12 +2,12 @@ Package to test the openlp.core.ui.mainwindow package. """ from unittest import TestCase -from mock import MagicMock, patch from PyQt4 import QtGui from openlp.core.lib import Registry from openlp.core.ui.mainwindow import MainWindow +from tests.interfaces import MagicMock, patch class TestMainWindow(TestCase): diff --git a/tests/interfaces/openlp_core_ui/test_servicemanager.py b/tests/interfaces/openlp_core_ui/test_servicemanager.py index dbd49102c..e8b6df94f 100644 --- a/tests/interfaces/openlp_core_ui/test_servicemanager.py +++ b/tests/interfaces/openlp_core_ui/test_servicemanager.py @@ -3,12 +3,12 @@ """ from unittest import TestCase -from mock import MagicMock, Mock, patch from PyQt4 import QtGui from openlp.core.lib import Registry, ScreenList, ServiceItem from openlp.core.ui.mainwindow import MainWindow +from tests.interfaces import MagicMock, patch class TestServiceManager(TestCase): @@ -41,7 +41,7 @@ class TestServiceManager(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, - 'The service manager list should be empty ') + 'The service manager list should be empty ') def context_menu_test(self): """ @@ -49,8 +49,8 @@ class TestServiceManager(TestCase): """ # GIVEN: A service item added with patch('PyQt4.QtGui.QTreeWidget.itemAt') as mocked_item_at_method, \ - patch('PyQt4.QtGui.QWidget.mapToGlobal') as mocked_map_to_global, \ - patch('PyQt4.QtGui.QMenu.exec_') as mocked_exec: + patch('PyQt4.QtGui.QWidget.mapToGlobal'), \ + patch('PyQt4.QtGui.QMenu.exec_'): mocked_item = MagicMock() mocked_item.parent.return_value = None mocked_item_at_method.return_value = mocked_item @@ -61,12 +61,12 @@ class TestServiceManager(TestCase): self.service_manager.service_items = [{'service_item': service_item}] q_point = None # Mocked actions. - self.service_manager.edit_action.setVisible = Mock() - self.service_manager.create_custom_action.setVisible = Mock() - self.service_manager.maintain_action.setVisible = Mock() - self.service_manager.notes_action.setVisible = Mock() - self.service_manager.time_action.setVisible = Mock() - self.service_manager.auto_start_action.setVisible = Mock() + self.service_manager.edit_action.setVisible = MagicMock() + self.service_manager.create_custom_action.setVisible = MagicMock() + self.service_manager.maintain_action.setVisible = MagicMock() + self.service_manager.notes_action.setVisible = MagicMock() + self.service_manager.time_action.setVisible = MagicMock() + self.service_manager.auto_start_action.setVisible = MagicMock() # WHEN: Show the context menu. self.service_manager.context_menu(q_point) diff --git a/tests/interfaces/openlp_core_ui/test_servicenotedialog.py b/tests/interfaces/openlp_core_ui/test_servicenotedialog.py index 64e7ca722..336c94655 100644 --- a/tests/interfaces/openlp_core_ui/test_servicenotedialog.py +++ b/tests/interfaces/openlp_core_ui/test_servicenotedialog.py @@ -2,12 +2,12 @@ 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 tests.interfaces import patch class TestStartNoteDialog(TestCase): diff --git a/tests/interfaces/openlp_core_ui/test_settings_form.py b/tests/interfaces/openlp_core_ui/test_settings_form.py index 7dd368e84..b9f032182 100644 --- a/tests/interfaces/openlp_core_ui/test_settings_form.py +++ b/tests/interfaces/openlp_core_ui/test_settings_form.py @@ -3,12 +3,11 @@ Package to test the openlp.core.lib.settingsform package. """ from unittest import TestCase -from mock import MagicMock, patch - from PyQt4 import QtCore, QtTest, QtGui from openlp.core.ui import settingsform from openlp.core.lib import Registry, ScreenList +from tests.interfaces import MagicMock, patch SCREEN = { @@ -168,4 +167,4 @@ class TestSettingsForm(TestCase): # THEN: Images_regenerate should have been added. assert self.dummy1.call_count == 1, 'dummy1 should have been called once' assert self.dummy2.call_count == 1, 'dummy2 should have been called once' - assert self.dummy3.call_count == 1, 'dummy3 should have been called once' \ No newline at end of file + assert self.dummy3.call_count == 1, 'dummy3 should have been called once' diff --git a/tests/interfaces/openlp_core_ui/test_starttimedialog.py b/tests/interfaces/openlp_core_ui/test_starttimedialog.py index 6542cc02e..de3d87910 100644 --- a/tests/interfaces/openlp_core_ui/test_starttimedialog.py +++ b/tests/interfaces/openlp_core_ui/test_starttimedialog.py @@ -2,13 +2,12 @@ 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 tests.interfaces import MagicMock, patch class TestStartTimeDialog(TestCase): diff --git a/tests/interfaces/openlp_plugins/bibles/test_lib_http.py b/tests/interfaces/openlp_plugins/bibles/test_lib_http.py index bd645f1ff..54ad3bec1 100644 --- a/tests/interfaces/openlp_plugins/bibles/test_lib_http.py +++ b/tests/interfaces/openlp_plugins/bibles/test_lib_http.py @@ -1,12 +1,11 @@ """ Package to test the openlp.plugin.bible.lib.https package. """ - from unittest import TestCase -from mock import MagicMock from openlp.core.lib import Registry from openlp.plugins.bibles.lib.http import BGExtract, CWExtract +from tests.interfaces import MagicMock class TestBibleHTTP(TestCase): diff --git a/tests/interfaces/openlp_plugins/custom/forms/test_customform.py b/tests/interfaces/openlp_plugins/custom/forms/test_customform.py index 61dbb822c..ffa3ec884 100644 --- a/tests/interfaces/openlp_plugins/custom/forms/test_customform.py +++ b/tests/interfaces/openlp_plugins/custom/forms/test_customform.py @@ -2,7 +2,6 @@ Module to test the EditCustomForm. """ from unittest import TestCase -from mock import MagicMock, patch from PyQt4 import QtGui, QtTest, QtCore @@ -10,6 +9,7 @@ from openlp.core.lib import Registry # Import needed due to import problems. from openlp.plugins.custom.lib.mediaitem import CustomMediaItem from openlp.plugins.custom.forms.editcustomform import EditCustomForm +from tests.interfaces import MagicMock, patch class TestEditCustomForm(TestCase): diff --git a/tests/interfaces/openlp_plugins/custom/forms/test_customslideform.py b/tests/interfaces/openlp_plugins/custom/forms/test_customslideform.py index 0ed70ab62..406b7e8a4 100644 --- a/tests/interfaces/openlp_plugins/custom/forms/test_customslideform.py +++ b/tests/interfaces/openlp_plugins/custom/forms/test_customslideform.py @@ -2,12 +2,12 @@ Module to test the EditCustomSlideForm. """ from unittest import TestCase -from mock import MagicMock, patch from PyQt4 import QtGui from openlp.core.lib import Registry from openlp.plugins.custom.forms.editcustomslideform import EditCustomSlideForm +from tests.interfaces import MagicMock, patch class TestEditCustomSlideForm(TestCase): diff --git a/tests/interfaces/openlp_plugins/songs/forms/test_editsongform.py b/tests/interfaces/openlp_plugins/songs/forms/test_editsongform.py index 8ed953048..405ba5cf6 100644 --- a/tests/interfaces/openlp_plugins/songs/forms/test_editsongform.py +++ b/tests/interfaces/openlp_plugins/songs/forms/test_editsongform.py @@ -1,13 +1,13 @@ """ Package to test the openlp.plugins.songs.forms.editsongform package. """ -from mock import MagicMock from unittest import TestCase from PyQt4 import QtGui from openlp.core.lib import Registry from openlp.plugins.songs.forms.editsongform import EditSongForm +from tests.interfaces import MagicMock class TestEditSongForm(TestCase):