← Back to team overview

openlp-core team mailing list archive

[Merge] lp:~tomasgroth/openlp/fix-wine-tests into lp:openlp

 

Tomas Groth has proposed merging lp:~tomasgroth/openlp/fix-wine-tests into lp:openlp.

Requested reviews:
  OpenLP Core (openlp-core)

For more details, see:
https://code.launchpad.net/~tomasgroth/openlp/fix-wine-tests/+merge/210909

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
-- 
https://code.launchpad.net/~tomasgroth/openlp/fix-wine-tests/+merge/210909
Your team OpenLP Core is requested to review the proposed merge of lp:~tomasgroth/openlp/fix-wine-tests into lp:openlp.
=== modified file 'openlp/plugins/presentations/lib/pdfcontroller.py'
--- openlp/plugins/presentations/lib/pdfcontroller.py	2014-02-21 22:27:00 +0000
+++ openlp/plugins/presentations/lib/pdfcontroller.py	2014-03-13 21:18:55 +0000
@@ -54,8 +54,8 @@
         :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

=== modified file 'tests/functional/openlp_core_common/test_applocation.py'
--- tests/functional/openlp_core_common/test_applocation.py	2013-12-24 08:56:50 +0000
+++ tests/functional/openlp_core_common/test_applocation.py	2014-03-13 21:18:55 +0000
@@ -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 @@
             # 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 @@
             # 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 @@
         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 @@
         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 @@
         """
         # 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):
         """

=== modified file 'tests/functional/openlp_core_common/test_settings.py'
--- tests/functional/openlp_core_common/test_settings.py	2014-03-12 05:31:19 +0000
+++ tests/functional/openlp_core_common/test_settings.py	2014-03-13 21:18:55 +0000
@@ -47,7 +47,7 @@
         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 @@
         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):

=== modified file 'tests/functional/openlp_core_lib/test_serviceitem.py'
--- tests/functional/openlp_core_lib/test_serviceitem.py	2013-12-31 07:27:07 +0000
+++ tests/functional/openlp_core_lib/test_serviceitem.py	2014-03-13 21:18:55 +0000
@@ -179,16 +179,18 @@
         # 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),

=== modified file 'tests/functional/openlp_core_utils/test_actions.py'
--- tests/functional/openlp_core_utils/test_actions.py	2014-03-12 19:05:06 +0000
+++ tests/functional/openlp_core_utils/test_actions.py	2014-03-13 21:18:55 +0000
@@ -51,7 +51,7 @@
         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 @@
         Clean up
         """
         self.settings.endGroup()
+        os.close(self.fd)
         os.unlink(Settings().fileName())
 
     def test_add_action_same_parent(self):

=== modified file 'tests/functional/openlp_core_utils/test_utils.py'
--- tests/functional/openlp_core_utils/test_utils.py	2013-12-24 11:32:56 +0000
+++ tests/functional/openlp_core_utils/test_utils.py	2014-03-13 21:18:55 +0000
@@ -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 @@
         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 @@
         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
 

=== modified file 'tests/functional/openlp_plugins/presentations/test_pdfcontroller.py'
--- tests/functional/openlp_plugins/presentations/test_pdfcontroller.py	2014-03-12 05:31:19 +0000
+++ tests/functional/openlp_plugins/presentations/test_pdfcontroller.py	2014-03-13 21:18:55 +0000
@@ -63,6 +63,8 @@
         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 @@
         """
         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 @@
         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 @@
         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

=== modified file 'tests/functional/openlp_plugins/presentations/test_presentationcontroller.py'
--- tests/functional/openlp_plugins/presentations/test_presentationcontroller.py	2014-03-04 20:18:14 +0000
+++ tests/functional/openlp_plugins/presentations/test_presentationcontroller.py	2014-03-13 21:18:55 +0000
@@ -60,7 +60,9 @@
         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,

=== modified file 'tests/functional/openlp_plugins/songs/test_mediaitem.py'
--- tests/functional/openlp_plugins/songs/test_mediaitem.py	2014-03-12 05:31:19 +0000
+++ tests/functional/openlp_plugins/songs/test_mediaitem.py	2014-03-13 21:18:55 +0000
@@ -29,7 +29,7 @@
             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 @@
         del self.application
         # Not all tests use settings!
         try:
+            os.close(self.fd)
             os.unlink(Settings().fileName())
         except Exception:
             pass

=== modified file 'tests/interfaces/openlp_core_lib/test_pluginmanager.py'
--- tests/interfaces/openlp_core_lib/test_pluginmanager.py	2014-03-12 22:15:08 +0000
+++ tests/interfaces/openlp_core_lib/test_pluginmanager.py	2014-03-13 21:18:55 +0000
@@ -24,7 +24,7 @@
         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 @@
 
     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 @@
         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.'
+

=== modified file 'tests/interfaces/openlp_core_ui/test_servicemanager.py'
--- tests/interfaces/openlp_core_ui/test_servicemanager.py	2014-03-10 19:56:36 +0000
+++ tests/interfaces/openlp_core_ui/test_servicemanager.py	2014-03-13 21:18:55 +0000
@@ -34,7 +34,6 @@
         """
         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):
         """

=== modified file 'tests/interfaces/openlp_core_ui/test_thememanager.py'
--- tests/interfaces/openlp_core_ui/test_thememanager.py	2014-03-12 22:15:08 +0000
+++ tests/interfaces/openlp_core_ui/test_thememanager.py	2014-03-13 21:18:55 +0000
@@ -49,7 +49,7 @@
         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 @@
         """
         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):

=== modified file 'tests/interfaces/openlp_core_utils/test_utils.py'
--- tests/interfaces/openlp_core_utils/test_utils.py	2013-08-31 18:17:38 +0000
+++ tests/interfaces/openlp_core_utils/test_utils.py	2014-03-13 21:18:55 +0000
@@ -3,6 +3,7 @@
 """
 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 @@
     """
     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 @@
         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'
\ No newline at end of file
+        assert result is True, 'The file is not an image file so the test should return True'
+


Follow ups