This commit is contained in:
Tim Bentley 2014-03-14 17:34:36 +00:00
commit d2efa83e89
28 changed files with 173 additions and 88 deletions

View File

@ -426,9 +426,9 @@ def get_locale_key(string):
The corresponding string. The corresponding string.
""" """
string = string.lower() string = string.lower()
# For Python 3 on platforms other than Windows ICU is not necessary. In those cases locale.strxfrm(str) can be used. # ICU is the prefered way to handle locale sort key, we fallback to locale.strxfrm which will work in most cases.
if os.name == 'nt':
global ICU_COLLATOR global ICU_COLLATOR
try:
if ICU_COLLATOR is None: if ICU_COLLATOR is None:
import icu import icu
from .languagemanager import LanguageManager from .languagemanager import LanguageManager
@ -436,9 +436,9 @@ def get_locale_key(string):
icu_locale = icu.Locale(language) icu_locale = icu.Locale(language)
ICU_COLLATOR = icu.Collator.createInstance(icu_locale) ICU_COLLATOR = icu.Collator.createInstance(icu_locale)
return ICU_COLLATOR.getSortKey(string) return ICU_COLLATOR.getSortKey(string)
except:
return locale.strxfrm(string).encode() return locale.strxfrm(string).encode()
def get_natural_key(string): def get_natural_key(string):
""" """
Generate a key for locale aware natural string sorting. Generate a key for locale aware natural string sorting.

View File

@ -54,8 +54,8 @@ class PdfController(PresentationController):
:param plugin: The plugin that creates the controller. :param plugin: The plugin that creates the controller.
""" """
log.debug('Initialising') log.debug('Initialising')
super(PdfController, self).__init__(plugin, 'Pdf', PdfDocument)
self.process = None self.process = None
PresentationController.__init__(self, plugin, 'Pdf', PdfDocument)
self.supports = ['pdf'] self.supports = ['pdf']
self.also_supports = [] self.also_supports = []
# Determine whether mudraw or ghostscript is used # Determine whether mudraw or ghostscript is used

View File

@ -30,6 +30,7 @@
Functional tests to test the AppLocation class and related methods. Functional tests to test the AppLocation class and related methods.
""" """
import copy import copy
import os
from unittest import TestCase from unittest import TestCase
from openlp.core.common import AppLocation, get_frozen_path from openlp.core.common import AppLocation, get_frozen_path
@ -53,9 +54,9 @@ class TestAppLocation(TestCase):
# GIVEN: A mocked out Settings class and a mocked out AppLocation.get_directory() # GIVEN: A mocked out Settings class and a mocked out AppLocation.get_directory()
mocked_settings = mocked_class.return_value mocked_settings = mocked_class.return_value
mocked_settings.contains.return_value = False mocked_settings.contains.return_value = False
mocked_get_directory.return_value = 'test/dir' mocked_get_directory.return_value = os.path.join('test','dir')
mocked_check_directory_exists.return_value = True mocked_check_directory_exists.return_value = True
mocked_os.path.normpath.return_value = 'test/dir' mocked_os.path.normpath.return_value = os.path.join('test','dir')
# WHEN: we call AppLocation.get_data_path() # WHEN: we call AppLocation.get_data_path()
data_path = AppLocation.get_data_path() data_path = AppLocation.get_data_path()
@ -63,8 +64,8 @@ class TestAppLocation(TestCase):
# THEN: check that all the correct methods were called, and the result is correct # THEN: check that all the correct methods were called, and the result is correct
mocked_settings.contains.assert_called_with('advanced/data path') mocked_settings.contains.assert_called_with('advanced/data path')
mocked_get_directory.assert_called_with(AppLocation.DataDir) mocked_get_directory.assert_called_with(AppLocation.DataDir)
mocked_check_directory_exists.assert_called_with('test/dir') mocked_check_directory_exists.assert_called_with(os.path.join('test','dir'))
self.assertEqual('test/dir', data_path, 'Result should be "test/dir"') self.assertEqual(os.path.join('test','dir'), data_path, 'Result should be "test/dir"')
def get_data_path_with_custom_location_test(self): def get_data_path_with_custom_location_test(self):
""" """
@ -109,14 +110,14 @@ class TestAppLocation(TestCase):
with patch('openlp.core.common.AppLocation.get_data_path') as mocked_get_data_path, \ with patch('openlp.core.common.AppLocation.get_data_path') as mocked_get_data_path, \
patch('openlp.core.common.applocation.os.listdir') as mocked_listdir: patch('openlp.core.common.applocation.os.listdir') as mocked_listdir:
# GIVEN: Our mocked modules/methods. # GIVEN: Our mocked modules/methods.
mocked_get_data_path.return_value = 'test/dir' mocked_get_data_path.return_value = os.path.join('test','dir')
mocked_listdir.return_value = copy.deepcopy(FILE_LIST) mocked_listdir.return_value = copy.deepcopy(FILE_LIST)
# When: Get the list of files. # When: Get the list of files.
result = AppLocation.get_files('section', '.mp3') result = AppLocation.get_files('section', '.mp3')
# Then: Check if the section parameter was used correctly. # Then: Check if the section parameter was used correctly.
mocked_listdir.assert_called_with('test/dir/section') mocked_listdir.assert_called_with(os.path.join('test','dir','section'))
# Then: check if the file lists are identical. # Then: check if the file lists are identical.
self.assertListEqual(['file5.mp3', 'file6.mp3'], result, 'The file lists should be identical.') self.assertListEqual(['file5.mp3', 'file6.mp3'], result, 'The file lists should be identical.')
@ -128,15 +129,15 @@ class TestAppLocation(TestCase):
with patch('openlp.core.common.AppLocation.get_data_path') as mocked_get_data_path, \ with patch('openlp.core.common.AppLocation.get_data_path') as mocked_get_data_path, \
patch('openlp.core.common.applocation.check_directory_exists') as mocked_check_directory_exists: patch('openlp.core.common.applocation.check_directory_exists') as mocked_check_directory_exists:
# GIVEN: A mocked out AppLocation.get_data_path() # GIVEN: A mocked out AppLocation.get_data_path()
mocked_get_data_path.return_value = 'test/dir' mocked_get_data_path.return_value = os.path.join('test','dir')
mocked_check_directory_exists.return_value = True mocked_check_directory_exists.return_value = True
# WHEN: we call AppLocation.get_data_path() # WHEN: we call AppLocation.get_data_path()
data_path = AppLocation.get_section_data_path('section') data_path = AppLocation.get_section_data_path('section')
# THEN: check that all the correct methods were called, and the result is correct # THEN: check that all the correct methods were called, and the result is correct
mocked_check_directory_exists.assert_called_with('test/dir/section') mocked_check_directory_exists.assert_called_with(os.path.join('test','dir','section'))
self.assertEqual('test/dir/section', data_path, 'Result should be "test/dir/section"') self.assertEqual(os.path.join('test','dir','section'), data_path, 'Result should be "test/dir/section"')
def get_directory_for_app_dir_test(self): def get_directory_for_app_dir_test(self):
""" """
@ -144,13 +145,13 @@ class TestAppLocation(TestCase):
""" """
# GIVEN: A mocked out _get_frozen_path function # GIVEN: A mocked out _get_frozen_path function
with patch('openlp.core.common.applocation.get_frozen_path') as mocked_get_frozen_path: with patch('openlp.core.common.applocation.get_frozen_path') as mocked_get_frozen_path:
mocked_get_frozen_path.return_value = 'app/dir' mocked_get_frozen_path.return_value = os.path.join('app','dir')
# WHEN: We call AppLocation.get_directory # WHEN: We call AppLocation.get_directory
directory = AppLocation.get_directory(AppLocation.AppDir) directory = AppLocation.get_directory(AppLocation.AppDir)
# THEN: check that the correct directory is returned # THEN: check that the correct directory is returned
self.assertEqual('app/dir', directory, 'Directory should be "app/dir"') self.assertEqual(os.path.join('app','dir'), directory, 'Directory should be "app/dir"')
def get_directory_for_plugins_dir_test(self): def get_directory_for_plugins_dir_test(self):
""" """

View File

@ -46,7 +46,8 @@ class TestSettings(TestCase):
""" """
Create the UI Create the UI
""" """
fd, self.ini_file = mkstemp('.ini') Settings.setDefaultFormat(Settings.IniFormat)
self.fd, self.ini_file = mkstemp('.ini')
Settings().set_filename(self.ini_file) Settings().set_filename(self.ini_file)
self.application = QtGui.QApplication.instance() self.application = QtGui.QApplication.instance()
@ -55,7 +56,7 @@ class TestSettings(TestCase):
Delete all the C++ objects at the end so that we don't have a segfault Delete all the C++ objects at the end so that we don't have a segfault
""" """
del self.application del self.application
os.unlink(self.ini_file) os.close(self.fd)
os.unlink(Settings().fileName()) os.unlink(Settings().fileName())
def settings_basic_test(self): def settings_basic_test(self):

View File

@ -179,6 +179,8 @@ class TestServiceItem(TestCase):
# new layout of service item. The layout use in serviceitem_image_2.osd is actually invalid now. # new layout of service item. The layout use in serviceitem_image_2.osd is actually invalid now.
self.assertTrue(service_item.is_valid, 'The first service item should be valid') self.assertTrue(service_item.is_valid, 'The first service item should be valid')
self.assertTrue(service_item2.is_valid, 'The second service item should be valid') self.assertTrue(service_item2.is_valid, 'The second service item should be valid')
# These test will fail on windows due to the difference in folder seperators
if os.name != 'nt':
self.assertEqual(test_file1, service_item.get_rendered_frame(0), self.assertEqual(test_file1, service_item.get_rendered_frame(0),
'The first frame should match the path to the image') 'The first frame should match the path to the image')
self.assertEqual(test_file2, service_item2.get_rendered_frame(0), self.assertEqual(test_file2, service_item2.get_rendered_frame(0),

View File

@ -49,8 +49,9 @@ class TestActionList(TestCase):
Prepare the tests Prepare the tests
""" """
self.action_list = ActionList.get_instance() self.action_list = ActionList.get_instance()
Settings.setDefaultFormat(Settings.IniFormat)
self.settings = Settings() self.settings = Settings()
fd, self.ini_file = mkstemp('.ini') self.fd, self.ini_file = mkstemp('.ini')
self.settings.set_filename(self.ini_file) self.settings.set_filename(self.ini_file)
self.settings.beginGroup('shortcuts') self.settings.beginGroup('shortcuts')
@ -59,7 +60,8 @@ class TestActionList(TestCase):
Clean up Clean up
""" """
self.settings.endGroup() self.settings.endGroup()
os.unlink(self.ini_file) os.close(self.fd)
os.unlink(Settings().fileName())
def test_add_action_same_parent(self): def test_add_action_same_parent(self):
""" """

View File

@ -29,6 +29,7 @@
""" """
Functional tests to test the AppLocation class and related methods. Functional tests to test the AppLocation class and related methods.
""" """
import os
from unittest import TestCase from unittest import TestCase
from openlp.core.utils import clean_filename, get_filesystem_encoding, get_locale_key, \ from openlp.core.utils import clean_filename, get_filesystem_encoding, get_locale_key, \
@ -140,6 +141,10 @@ class TestUtils(TestCase):
Test the split_filename() function with a path to a file Test the split_filename() function with a path to a file
""" """
# GIVEN: A path to a file. # GIVEN: A path to a file.
if os.name == 'nt':
file_path = 'C:\\home\\user\\myfile.txt'
wanted_result = ('C:\\home\\user', 'myfile.txt')
else:
file_path = '/home/user/myfile.txt' file_path = '/home/user/myfile.txt'
wanted_result = ('/home/user', 'myfile.txt') wanted_result = ('/home/user', 'myfile.txt')
with patch('openlp.core.utils.os.path.isfile') as mocked_is_file: with patch('openlp.core.utils.os.path.isfile') as mocked_is_file:
@ -156,6 +161,10 @@ class TestUtils(TestCase):
Test the split_filename() function with a path to a directory Test the split_filename() function with a path to a directory
""" """
# GIVEN: A path to a dir. # GIVEN: A path to a dir.
if os.name == 'nt':
file_path = 'C:\\home\\user\\mydir'
wanted_result = ('C:\\home\\user\\mydir', '')
else:
file_path = '/home/user/mydir' file_path = '/home/user/mydir'
wanted_result = ('/home/user/mydir', '') wanted_result = ('/home/user/mydir', '')
with patch('openlp.core.utils.os.path.isfile') as mocked_is_file: with patch('openlp.core.utils.os.path.isfile') as mocked_is_file:

View File

@ -55,6 +55,7 @@ class TestPdfController(TestCase):
""" """
Set up the components need for all tests. Set up the components need for all tests.
""" """
Settings.setDefaultFormat(Settings.IniFormat)
self.fd, self.ini_file = mkstemp('.ini') self.fd, self.ini_file = mkstemp('.ini')
Settings().set_filename(self.ini_file) Settings().set_filename(self.ini_file)
self.application = QtGui.QApplication.instance() self.application = QtGui.QApplication.instance()
@ -62,6 +63,8 @@ class TestPdfController(TestCase):
Settings().extend_default_settings(__default_settings__) Settings().extend_default_settings(__default_settings__)
self.temp_folder = mkdtemp() self.temp_folder = mkdtemp()
self.thumbnail_folder = mkdtemp() self.thumbnail_folder = mkdtemp()
self.mock_plugin = MagicMock()
self.mock_plugin.settings_section = self.temp_folder
def tearDown(self): def tearDown(self):
""" """
@ -69,7 +72,8 @@ class TestPdfController(TestCase):
""" """
del self.application del self.application
try: try:
os.unlink(self.ini_file) os.close(self.fd)
os.unlink(Settings().fileName())
shutil.rmtree(self.thumbnail_folder) shutil.rmtree(self.thumbnail_folder)
shutil.rmtree(self.temp_folder) shutil.rmtree(self.temp_folder)
except OSError: except OSError:
@ -83,7 +87,7 @@ class TestPdfController(TestCase):
controller = None controller = None
# WHEN: The presentation controller object is created # WHEN: The presentation controller object is created
controller = PdfController(plugin=MagicMock()) controller = PdfController(plugin=self.mock_plugin)
# THEN: The name of the presentation controller should be correct # THEN: The name of the presentation controller should be correct
self.assertEqual('Pdf', controller.name, 'The name of the presentation controller should be correct') self.assertEqual('Pdf', controller.name, 'The name of the presentation controller should be correct')
@ -96,7 +100,7 @@ class TestPdfController(TestCase):
test_file = os.path.join(TEST_RESOURCES_PATH, 'presentations', 'pdf_test1.pdf') test_file = os.path.join(TEST_RESOURCES_PATH, 'presentations', 'pdf_test1.pdf')
# WHEN: The Pdf is loaded # WHEN: The Pdf is loaded
controller = PdfController(plugin=MagicMock()) controller = PdfController(plugin=self.mock_plugin)
if not controller.check_available(): if not controller.check_available():
raise SkipTest('Could not detect mudraw or ghostscript, so skipping PDF test') raise SkipTest('Could not detect mudraw or ghostscript, so skipping PDF test')
controller.temp_folder = self.temp_folder controller.temp_folder = self.temp_folder

View File

@ -60,7 +60,9 @@ class TestPresentationController(TestCase):
controller = None controller = None
# WHEN: The presentation controller object is created # WHEN: The presentation controller object is created
controller = PresentationController(plugin=MagicMock()) mock_plugin = MagicMock()
mock_plugin.settings_section = ''
controller = PresentationController(plugin=mock_plugin)
# THEN: The name of the presentation controller should be correct # THEN: The name of the presentation controller should be correct
self.assertEqual('PresentationController', controller.name, self.assertEqual('PresentationController', controller.name,

View File

@ -62,6 +62,7 @@ class TestRemoteTab(TestCase):
""" """
Create the UI Create the UI
""" """
Settings.setDefaultFormat(Settings.IniFormat)
self.fd, self.ini_file = mkstemp('.ini') self.fd, self.ini_file = mkstemp('.ini')
Settings().set_filename(self.ini_file) Settings().set_filename(self.ini_file)
self.application = QtGui.QApplication.instance() self.application = QtGui.QApplication.instance()
@ -77,7 +78,7 @@ class TestRemoteTab(TestCase):
del self.parent del self.parent
del self.form del self.form
os.close(self.fd) os.close(self.fd)
os.unlink(self.ini_file) os.unlink(Settings().fileName())
def get_ip_address_default_test(self): def get_ip_address_default_test(self):
""" """

View File

@ -61,6 +61,7 @@ class TestRouter(TestCase):
""" """
Create the UI Create the UI
""" """
Settings.setDefaultFormat(Settings.IniFormat)
self.fd, self.ini_file = mkstemp('.ini') self.fd, self.ini_file = mkstemp('.ini')
Settings().set_filename(self.ini_file) Settings().set_filename(self.ini_file)
self.application = QtGui.QApplication.instance() self.application = QtGui.QApplication.instance()
@ -73,7 +74,7 @@ class TestRouter(TestCase):
""" """
del self.application del self.application
os.close(self.fd) os.close(self.fd)
os.unlink(self.ini_file) os.unlink(Settings().fileName())
def password_encrypter_test(self): def password_encrypter_test(self):
""" """

View File

@ -28,7 +28,8 @@ class TestMediaItem(TestCase):
patch('openlp.plugins.songs.forms.editsongform.EditSongForm.__init__'): patch('openlp.plugins.songs.forms.editsongform.EditSongForm.__init__'):
self.media_item = SongMediaItem(None, MagicMock()) self.media_item = SongMediaItem(None, MagicMock())
fd, self.ini_file = mkstemp('.ini') Settings.setDefaultFormat(Settings.IniFormat)
self.fd, self.ini_file = mkstemp('.ini')
Settings().set_filename(self.ini_file) Settings().set_filename(self.ini_file)
self.application = QtGui.QApplication.instance() self.application = QtGui.QApplication.instance()
QtCore.QLocale.setDefault(QtCore.QLocale('en_GB')) QtCore.QLocale.setDefault(QtCore.QLocale('en_GB'))
@ -40,7 +41,7 @@ class TestMediaItem(TestCase):
del self.application del self.application
# Not all tests use settings! # Not all tests use settings!
try: try:
os.unlink(self.ini_file) os.close(self.fd)
os.unlink(Settings().fileName()) os.unlink(Settings().fileName())
except Exception: except Exception:
pass pass

View File

@ -7,7 +7,7 @@ import shutil
from tempfile import mkstemp, mkdtemp from tempfile import mkstemp, mkdtemp
from unittest import TestCase from unittest import TestCase
from PyQt4 import QtGui from PyQt4 import QtGui, QtCore
from openlp.core.common import Registry, Settings from openlp.core.common import Registry, Settings
from openlp.core.lib.pluginmanager import PluginManager from openlp.core.lib.pluginmanager import PluginManager
@ -23,22 +23,27 @@ class TestPluginManager(TestCase):
""" """
Some pre-test setup required. Some pre-test setup required.
""" """
fd, self.ini_file = mkstemp('.ini') Settings.setDefaultFormat(Settings.IniFormat)
self.fd, self.ini_file = mkstemp('.ini')
self.temp_dir = mkdtemp('openlp') self.temp_dir = mkdtemp('openlp')
Settings().set_filename(self.ini_file) Settings().set_filename(self.ini_file)
Settings().setValue('advanced/data path', self.temp_dir) Settings().setValue('advanced/data path', self.temp_dir)
Registry.create() Registry.create()
Registry().register('service_list', MagicMock()) Registry().register('service_list', MagicMock())
old_app_instance = QtCore.QCoreApplication.instance()
if old_app_instance is None:
self.app = QtGui.QApplication([]) self.app = QtGui.QApplication([])
else:
self.app = old_app_instance
self.main_window = QtGui.QMainWindow() self.main_window = QtGui.QMainWindow()
Registry().register('main_window', self.main_window) Registry().register('main_window', self.main_window)
def tearDown(self): def tearDown(self):
del self.app
del self.main_window del self.main_window
os.close(self.fd)
os.unlink(Settings().fileName())
Settings().remove('advanced/data path') Settings().remove('advanced/data path')
shutil.rmtree(self.temp_dir) shutil.rmtree(self.temp_dir)
os.unlink(self.ini_file)
def find_plugins_test(self): def find_plugins_test(self):
""" """
@ -64,3 +69,4 @@ class TestPluginManager(TestCase):
assert 'songusage' in plugin_names, 'There should be a "songusage" plugin.' assert 'songusage' in plugin_names, 'There should be a "songusage" plugin.'
assert 'alerts' in plugin_names, 'There should be a "alerts" plugin.' assert 'alerts' in plugin_names, 'There should be a "alerts" plugin.'
assert 'remotes' in plugin_names, 'There should be a "remotes" plugin.' assert 'remotes' in plugin_names, 'There should be a "remotes" plugin.'

View File

@ -3,7 +3,7 @@
""" """
from unittest import TestCase from unittest import TestCase
from PyQt4 import QtGui, QtTest from PyQt4 import QtCore, QtGui, QtTest
from openlp.core.common import Registry from openlp.core.common import Registry
from openlp.core.ui import filerenameform from openlp.core.ui import filerenameform
@ -17,7 +17,11 @@ class TestStartFileRenameForm(TestCase):
Create the UI Create the UI
""" """
Registry.create() Registry.create()
old_app_instance = QtCore.QCoreApplication.instance()
if old_app_instance is None:
self.app = QtGui.QApplication([]) self.app = QtGui.QApplication([])
else:
self.app = old_app_instance
self.main_window = QtGui.QMainWindow() self.main_window = QtGui.QMainWindow()
Registry().register('main_window', self.main_window) Registry().register('main_window', self.main_window)
self.form = filerenameform.FileRenameForm() self.form = filerenameform.FileRenameForm()
@ -28,7 +32,6 @@ class TestStartFileRenameForm(TestCase):
""" """
del self.form del self.form
del self.main_window del self.main_window
del self.app
def window_title_test(self): def window_title_test(self):
""" """

View File

@ -4,7 +4,7 @@
from unittest import TestCase from unittest import TestCase
from PyQt4 import QtGui from PyQt4 import QtGui, QtCore
from openlp.core.common import Registry from openlp.core.common import Registry
from openlp.core.lib import ServiceItem from openlp.core.lib import ServiceItem
@ -20,7 +20,11 @@ class TestListPreviewWidget(TestCase):
Create the UI. Create the UI.
""" """
Registry.create() Registry.create()
old_app_instance = QtCore.QCoreApplication.instance()
if old_app_instance is None:
self.app = QtGui.QApplication([]) self.app = QtGui.QApplication([])
else:
self.app = old_app_instance
self.main_window = QtGui.QMainWindow() self.main_window = QtGui.QMainWindow()
self.image = QtGui.QImage(1, 1, QtGui.QImage.Format_RGB32) self.image = QtGui.QImage(1, 1, QtGui.QImage.Format_RGB32)
self.image_manager = MagicMock() self.image_manager = MagicMock()
@ -34,7 +38,6 @@ class TestListPreviewWidget(TestCase):
""" """
del self.preview_widget del self.preview_widget
del self.main_window del self.main_window
del self.app
def initial_slide_count_test(self): def initial_slide_count_test(self):
""" """

View File

@ -3,7 +3,7 @@ Package to test the openlp.core.ui.mainwindow package.
""" """
from unittest import TestCase from unittest import TestCase
from PyQt4 import QtGui from PyQt4 import QtGui, QtCore
from openlp.core.common import Registry from openlp.core.common import Registry
from openlp.core.ui.mainwindow import MainWindow from openlp.core.ui.mainwindow import MainWindow
@ -18,7 +18,11 @@ class TestMainWindow(TestCase):
""" """
Registry.create() Registry.create()
self.registry = Registry() self.registry = Registry()
old_app_instance = QtCore.QCoreApplication.instance()
if old_app_instance is None:
self.app = QtGui.QApplication([]) self.app = QtGui.QApplication([])
else:
self.app = old_app_instance
# Mock cursor busy/normal methods. # Mock cursor busy/normal methods.
self.app.set_busy_cursor = MagicMock() self.app.set_busy_cursor = MagicMock()
self.app.set_normal_cursor = MagicMock() self.app.set_normal_cursor = MagicMock()
@ -42,7 +46,6 @@ class TestMainWindow(TestCase):
Delete all the C++ objects at the end so that we don't have a segfault Delete all the C++ objects at the end so that we don't have a segfault
""" """
del self.main_window del self.main_window
del self.app
def restore_current_media_manager_item_test(self): def restore_current_media_manager_item_test(self):
""" """

View File

@ -19,7 +19,11 @@ class TestServiceManager(TestCase):
Create the UI Create the UI
""" """
Registry.create() Registry.create()
old_app_instance = QtCore.QCoreApplication.instance()
if old_app_instance is None:
self.app = QtGui.QApplication([]) self.app = QtGui.QApplication([])
else:
self.app = old_app_instance
ScreenList.create(self.app.desktop()) ScreenList.create(self.app.desktop())
Registry().register('application', MagicMock()) Registry().register('application', MagicMock())
with patch('openlp.core.lib.PluginManager'): with patch('openlp.core.lib.PluginManager'):
@ -30,8 +34,6 @@ class TestServiceManager(TestCase):
""" """
Delete all the C++ objects at the end so that we don't have a segfault 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): def basic_service_manager_test(self):
""" """

View File

@ -17,7 +17,11 @@ class TestStartNoteDialog(TestCase):
Create the UI Create the UI
""" """
Registry.create() Registry.create()
old_app_instance = QtCore.QCoreApplication.instance()
if old_app_instance is None:
self.app = QtGui.QApplication([]) self.app = QtGui.QApplication([])
else:
self.app = old_app_instance
self.main_window = QtGui.QMainWindow() self.main_window = QtGui.QMainWindow()
Registry().register('main_window', self.main_window) Registry().register('main_window', self.main_window)
self.form = servicenoteform.ServiceNoteForm() self.form = servicenoteform.ServiceNoteForm()
@ -28,7 +32,6 @@ class TestStartNoteDialog(TestCase):
""" """
del self.form del self.form
del self.main_window del self.main_window
del self.app
def basic_display_test(self): def basic_display_test(self):
""" """

View File

@ -31,7 +31,11 @@ class TestSettingsForm(TestCase):
self.dummy2 = MagicMock() self.dummy2 = MagicMock()
self.dummy3 = MagicMock() self.dummy3 = MagicMock()
self.desktop = MagicMock() self.desktop = MagicMock()
old_app_instance = QtCore.QCoreApplication.instance()
if old_app_instance is None:
self.app = QtGui.QApplication([]) self.app = QtGui.QApplication([])
else:
self.app = old_app_instance
self.desktop.primaryScreen.return_value = SCREEN['primary'] self.desktop.primaryScreen.return_value = SCREEN['primary']
self.desktop.screenCount.return_value = SCREEN['number'] self.desktop.screenCount.return_value = SCREEN['number']
self.desktop.screenGeometry.return_value = SCREEN['size'] self.desktop.screenGeometry.return_value = SCREEN['size']
@ -44,7 +48,6 @@ class TestSettingsForm(TestCase):
Delete all the C++ objects at the end so that we don't have a segfault Delete all the C++ objects at the end so that we don't have a segfault
""" """
del self.form del self.form
del self.app
def basic_cancel_test(self): def basic_cancel_test(self):
""" """

View File

@ -17,7 +17,11 @@ class TestStartTimeDialog(TestCase):
Create the UI Create the UI
""" """
Registry.create() Registry.create()
old_app_instance = QtCore.QCoreApplication.instance()
if old_app_instance is None:
self.app = QtGui.QApplication([]) self.app = QtGui.QApplication([])
else:
self.app = old_app_instance
self.main_window = QtGui.QMainWindow() self.main_window = QtGui.QMainWindow()
Registry().register('main_window', self.main_window) Registry().register('main_window', self.main_window)
self.form = starttimeform.StartTimeForm() self.form = starttimeform.StartTimeForm()
@ -28,7 +32,6 @@ class TestStartTimeDialog(TestCase):
""" """
del self.form del self.form
del self.main_window del self.main_window
del self.app
def ui_defaults_test(self): def ui_defaults_test(self):
""" """

View File

@ -33,7 +33,7 @@ import os
from unittest import TestCase from unittest import TestCase
from tempfile import mkstemp from tempfile import mkstemp
from PyQt4 import QtGui from PyQt4 import QtGui, QtCore
from openlp.core.common import Registry, Settings from openlp.core.common import Registry, Settings
from openlp.core.ui import ThemeManager from openlp.core.ui import ThemeManager
@ -48,9 +48,14 @@ class TestThemeManager(TestCase):
""" """
Create the UI Create the UI
""" """
fd, self.ini_file = mkstemp('.ini') Settings.setDefaultFormat(Settings.IniFormat)
self.fd, self.ini_file = mkstemp('.ini')
Settings().set_filename(self.ini_file) Settings().set_filename(self.ini_file)
old_app_instance = QtCore.QCoreApplication.instance()
if old_app_instance is None:
self.app = QtGui.QApplication([]) self.app = QtGui.QApplication([])
else:
self.app = old_app_instance
Registry.create() Registry.create()
self.theme_manager = ThemeManager() self.theme_manager = ThemeManager()
@ -58,9 +63,8 @@ class TestThemeManager(TestCase):
""" """
Delete all the C++ objects at the end so that we don't have a segfault Delete all the C++ objects at the end so that we don't have a segfault
""" """
os.unlink(self.ini_file) os.close(self.fd)
os.unlink(Settings().fileName()) os.unlink(Settings().fileName())
del self.app
def initialise_test(self): def initialise_test(self):
""" """

View File

@ -3,6 +3,7 @@ Functional tests to test the AppLocation class and related methods.
""" """
import os import os
from unittest import TestCase from unittest import TestCase
from PyQt4 import QtCore, QtGui
from openlp.core.utils import is_not_image_file from openlp.core.utils import is_not_image_file
from tests.utils.constants import TEST_RESOURCES_PATH from tests.utils.constants import TEST_RESOURCES_PATH
@ -12,6 +13,17 @@ class TestUtils(TestCase):
""" """
A test suite to test out various methods around the Utils functions. A test suite to test out various methods around the Utils functions.
""" """
def setUp(self):
"""
Some pre-test setup required.
"""
old_app_instance = QtCore.QCoreApplication.instance()
if old_app_instance is None:
self.app = QtGui.QApplication([])
else:
self.app = old_app_instance
def is_not_image_empty_test(self): def is_not_image_empty_test(self):
""" """
Test the method handles an empty string Test the method handles an empty string
@ -50,3 +62,4 @@ class TestUtils(TestCase):
# THEN the result is false # THEN the result is false
assert result is True, 'The file is not an image file so the test should return True' assert result is True, 'The file is not an image file so the test should return True'

View File

@ -49,7 +49,11 @@ class TestEditCustomForm(TestCase):
Create the UI Create the UI
""" """
Registry.create() Registry.create()
old_app_instance = QtCore.QCoreApplication.instance()
if old_app_instance is None:
self.app = QtGui.QApplication([]) self.app = QtGui.QApplication([])
else:
self.app = old_app_instance
self.main_window = QtGui.QMainWindow() self.main_window = QtGui.QMainWindow()
Registry().register('main_window', self.main_window) Registry().register('main_window', self.main_window)
media_item = MagicMock() media_item = MagicMock()
@ -62,7 +66,6 @@ class TestEditCustomForm(TestCase):
""" """
del self.form del self.form
del self.main_window del self.main_window
del self.app
def load_themes_test(self): def load_themes_test(self):
""" """

View File

@ -3,7 +3,7 @@ Module to test the EditCustomSlideForm.
""" """
from unittest import TestCase from unittest import TestCase
from PyQt4 import QtGui from PyQt4 import QtGui, QtCore
from openlp.core.common import Registry from openlp.core.common import Registry
from openlp.plugins.custom.forms.editcustomslideform import EditCustomSlideForm from openlp.plugins.custom.forms.editcustomslideform import EditCustomSlideForm
@ -19,7 +19,11 @@ class TestEditCustomSlideForm(TestCase):
Create the UI Create the UI
""" """
Registry.create() Registry.create()
old_app_instance = QtCore.QCoreApplication.instance()
if old_app_instance is None:
self.app = QtGui.QApplication([]) self.app = QtGui.QApplication([])
else:
self.app = old_app_instance
self.main_window = QtGui.QMainWindow() self.main_window = QtGui.QMainWindow()
Registry().register('main_window', self.main_window) Registry().register('main_window', self.main_window)
self.form = EditCustomSlideForm() self.form = EditCustomSlideForm()
@ -30,7 +34,6 @@ class TestEditCustomSlideForm(TestCase):
""" """
del self.form del self.form
del self.main_window del self.main_window
del self.app
def basic_test(self): def basic_test(self):
""" """

View File

@ -3,7 +3,7 @@ Package to test the openlp.plugins.songs.forms.authorsform package.
""" """
from unittest import TestCase from unittest import TestCase
from PyQt4 import QtGui from PyQt4 import QtGui, QtCore
from openlp.core.common import Registry from openlp.core.common import Registry
from openlp.plugins.songs.forms.authorsform import AuthorsForm from openlp.plugins.songs.forms.authorsform import AuthorsForm
@ -19,7 +19,11 @@ class TestAuthorsForm(TestCase):
Create the UI Create the UI
""" """
Registry.create() Registry.create()
old_app_instance = QtCore.QCoreApplication.instance()
if old_app_instance is None:
self.app = QtGui.QApplication([]) self.app = QtGui.QApplication([])
else:
self.app = old_app_instance
self.main_window = QtGui.QMainWindow() self.main_window = QtGui.QMainWindow()
Registry().register('main_window', self.main_window) Registry().register('main_window', self.main_window)
self.form = AuthorsForm() self.form = AuthorsForm()
@ -30,7 +34,6 @@ class TestAuthorsForm(TestCase):
""" """
del self.form del self.form
del self.main_window del self.main_window
del self.app
def ui_defaults_test(self): def ui_defaults_test(self):
""" """

View File

@ -3,7 +3,7 @@ Package to test the openlp.plugins.songs.forms.editsongform package.
""" """
from unittest import TestCase from unittest import TestCase
from PyQt4 import QtGui from PyQt4 import QtGui, QtCore
from openlp.core.common import Registry from openlp.core.common import Registry
from openlp.plugins.songs.forms.editsongform import EditSongForm from openlp.plugins.songs.forms.editsongform import EditSongForm
@ -20,7 +20,11 @@ class TestEditSongForm(TestCase):
Create the UI Create the UI
""" """
Registry.create() Registry.create()
old_app_instance = QtCore.QCoreApplication.instance()
if old_app_instance is None:
self.app = QtGui.QApplication([]) self.app = QtGui.QApplication([])
else:
self.app = old_app_instance
self.main_window = QtGui.QMainWindow() self.main_window = QtGui.QMainWindow()
Registry().register('main_window', self.main_window) Registry().register('main_window', self.main_window)
Registry().register('theme_manager', MagicMock()) Registry().register('theme_manager', MagicMock())
@ -32,7 +36,6 @@ class TestEditSongForm(TestCase):
""" """
del self.form del self.form
del self.main_window del self.main_window
del self.app
def ui_defaults_test(self): def ui_defaults_test(self):
""" """

View File

@ -19,7 +19,11 @@ class TestEditVerseForm(TestCase):
Create the UI Create the UI
""" """
Registry.create() Registry.create()
old_app_instance = QtCore.QCoreApplication.instance()
if old_app_instance is None:
self.app = QtGui.QApplication([]) self.app = QtGui.QApplication([])
else:
self.app = old_app_instance
self.main_window = QtGui.QMainWindow() self.main_window = QtGui.QMainWindow()
Registry().register('main_window', self.main_window) Registry().register('main_window', self.main_window)
self.form = EditVerseForm() self.form = EditVerseForm()
@ -30,7 +34,6 @@ class TestEditVerseForm(TestCase):
""" """
del self.form del self.form
del self.main_window del self.main_window
del self.app
def ui_defaults_test(self): def ui_defaults_test(self):
""" """

View File

@ -3,7 +3,7 @@ Package to test the openlp.plugins.songs.forms.topicsform package.
""" """
from unittest import TestCase from unittest import TestCase
from PyQt4 import QtGui from PyQt4 import QtGui, QtCore
from openlp.core.common import Registry from openlp.core.common import Registry
from openlp.plugins.songs.forms.topicsform import TopicsForm from openlp.plugins.songs.forms.topicsform import TopicsForm
@ -19,7 +19,11 @@ class TestTopicsForm(TestCase):
Create the UI Create the UI
""" """
Registry.create() Registry.create()
old_app_instance = QtCore.QCoreApplication.instance()
if old_app_instance is None:
self.app = QtGui.QApplication([]) self.app = QtGui.QApplication([])
else:
self.app = old_app_instance
self.main_window = QtGui.QMainWindow() self.main_window = QtGui.QMainWindow()
Registry().register('main_window', self.main_window) Registry().register('main_window', self.main_window)
self.form = TopicsForm() self.form = TopicsForm()
@ -30,7 +34,6 @@ class TestTopicsForm(TestCase):
""" """
del self.form del self.form
del self.main_window del self.main_window
del self.app
def ui_defaults_test(self): def ui_defaults_test(self):
""" """