From cffad287499e060ad0dca9647470a27e7e25f71d Mon Sep 17 00:00:00 2001 From: Tomas Groth Date: Wed, 14 Jan 2015 11:56:18 +0100 Subject: [PATCH 1/6] Close session after upgrade. Fixes a filelock issue in windows tests. --- openlp/core/lib/db.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/openlp/core/lib/db.py b/openlp/core/lib/db.py index b846ccf15..7d4f8e317 100644 --- a/openlp/core/lib/db.py +++ b/openlp/core/lib/db.py @@ -156,7 +156,10 @@ def upgrade_db(url, upgrade): except (SQLAlchemyError, DBAPIError): version_meta = Metadata.populate(key='version', value=int(upgrade.__version__)) session.commit() - return int(version_meta.value), upgrade.__version__ + upgrade_version = upgrade.__version__ + version_meta = int(version_meta.value) + session.close() + return version_meta, upgrade_version def delete_database(plugin_name, db_file_name=None): From dc3cd4157622275a242c17799baf2a7ac2a2294b Mon Sep 17 00:00:00 2001 From: Tomas Groth Date: Wed, 14 Jan 2015 11:57:54 +0100 Subject: [PATCH 2/6] Use a in-memory sqlite DB for projector test, instead of filebased. Fixes a filelock issue in windows tests. --- tests/interfaces/openlp_core_ui/test_projectoreditform.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/tests/interfaces/openlp_core_ui/test_projectoreditform.py b/tests/interfaces/openlp_core_ui/test_projectoreditform.py index ae3a53039..f7b882528 100644 --- a/tests/interfaces/openlp_core_ui/test_projectoreditform.py +++ b/tests/interfaces/openlp_core_ui/test_projectoreditform.py @@ -31,8 +31,6 @@ Interface tests to test the openlp.core.ui.projector.editform.ProjectorEditForm( class and methods. """ -import os -import tempfile from unittest import TestCase from openlp.core.common import Registry, Settings @@ -43,8 +41,6 @@ from tests.functional import patch from tests.helpers.testmixin import TestMixin from tests.resources.projector.data import TEST1_DATA, TEST2_DATA -tmpfile = tempfile.mkstemp(prefix='openlp-test-projectormanager', suffix='.sql')[1] - class TestProjectorEditForm(TestCase, TestMixin): """ @@ -60,8 +56,7 @@ class TestProjectorEditForm(TestCase, TestMixin): self.setup_application() Registry.create() with patch('openlp.core.lib.projector.db.init_url') as mocked_init_url: - mocked_init_url.start() - mocked_init_url.return_value = 'sqlite:///{}'.format(tmpfile) + mocked_init_url.return_value = 'sqlite://' self.projectordb = ProjectorDB() self.projector_form = ProjectorEditForm(projectordb=self.projectordb) @@ -74,7 +69,6 @@ class TestProjectorEditForm(TestCase, TestMixin): """ self.projectordb.session.close() del(self.projector_form) - os.remove(tmpfile) self.destroy_settings() def edit_form_add_projector_test(self): From 1efc145cdfc60265ca14360f2db7db6c6cf57115 Mon Sep 17 00:00:00 2001 From: Tomas Groth Date: Wed, 14 Jan 2015 12:32:27 +0100 Subject: [PATCH 3/6] PEP8 fixes --- openlp/core/ui/slidecontroller.py | 1 - openlp/core/utils/__init__.py | 2 +- .../openlp_core_ui/test_slidecontroller.py | 5 +-- .../openlp_core_ui/test_themeform.py | 34 +++++++++---------- .../functional/openlp_core_utils/test_init.py | 4 +-- .../openlp_plugins/custom/test_mediaitem.py | 2 +- 6 files changed, 23 insertions(+), 25 deletions(-) diff --git a/openlp/core/ui/slidecontroller.py b/openlp/core/ui/slidecontroller.py index ee627fc6c..c8efd42b7 100644 --- a/openlp/core/ui/slidecontroller.py +++ b/openlp/core/ui/slidecontroller.py @@ -125,7 +125,6 @@ class InfoLabel(QtGui.QLabel): alignment = QtCore.Qt.AlignLeft painter.drawText(self.rect(), alignment, elided) - def setText(self, text): """ Reimplemented to set the tool tip text. diff --git a/openlp/core/utils/__init__.py b/openlp/core/utils/__init__.py index 257351758..7ecb56ea7 100644 --- a/openlp/core/utils/__init__.py +++ b/openlp/core/utils/__init__.py @@ -429,7 +429,7 @@ def get_uno_command(connection_type='pipe'): """ for command in ['libreoffice', 'soffice']: if which(command): - break + break else: raise FileNotFoundError('Command not found') diff --git a/tests/functional/openlp_core_ui/test_slidecontroller.py b/tests/functional/openlp_core_ui/test_slidecontroller.py index 9a6edd567..b0297aca0 100644 --- a/tests/functional/openlp_core_ui/test_slidecontroller.py +++ b/tests/functional/openlp_core_ui/test_slidecontroller.py @@ -560,6 +560,7 @@ class TestSlideController(TestCase): mocked_preview_widget.change_slide.assert_called_once_with(7) mocked_slide_selected.assert_called_once_with() + class TestInfoLabel(TestCase): def paint_event_text_fits_test(self): @@ -570,7 +571,7 @@ class TestInfoLabel(TestCase): metrics = QtGui.QFontMetrics(font) with patch('openlp.core.ui.slidecontroller.QtGui.QLabel'), \ - patch('openlp.core.ui.slidecontroller.QtGui.QPainter') as mocked_qpainter: + patch('openlp.core.ui.slidecontroller.QtGui.QPainter') as mocked_qpainter: # GIVEN: An instance of InfoLabel, with mocked text return, width and rect methods info_label = InfoLabel() @@ -598,7 +599,7 @@ class TestInfoLabel(TestCase): metrics = QtGui.QFontMetrics(font) with patch('openlp.core.ui.slidecontroller.QtGui.QLabel'), \ - patch('openlp.core.ui.slidecontroller.QtGui.QPainter') as mocked_qpainter: + patch('openlp.core.ui.slidecontroller.QtGui.QPainter') as mocked_qpainter: # GIVEN: An instance of InfoLabel, with mocked text return, width and rect methods info_label = InfoLabel() diff --git a/tests/functional/openlp_core_ui/test_themeform.py b/tests/functional/openlp_core_ui/test_themeform.py index 1a32edddb..11214e03a 100644 --- a/tests/functional/openlp_core_ui/test_themeform.py +++ b/tests/functional/openlp_core_ui/test_themeform.py @@ -48,13 +48,12 @@ class TestThemeManager(TestCase): # GIVEN: An instance of Theme Form and mocked QFileDialog which returns an empty string (similating a user # pressing cancel) with patch('openlp.core.ui.ThemeForm._setup'),\ - patch('openlp.core.ui.themeform.get_images_filter', - **{'return_value': 'Image Files (*.bmp; *.gif)(*.bmp *.gif)'}),\ - patch('openlp.core.ui.themeform.QtGui.QFileDialog.getOpenFileName', - **{'return_value': ''}) as mocked_get_open_file_name,\ - patch('openlp.core.ui.themeform.translate', **{'return_value': 'Translated String'}),\ - patch('openlp.core.ui.ThemeForm.set_background_page_values') as mocked_set_background_page_values: - + patch('openlp.core.ui.themeform.get_images_filter', + **{'return_value': 'Image Files (*.bmp; *.gif)(*.bmp *.gif)'}),\ + patch('openlp.core.ui.themeform.QtGui.QFileDialog.getOpenFileName', + **{'return_value': ''}) as mocked_get_open_file_name,\ + patch('openlp.core.ui.themeform.translate', **{'return_value': 'Translated String'}),\ + patch('openlp.core.ui.ThemeForm.set_background_page_values') as mocked_set_background_page_values: instance = ThemeForm(None) mocked_image_file_edit = MagicMock() mocked_image_file_edit.text.return_value = '/original_path/file.ext' @@ -66,8 +65,8 @@ class TestThemeManager(TestCase): # THEN: The QFileDialog getOpenFileName and set_background_page_values moethods should have been called # with known arguments mocked_get_open_file_name.assert_called_once_with(instance, 'Translated String', '/original_path/file.ext', - 'Image Files (*.bmp; *.gif)(*.bmp *.gif);;All Files (*.*)' - ) + 'Image Files (*.bmp; *.gif)(*.bmp *.gif);;' + 'All Files (*.*)') mocked_set_background_page_values.assert_called_once_with() def select_image_file_dialog_new_file_test(self): @@ -76,13 +75,12 @@ class TestThemeManager(TestCase): """ # GIVEN: An instance of Theme Form and mocked QFileDialog which returns a file path with patch('openlp.core.ui.ThemeForm._setup'),\ - patch('openlp.core.ui.themeform.get_images_filter', - **{'return_value': 'Image Files (*.bmp; *.gif)(*.bmp *.gif)'}),\ - patch('openlp.core.ui.themeform.QtGui.QFileDialog.getOpenFileName', - **{'return_value': '/new_path/file.ext'}) as mocked_get_open_file_name,\ - patch('openlp.core.ui.themeform.translate', **{'return_value': 'Translated String'}),\ - patch('openlp.core.ui.ThemeForm.set_background_page_values') as mocked_background_page_values: - + patch('openlp.core.ui.themeform.get_images_filter', + **{'return_value': 'Image Files (*.bmp; *.gif)(*.bmp *.gif)'}),\ + patch('openlp.core.ui.themeform.QtGui.QFileDialog.getOpenFileName', + **{'return_value': '/new_path/file.ext'}) as mocked_get_open_file_name,\ + patch('openlp.core.ui.themeform.translate', **{'return_value': 'Translated String'}),\ + patch('openlp.core.ui.ThemeForm.set_background_page_values') as mocked_background_page_values: instance = ThemeForm(None) mocked_image_file_edit = MagicMock() mocked_image_file_edit.text.return_value = '/original_path/file.ext' @@ -95,8 +93,8 @@ class TestThemeManager(TestCase): # THEN: The QFileDialog getOpenFileName and set_background_page_values moethods should have been called # with known arguments and theme.background_filename should be set mocked_get_open_file_name.assert_called_once_with(instance, 'Translated String', '/original_path/file.ext', - 'Image Files (*.bmp; *.gif)(*.bmp *.gif);;All Files (*.*)' - ) + 'Image Files (*.bmp; *.gif)(*.bmp *.gif);;' + 'All Files (*.*)') self.assertEqual(instance.theme.background_filename, '/new_path/file.ext', 'theme.background_filename should be set to the path that the file dialog returns') mocked_background_page_values.assert_called_once_with() diff --git a/tests/functional/openlp_core_utils/test_init.py b/tests/functional/openlp_core_utils/test_init.py index a64a9b25c..819dde6ef 100644 --- a/tests/functional/openlp_core_utils/test_init.py +++ b/tests/functional/openlp_core_utils/test_init.py @@ -83,7 +83,7 @@ class TestInitFunctions(TestMixin, TestCase): # THEN: The command 'libreoffice' should be called with the appropriate parameters self.assertEquals(result, 'libreoffice --nologo --norestore --minimized --nodefault --nofirststartwizard' - ' "--accept=pipe,name=openlp_pipe;urp;"') + ' "--accept=pipe,name=openlp_pipe;urp;"') def get_uno_command_only_soffice_command_exists_test(self): """ @@ -101,7 +101,7 @@ class TestInitFunctions(TestMixin, TestCase): # THEN: The command 'soffice' should be called with the appropriate parameters self.assertEquals(result, 'soffice --nologo --norestore --minimized --nodefault --nofirststartwizard' - ' "--accept=pipe,name=openlp_pipe;urp;"') + ' "--accept=pipe,name=openlp_pipe;urp;"') def get_uno_command_when_no_command_exists_test(self): """ diff --git a/tests/functional/openlp_plugins/custom/test_mediaitem.py b/tests/functional/openlp_plugins/custom/test_mediaitem.py index ef04dfb4e..67671695b 100644 --- a/tests/functional/openlp_plugins/custom/test_mediaitem.py +++ b/tests/functional/openlp_plugins/custom/test_mediaitem.py @@ -98,4 +98,4 @@ class TestMediaItem(TestCase, TestMixin): # THEN: the item should not be added to the database. self.assertEqual(self.media_item.create_from_service_item.call_count, 1, - 'The item should have been added to the database') \ No newline at end of file + 'The item should have been added to the database') From 76b47019b6251f6343f7b0a12d8a05b9af8baddc Mon Sep 17 00:00:00 2001 From: Tomas Groth Date: Fri, 16 Jan 2015 14:51:38 +0100 Subject: [PATCH 4/6] Mock out AudioPlayer to avoid loading Phonon during test. --- tests/functional/openlp_core_ui/test_maindisplay.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/functional/openlp_core_ui/test_maindisplay.py b/tests/functional/openlp_core_ui/test_maindisplay.py index 507b89f67..4a7328c45 100644 --- a/tests/functional/openlp_core_ui/test_maindisplay.py +++ b/tests/functional/openlp_core_ui/test_maindisplay.py @@ -39,7 +39,7 @@ from openlp.core.ui import MainDisplay from openlp.core.ui.maindisplay import TRANSPARENT_STYLESHEET, OPAQUE_STYLESHEET from tests.helpers.testmixin import TestMixin -from tests.functional import MagicMock +from tests.functional import MagicMock, patch SCREEN = { 'primary': False, @@ -64,11 +64,14 @@ class TestMainDisplay(TestCase, TestMixin): self.registry = Registry() self.setup_application() Registry().register('application', self.app) + self.mocked_audio_player = patch('openlp.core.ui.maindisplay.AudioPlayer') + self.mocked_audio_player.start() def tearDown(self): """ Delete QApplication. """ + self.mocked_audio_player.stop() del self.screens def initial_main_display_test(self): From 36e4b0c8eb77f780d0d9ffd03cc5429250aaaee2 Mon Sep 17 00:00:00 2001 From: Tomas Groth Date: Fri, 16 Jan 2015 16:25:25 +0100 Subject: [PATCH 5/6] Attempt to fix WorshipCenterProImport init under wine tests --- .../songs/lib/importers/worshipcenterpro.py | 2 +- .../songs/test_worshipcenterproimport.py | 22 ++++++++++++------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/openlp/plugins/songs/lib/importers/worshipcenterpro.py b/openlp/plugins/songs/lib/importers/worshipcenterpro.py index 17029acb8..5ecc89e46 100644 --- a/openlp/plugins/songs/lib/importers/worshipcenterpro.py +++ b/openlp/plugins/songs/lib/importers/worshipcenterpro.py @@ -49,7 +49,7 @@ class WorshipCenterProImport(SongImport): """ Initialise the WorshipCenter Pro importer. """ - SongImport.__init__(self, manager, **kwargs) + super(WorshipCenterProImport, self).__init__(manager, **kwargs) def do_import(self): """ diff --git a/tests/functional/openlp_plugins/songs/test_worshipcenterproimport.py b/tests/functional/openlp_plugins/songs/test_worshipcenterproimport.py index e1baa1218..7f248f1f8 100644 --- a/tests/functional/openlp_plugins/songs/test_worshipcenterproimport.py +++ b/tests/functional/openlp_plugins/songs/test_worshipcenterproimport.py @@ -36,10 +36,11 @@ if os.name != 'nt': raise SkipTest('Not Windows, skipping test') import pyodbc - -from openlp.plugins.songs.lib.importers.worshipcenterpro import WorshipCenterProImport from tests.functional import patch, MagicMock +from openlp.core.common import Registry +from openlp.plugins.songs.lib.importers.worshipcenterpro import WorshipCenterProImport + class TestRecord(object): """ @@ -61,7 +62,7 @@ class WorshipCenterProImportLogger(WorshipCenterProImport): _title_assignment_list = [] def __init__(self, manager): - WorshipCenterProImport.__init__(self, manager) + WorshipCenterProImport.__init__(self, manager, filenames=[]) @property def title(self): @@ -136,6 +137,12 @@ class TestWorshipCenterProSongImport(TestCase): """ Test the functions in the :mod:`worshipcenterproimport` module. """ + def setUp(self): + """ + Create the registry + """ + Registry.create() + def create_importer_test(self): """ Test creating an instance of the WorshipCenter Pro file importer @@ -145,7 +152,7 @@ class TestWorshipCenterProSongImport(TestCase): mocked_manager = MagicMock() # WHEN: An importer object is created - importer = WorshipCenterProImport(mocked_manager) + importer = WorshipCenterProImport(mocked_manager, filenames=[]) # THEN: The importer object should not be None self.assertIsNotNone(importer, 'Import should not be none') @@ -157,13 +164,12 @@ class TestWorshipCenterProSongImport(TestCase): # GIVEN: A mocked out SongImport class, a mocked out pyodbc module, a mocked out translate method, # a mocked "manager" and a mocked out log_error method. with patch('openlp.plugins.songs.lib.importers.worshipcenterpro.SongImport'), \ - patch('openlp.plugins.songs.lib.importers.worshipcenterpro.pyodbc.connect') \ - as mocked_pyodbc_connect, \ + patch('openlp.plugins.songs.lib.importers.worshipcenterpro.pyodbc.connect') as mocked_pyodbc_connect, \ patch('openlp.plugins.songs.lib.importers.worshipcenterpro.translate') as mocked_translate: mocked_manager = MagicMock() mocked_log_error = MagicMock() mocked_translate.return_value = 'Translated Text' - importer = WorshipCenterProImport(mocked_manager) + importer = WorshipCenterProImport(mocked_manager, filenames=[]) importer.log_error = mocked_log_error importer.import_source = 'import_source' pyodbc_errors = [pyodbc.DatabaseError, pyodbc.IntegrityError, pyodbc.InternalError, pyodbc.OperationalError] @@ -187,7 +193,7 @@ class TestWorshipCenterProSongImport(TestCase): # GIVEN: A mocked out SongImport class, a mocked out pyodbc module with a simulated recordset, a mocked out # translate method, a mocked "manager", add_verse method & mocked_finish method. with patch('openlp.plugins.songs.lib.importers.worshipcenterpro.SongImport'), \ - patch('openlp.plugins.songs.lib.importers.worshipcenterpro.pyodbc') as mocked_pyodbc, \ + patch('openlp.plugins.songs.lib.importers.worshipcenterpro.pyodbc') as mocked_pyodbc, \ patch('openlp.plugins.songs.lib.importers.worshipcenterpro.translate') as mocked_translate: mocked_manager = MagicMock() mocked_import_wizard = MagicMock() From 255b7d8495f2f42c46eea7e1207a0b12bffaca58 Mon Sep 17 00:00:00 2001 From: Tomas Groth Date: Fri, 16 Jan 2015 20:23:56 +0000 Subject: [PATCH 6/6] pep8 fix --- tests/functional/openlp_core_lib/test_renderer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/functional/openlp_core_lib/test_renderer.py b/tests/functional/openlp_core_lib/test_renderer.py index 32623c8fa..e08a6212a 100644 --- a/tests/functional/openlp_core_lib/test_renderer.py +++ b/tests/functional/openlp_core_lib/test_renderer.py @@ -155,7 +155,7 @@ class TestRenderer(TestCase): expected_words = ['
[---] '] service_item = ServiceItem(None) - # WHEN: Split the line based on word split rules + # WHEN: Split the line based on word split rules result_words = renderer.format_slide(given_line, service_item) # THEN: The blanks have been removed.