← Back to team overview

openlp-core team mailing list archive

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

 

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

Requested reviews:
  OpenLP Core (openlp-core)

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

Fix tests.
To avoid segfaults reuse QApplication instance.
Also use ICU when getting locale sort key.
-- 
https://code.launchpad.net/~tomasgroth/openlp/fix-tests/+merge/210288
Your team OpenLP Core is requested to review the proposed merge of lp:~tomasgroth/openlp/fix-tests into lp:openlp.
=== modified file 'openlp/core/utils/__init__.py'
--- openlp/core/utils/__init__.py	2014-01-11 21:29:01 +0000
+++ openlp/core/utils/__init__.py	2014-03-10 20:02:23 +0000
@@ -426,17 +426,14 @@
         The corresponding string.
     """
     string = string.lower()
-    # For Python 3 on platforms other than Windows ICU is not necessary. In those cases locale.strxfrm(str) can be used.
-    if os.name == 'nt':
-        global ICU_COLLATOR
-        if ICU_COLLATOR is None:
-            import icu
-            from .languagemanager import LanguageManager
-            language = LanguageManager.get_language()
-            icu_locale = icu.Locale(language)
-            ICU_COLLATOR = icu.Collator.createInstance(icu_locale)
-        return ICU_COLLATOR.getSortKey(string)
-    return locale.strxfrm(string).encode()
+    global ICU_COLLATOR
+    if ICU_COLLATOR is None:
+        import icu
+        from .languagemanager import LanguageManager
+        language = LanguageManager.get_language()
+        icu_locale = icu.Locale(language)
+        ICU_COLLATOR = icu.Collator.createInstance(icu_locale)
+    return ICU_COLLATOR.getSortKey(string)
 
 
 def get_natural_key(string):

=== modified file 'tests/interfaces/openlp_core_lib/test_pluginmanager.py'
--- tests/interfaces/openlp_core_lib/test_pluginmanager.py	2013-12-13 17:44:05 +0000
+++ tests/interfaces/openlp_core_lib/test_pluginmanager.py	2014-03-10 20:02:23 +0000
@@ -7,7 +7,7 @@
 from tempfile import mkstemp, mkdtemp
 from unittest import TestCase
 
-from PyQt4 import QtGui
+from PyQt4 import QtGui, QtCore
 
 from openlp.core.common import Registry, Settings
 from openlp.core.lib.pluginmanager import PluginManager
@@ -29,12 +29,15 @@
         Settings().setValue('advanced/data path', self.temp_dir)
         Registry.create()
         Registry().register('service_list', MagicMock())
-        self.app = QtGui.QApplication([])
+        old_app_instance = QtCore.QCoreApplication.instance()
+        if old_app_instance is None:
+            self.app = QtGui.QApplication([])
+        else:
+            self.app = old_app_instance
         self.main_window = QtGui.QMainWindow()
         Registry().register('main_window', self.main_window)
 
     def tearDown(self):
-        del self.app
         del self.main_window
         Settings().remove('advanced/data path')
         shutil.rmtree(self.temp_dir)

=== modified file 'tests/interfaces/openlp_core_ui/test_filerenamedialog.py'
--- tests/interfaces/openlp_core_ui/test_filerenamedialog.py	2013-12-13 17:44:05 +0000
+++ tests/interfaces/openlp_core_ui/test_filerenamedialog.py	2014-03-10 20:02:23 +0000
@@ -3,7 +3,7 @@
 """
 from unittest import TestCase
 
-from PyQt4 import QtGui, QtTest
+from PyQt4 import QtCore, QtGui, QtTest
 
 from openlp.core.common import Registry
 from openlp.core.ui import filerenameform
@@ -17,7 +17,11 @@
         Create the UI
         """
         Registry.create()
-        self.app = QtGui.QApplication([])
+        old_app_instance = QtCore.QCoreApplication.instance()
+        if old_app_instance is None:
+            self.app = QtGui.QApplication([])
+        else:
+            self.app = old_app_instance
         self.main_window = QtGui.QMainWindow()
         Registry().register('main_window', self.main_window)
         self.form = filerenameform.FileRenameForm()
@@ -28,7 +32,6 @@
         """
         del self.form
         del self.main_window
-        del self.app
 
     def window_title_test(self):
         """

=== modified file 'tests/interfaces/openlp_core_ui/test_listpreviewwidget.py'
--- tests/interfaces/openlp_core_ui/test_listpreviewwidget.py	2014-01-01 14:59:57 +0000
+++ tests/interfaces/openlp_core_ui/test_listpreviewwidget.py	2014-03-10 20:02:23 +0000
@@ -4,7 +4,7 @@
 
 from unittest import TestCase
 
-from PyQt4 import QtGui
+from PyQt4 import QtGui, QtCore
 
 from openlp.core.common import Registry
 from openlp.core.lib import ServiceItem
@@ -20,7 +20,11 @@
         Create the UI.
         """
         Registry.create()
-        self.app = QtGui.QApplication([])
+        old_app_instance = QtCore.QCoreApplication.instance()
+        if old_app_instance is None:
+            self.app = QtGui.QApplication([])
+        else:
+            self.app = old_app_instance
         self.main_window = QtGui.QMainWindow()
         self.image = QtGui.QImage(1, 1, QtGui.QImage.Format_RGB32)
         self.image_manager = MagicMock()
@@ -34,7 +38,6 @@
         """
         del self.preview_widget
         del self.main_window
-        del self.app
 
     def initial_slide_count_test(self):
         """

=== modified file 'tests/interfaces/openlp_core_ui/test_mainwindow.py'
--- tests/interfaces/openlp_core_ui/test_mainwindow.py	2014-01-01 14:59:57 +0000
+++ tests/interfaces/openlp_core_ui/test_mainwindow.py	2014-03-10 20:02:23 +0000
@@ -3,7 +3,7 @@
 """
 from unittest import TestCase
 
-from PyQt4 import QtGui
+from PyQt4 import QtGui, QtCore
 
 from openlp.core.common import Registry
 from openlp.core.ui.mainwindow import MainWindow
@@ -18,7 +18,11 @@
         """
         Registry.create()
         self.registry = Registry()
-        self.app = QtGui.QApplication([])
+        old_app_instance = QtCore.QCoreApplication.instance()
+        if old_app_instance is None:
+            self.app = QtGui.QApplication([])
+        else:
+            self.app = old_app_instance
         # Mock cursor busy/normal methods.
         self.app.set_busy_cursor = MagicMock()
         self.app.set_normal_cursor = MagicMock()
@@ -42,7 +46,6 @@
         Delete all the C++ objects at the end so that we don't have a segfault
         """
         del self.main_window
-        del self.app
 
     def restore_current_media_manager_item_test(self):
         """

=== modified file 'tests/interfaces/openlp_core_ui/test_servicemanager.py'
--- tests/interfaces/openlp_core_ui/test_servicemanager.py	2013-12-31 20:29:03 +0000
+++ tests/interfaces/openlp_core_ui/test_servicemanager.py	2014-03-10 20:02:23 +0000
@@ -19,7 +19,11 @@
         Create the UI
         """
         Registry.create()
-        self.app = QtGui.QApplication([])
+        old_app_instance = QtCore.QCoreApplication.instance()
+        if old_app_instance is None:
+            self.app = QtGui.QApplication([])
+        else:
+            self.app = old_app_instance
         ScreenList.create(self.app.desktop())
         Registry().register('application', MagicMock())
         with patch('openlp.core.lib.PluginManager'):
@@ -31,7 +35,6 @@
         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):
         """

=== modified file 'tests/interfaces/openlp_core_ui/test_servicenotedialog.py'
--- tests/interfaces/openlp_core_ui/test_servicenotedialog.py	2013-12-13 17:44:05 +0000
+++ tests/interfaces/openlp_core_ui/test_servicenotedialog.py	2014-03-10 20:02:23 +0000
@@ -17,7 +17,11 @@
         Create the UI
         """
         Registry.create()
-        self.app = QtGui.QApplication([])
+        old_app_instance = QtCore.QCoreApplication.instance()
+        if old_app_instance is None:
+            self.app = QtGui.QApplication([])
+        else:
+            self.app = old_app_instance
         self.main_window = QtGui.QMainWindow()
         Registry().register('main_window', self.main_window)
         self.form = servicenoteform.ServiceNoteForm()
@@ -28,7 +32,6 @@
         """
         del self.form
         del self.main_window
-        del self.app
 
     def basic_display_test(self):
         """

=== modified file 'tests/interfaces/openlp_core_ui/test_settings_form.py'
--- tests/interfaces/openlp_core_ui/test_settings_form.py	2013-12-13 17:44:05 +0000
+++ tests/interfaces/openlp_core_ui/test_settings_form.py	2014-03-10 20:02:23 +0000
@@ -31,7 +31,11 @@
         self.dummy2 = MagicMock()
         self.dummy3 = MagicMock()
         self.desktop = MagicMock()
-        self.app = QtGui.QApplication([])
+        old_app_instance = QtCore.QCoreApplication.instance()
+        if old_app_instance is None:
+            self.app = QtGui.QApplication([])
+        else:
+            self.app = old_app_instance
         self.desktop.primaryScreen.return_value = SCREEN['primary']
         self.desktop.screenCount.return_value = SCREEN['number']
         self.desktop.screenGeometry.return_value = SCREEN['size']
@@ -44,7 +48,6 @@
         Delete all the C++ objects at the end so that we don't have a segfault
         """
         del self.form
-        del self.app
 
     def basic_cancel_test(self):
         """

=== modified file 'tests/interfaces/openlp_core_ui/test_starttimedialog.py'
--- tests/interfaces/openlp_core_ui/test_starttimedialog.py	2014-01-01 14:59:57 +0000
+++ tests/interfaces/openlp_core_ui/test_starttimedialog.py	2014-03-10 20:02:23 +0000
@@ -17,7 +17,11 @@
         Create the UI
         """
         Registry.create()
-        self.app = QtGui.QApplication([])
+        old_app_instance = QtCore.QCoreApplication.instance()
+        if old_app_instance is None:
+            self.app = QtGui.QApplication([])
+        else:
+            self.app = old_app_instance
         self.main_window = QtGui.QMainWindow()
         Registry().register('main_window', self.main_window)
         self.form = starttimeform.StartTimeForm()
@@ -28,7 +32,6 @@
         """
         del self.form
         del self.main_window
-        del self.app
 
     def ui_defaults_test(self):
         """

=== modified file 'tests/interfaces/openlp_core_ui/test_thememanager.py'
--- tests/interfaces/openlp_core_ui/test_thememanager.py	2014-01-04 08:28:45 +0000
+++ tests/interfaces/openlp_core_ui/test_thememanager.py	2014-03-10 20:02:23 +0000
@@ -33,7 +33,7 @@
 from unittest import TestCase
 from tempfile import mkstemp
 
-from PyQt4 import QtGui
+from PyQt4 import QtGui, QtCore
 
 from openlp.core.common import Registry, Settings
 from openlp.core.ui import ThemeManager
@@ -50,7 +50,11 @@
         """
         fd, self.ini_file = mkstemp('.ini')
         Settings().set_filename(self.ini_file)
-        self.app = QtGui.QApplication([])
+        old_app_instance = QtCore.QCoreApplication.instance()
+        if old_app_instance is None:
+            self.app = QtGui.QApplication([])
+        else:
+            self.app = old_app_instance
         Registry.create()
         self.theme_manager = ThemeManager()
 
@@ -60,7 +64,6 @@
         """
         os.unlink(self.ini_file)
         os.unlink(Settings().fileName())
-        del self.app
 
     def initialise_test(self):
         """

=== modified file 'tests/interfaces/openlp_plugins/custom/forms/test_customform.py'
--- tests/interfaces/openlp_plugins/custom/forms/test_customform.py	2013-12-13 17:44:05 +0000
+++ tests/interfaces/openlp_plugins/custom/forms/test_customform.py	2014-03-10 20:02:23 +0000
@@ -21,7 +21,11 @@
         Create the UI
         """
         Registry.create()
-        self.app = QtGui.QApplication([])
+        old_app_instance = QtCore.QCoreApplication.instance()
+        if old_app_instance is None:
+            self.app = QtGui.QApplication([])
+        else:
+            self.app = old_app_instance
         self.main_window = QtGui.QMainWindow()
         Registry().register('main_window', self.main_window)
         media_item = MagicMock()
@@ -34,7 +38,6 @@
         """
         del self.form
         del self.main_window
-        del self.app
 
     def load_themes_test(self):
         """

=== modified file 'tests/interfaces/openlp_plugins/custom/forms/test_customslideform.py'
--- tests/interfaces/openlp_plugins/custom/forms/test_customslideform.py	2013-12-13 17:44:05 +0000
+++ tests/interfaces/openlp_plugins/custom/forms/test_customslideform.py	2014-03-10 20:02:23 +0000
@@ -3,7 +3,7 @@
 """
 from unittest import TestCase
 
-from PyQt4 import QtGui
+from PyQt4 import QtGui, QtCore
 
 from openlp.core.common import Registry
 from openlp.plugins.custom.forms.editcustomslideform import EditCustomSlideForm
@@ -19,7 +19,11 @@
         Create the UI
         """
         Registry.create()
-        self.app = QtGui.QApplication([])
+        old_app_instance = QtCore.QCoreApplication.instance()
+        if old_app_instance is None:
+            self.app = QtGui.QApplication([])
+        else:
+            self.app = old_app_instance
         self.main_window = QtGui.QMainWindow()
         Registry().register('main_window', self.main_window)
         self.form = EditCustomSlideForm()
@@ -30,7 +34,6 @@
         """
         del self.form
         del self.main_window
-        del self.app
 
     def basic_test(self):
         """

=== modified file 'tests/interfaces/openlp_plugins/songs/forms/test_authorsform.py'
--- tests/interfaces/openlp_plugins/songs/forms/test_authorsform.py	2013-12-13 17:44:05 +0000
+++ tests/interfaces/openlp_plugins/songs/forms/test_authorsform.py	2014-03-10 20:02:23 +0000
@@ -3,7 +3,7 @@
 """
 from unittest import TestCase
 
-from PyQt4 import QtGui
+from PyQt4 import QtGui, QtCore
 
 from openlp.core.common import Registry
 from openlp.plugins.songs.forms.authorsform import AuthorsForm
@@ -19,7 +19,11 @@
         Create the UI
         """
         Registry.create()
-        self.app = QtGui.QApplication([])
+        old_app_instance = QtCore.QCoreApplication.instance()
+        if old_app_instance is None:
+            self.app = QtGui.QApplication([])
+        else:
+            self.app = old_app_instance
         self.main_window = QtGui.QMainWindow()
         Registry().register('main_window', self.main_window)
         self.form = AuthorsForm()
@@ -30,7 +34,6 @@
         """
         del self.form
         del self.main_window
-        del self.app
 
     def ui_defaults_test(self):
         """

=== modified file 'tests/interfaces/openlp_plugins/songs/forms/test_editsongform.py'
--- tests/interfaces/openlp_plugins/songs/forms/test_editsongform.py	2013-12-13 17:44:05 +0000
+++ tests/interfaces/openlp_plugins/songs/forms/test_editsongform.py	2014-03-10 20:02:23 +0000
@@ -3,7 +3,7 @@
 """
 from unittest import TestCase
 
-from PyQt4 import QtGui
+from PyQt4 import QtGui, QtCore
 
 from openlp.core.common import Registry
 from openlp.plugins.songs.forms.editsongform import EditSongForm
@@ -20,7 +20,11 @@
         Create the UI
         """
         Registry.create()
-        self.app = QtGui.QApplication([])
+        old_app_instance = QtCore.QCoreApplication.instance()
+        if old_app_instance is None:
+            self.app = QtGui.QApplication([])
+        else:
+            self.app = old_app_instance
         self.main_window = QtGui.QMainWindow()
         Registry().register('main_window', self.main_window)
         Registry().register('theme_manager', MagicMock())
@@ -32,7 +36,6 @@
         """
         del self.form
         del self.main_window
-        del self.app
 
     def ui_defaults_test(self):
         """

=== modified file 'tests/interfaces/openlp_plugins/songs/forms/test_editverseform.py'
--- tests/interfaces/openlp_plugins/songs/forms/test_editverseform.py	2013-12-13 17:44:05 +0000
+++ tests/interfaces/openlp_plugins/songs/forms/test_editverseform.py	2014-03-10 20:02:23 +0000
@@ -19,7 +19,11 @@
         Create the UI
         """
         Registry.create()
-        self.app = QtGui.QApplication([])
+        old_app_instance = QtCore.QCoreApplication.instance()
+        if old_app_instance is None:
+            self.app = QtGui.QApplication([])
+        else:
+            self.app = old_app_instance
         self.main_window = QtGui.QMainWindow()
         Registry().register('main_window', self.main_window)
         self.form = EditVerseForm()
@@ -30,7 +34,6 @@
         """
         del self.form
         del self.main_window
-        del self.app
 
     def ui_defaults_test(self):
         """

=== modified file 'tests/interfaces/openlp_plugins/songs/forms/test_topicsform.py'
--- tests/interfaces/openlp_plugins/songs/forms/test_topicsform.py	2013-12-13 17:44:05 +0000
+++ tests/interfaces/openlp_plugins/songs/forms/test_topicsform.py	2014-03-10 20:02:23 +0000
@@ -3,7 +3,7 @@
 """
 from unittest import TestCase
 
-from PyQt4 import QtGui
+from PyQt4 import QtGui, QtCore
 
 from openlp.core.common import Registry
 from openlp.plugins.songs.forms.topicsform import TopicsForm
@@ -19,7 +19,11 @@
         Create the UI
         """
         Registry.create()
-        self.app = QtGui.QApplication([])
+        old_app_instance = QtCore.QCoreApplication.instance()
+        if old_app_instance is None:
+            self.app = QtGui.QApplication([])
+        else:
+            self.app = old_app_instance
         self.main_window = QtGui.QMainWindow()
         Registry().register('main_window', self.main_window)
         self.form = TopicsForm()
@@ -30,7 +34,6 @@
         """
         del self.form
         del self.main_window
-        del self.app
 
     def ui_defaults_test(self):
         """


Follow ups