Fixes for the test-suite to make to run under wine/windows.

The only test that still fails is tests/interfaces/openlp_core_lib/test_pluginmanager.py

bzr-revno: 2333
This commit is contained in:
Tomas Groth 2014-03-14 17:34:15 +00:00 committed by Tim Bentley
commit 31860d8d6a
13 changed files with 72 additions and 37 deletions

View File

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

View File

@ -30,6 +30,7 @@
Functional tests to test the AppLocation class and related methods.
"""
import copy
import os
from unittest import TestCase
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()
mocked_settings = mocked_class.return_value
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_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()
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
mocked_settings.contains.assert_called_with('advanced/data path')
mocked_get_directory.assert_called_with(AppLocation.DataDir)
mocked_check_directory_exists.assert_called_with('test/dir')
self.assertEqual('test/dir', data_path, 'Result should be "test/dir"')
mocked_check_directory_exists.assert_called_with(os.path.join('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):
"""
@ -109,14 +110,14 @@ class TestAppLocation(TestCase):
with patch('openlp.core.common.AppLocation.get_data_path') as mocked_get_data_path, \
patch('openlp.core.common.applocation.os.listdir') as mocked_listdir:
# 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)
# When: Get the list of files.
result = AppLocation.get_files('section', '.mp3')
# 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.
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, \
patch('openlp.core.common.applocation.check_directory_exists') as mocked_check_directory_exists:
# 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
# WHEN: we call AppLocation.get_data_path()
data_path = AppLocation.get_section_data_path('section')
# THEN: check that all the correct methods were called, and the result is correct
mocked_check_directory_exists.assert_called_with('test/dir/section')
self.assertEqual('test/dir/section', data_path, 'Result should be "test/dir/section"')
mocked_check_directory_exists.assert_called_with(os.path.join('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):
"""
@ -144,13 +145,13 @@ class TestAppLocation(TestCase):
"""
# GIVEN: A mocked out _get_frozen_path function
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
directory = AppLocation.get_directory(AppLocation.AppDir)
# 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):
"""

View File

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

View File

@ -179,16 +179,18 @@ class TestServiceItem(TestCase):
# 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_item2.is_valid, 'The second service item should be valid')
self.assertEqual(test_file1, service_item.get_rendered_frame(0),
'The first frame should match the path to the image')
self.assertEqual(test_file2, service_item2.get_rendered_frame(0),
'The Second frame should match the path to the image')
self.assertEqual(frame_array1, service_item.get_frames()[0], 'The return should match the frame array1')
self.assertEqual(frame_array2, service_item2.get_frames()[0], 'The return should match the frame array2')
self.assertEqual(test_file1, service_item.get_frame_path(0),
'The frame path should match the full path to the image')
self.assertEqual(test_file2, service_item2.get_frame_path(0),
'The frame path should match the full path to the image')
# 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),
'The first frame should match the path to the image')
self.assertEqual(test_file2, service_item2.get_rendered_frame(0),
'The Second frame should match the path to the image')
self.assertEqual(frame_array1, service_item.get_frames()[0], 'The return should match the frame array1')
self.assertEqual(frame_array2, service_item2.get_frames()[0], 'The return should match the frame array2')
self.assertEqual(test_file1, service_item.get_frame_path(0),
'The frame path should match the full path to the image')
self.assertEqual(test_file2, service_item2.get_frame_path(0),
'The frame path should match the full path to the image')
self.assertEqual(image_name1, service_item.get_frame_title(0),
'The 1st frame title should match the image name')
self.assertEqual(image_name2, service_item2.get_frame_title(0),

View File

@ -51,7 +51,7 @@ class TestActionList(TestCase):
self.action_list = ActionList.get_instance()
Settings.setDefaultFormat(Settings.IniFormat)
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.beginGroup('shortcuts')
@ -60,6 +60,7 @@ class TestActionList(TestCase):
Clean up
"""
self.settings.endGroup()
os.close(self.fd)
os.unlink(Settings().fileName())
def test_add_action_same_parent(self):

View File

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

View File

@ -63,6 +63,8 @@ class TestPdfController(TestCase):
Settings().extend_default_settings(__default_settings__)
self.temp_folder = mkdtemp()
self.thumbnail_folder = mkdtemp()
self.mock_plugin = MagicMock()
self.mock_plugin.settings_section = self.temp_folder
def tearDown(self):
"""
@ -70,6 +72,7 @@ class TestPdfController(TestCase):
"""
del self.application
try:
os.close(self.fd)
os.unlink(Settings().fileName())
shutil.rmtree(self.thumbnail_folder)
shutil.rmtree(self.temp_folder)
@ -84,7 +87,7 @@ class TestPdfController(TestCase):
controller = None
# 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
self.assertEqual('Pdf', controller.name, 'The name of the presentation controller should be correct')
@ -97,7 +100,7 @@ class TestPdfController(TestCase):
test_file = os.path.join(TEST_RESOURCES_PATH, 'presentations', 'pdf_test1.pdf')
# WHEN: The Pdf is loaded
controller = PdfController(plugin=MagicMock())
controller = PdfController(plugin=self.mock_plugin)
if not controller.check_available():
raise SkipTest('Could not detect mudraw or ghostscript, so skipping PDF test')
controller.temp_folder = self.temp_folder

View File

@ -60,7 +60,9 @@ class TestPresentationController(TestCase):
controller = None
# 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
self.assertEqual('PresentationController', controller.name,

View File

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

View File

@ -24,7 +24,7 @@ class TestPluginManager(TestCase):
Some pre-test setup required.
"""
Settings.setDefaultFormat(Settings.IniFormat)
fd, self.ini_file = mkstemp('.ini')
self.fd, self.ini_file = mkstemp('.ini')
self.temp_dir = mkdtemp('openlp')
Settings().set_filename(self.ini_file)
Settings().setValue('advanced/data path', self.temp_dir)
@ -40,9 +40,10 @@ class TestPluginManager(TestCase):
def tearDown(self):
del self.main_window
os.close(self.fd)
os.unlink(Settings().fileName())
Settings().remove('advanced/data path')
shutil.rmtree(self.temp_dir)
os.unlink(Settings().fileName())
def find_plugins_test(self):
"""
@ -68,3 +69,4 @@ class TestPluginManager(TestCase):
assert 'songusage' in plugin_names, 'There should be a "songusage" plugin.'
assert 'alerts' in plugin_names, 'There should be a "alerts" plugin.'
assert 'remotes' in plugin_names, 'There should be a "remotes" plugin.'

View File

@ -34,7 +34,6 @@ class TestServiceManager(TestCase):
"""
Delete all the C++ objects at the end so that we don't have a segfault
"""
del self.main_window
def basic_service_manager_test(self):
"""

View File

@ -49,7 +49,7 @@ class TestThemeManager(TestCase):
Create the UI
"""
Settings.setDefaultFormat(Settings.IniFormat)
fd, self.ini_file = mkstemp('.ini')
self.fd, self.ini_file = mkstemp('.ini')
Settings().set_filename(self.ini_file)
old_app_instance = QtCore.QCoreApplication.instance()
if old_app_instance is None:
@ -63,6 +63,7 @@ class TestThemeManager(TestCase):
"""
Delete all the C++ objects at the end so that we don't have a segfault
"""
os.close(self.fd)
os.unlink(Settings().fileName())
def initialise_test(self):

View File

@ -3,6 +3,7 @@ Functional tests to test the AppLocation class and related methods.
"""
import os
from unittest import TestCase
from PyQt4 import QtCore, QtGui
from openlp.core.utils import is_not_image_file
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.
"""
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):
"""
Test the method handles an empty string
@ -49,4 +61,5 @@ class TestUtils(TestCase):
result = is_not_image_file(file_name)
# 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'