From 06339426d252b811c932a8ee03ebdb2023ce9fa8 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Sun, 3 Nov 2019 20:46:21 +0000 Subject: [PATCH] Fix presentations on Linux (and hopefully Windows too) --- .../presentations/lib/impresscontroller.py | 8 ++-- .../plugins/songs/lib/importers/openoffice.py | 2 +- .../presentations/test_impresscontroller.py | 44 +++++++++++++++++-- 3 files changed, 46 insertions(+), 8 deletions(-) diff --git a/openlp/plugins/presentations/lib/impresscontroller.py b/openlp/plugins/presentations/lib/impresscontroller.py index 6170fd78e..7e53d310a 100644 --- a/openlp/plugins/presentations/lib/impresscontroller.py +++ b/openlp/plugins/presentations/lib/impresscontroller.py @@ -152,7 +152,7 @@ class ImpressController(PresentationController): self.toggle_presentation_screen(False) return desktop except Exception: - log.warning('Failed to get UNO desktop') + log.exception('Failed to get UNO desktop') return None def get_com_desktop(self): @@ -232,7 +232,7 @@ class ImpressController(PresentationController): self.conf_provider = self.manager.createInstanceWithContext( 'com.sun.star.configuration.ConfigurationProvider', uno.getComponentContext()) # Setup lookup properties to get Impress settings - properties = tuple(self.create_property('nodepath', 'org.openoffice.Office.Impress')) + properties = (self.create_property('nodepath', 'org.openoffice.Office.Impress'),) try: # Get an updateable configuration view impress_conf_props = self.conf_provider.createInstanceWithArguments( @@ -308,7 +308,7 @@ class ImpressDocument(PresentationDocument): if desktop is None: return False self.desktop = desktop - properties = tuple(self.controller.create_property('Hidden', True)) + properties = (self.controller.create_property('Hidden', True),) try: self.document = desktop.loadComponentFromURL(url, '_blank', 0, properties) except Exception: @@ -333,7 +333,7 @@ class ImpressDocument(PresentationDocument): return temp_folder_path = self.get_temp_folder() thumb_dir_url = temp_folder_path.as_uri() - properties = tuple(self.controller.create_property('FilterName', 'impress_png_Export')) + properties = (self.controller.create_property('FilterName', 'impress_png_Export'),) doc = self.document pages = doc.getDrawPages() if not pages: diff --git a/openlp/plugins/songs/lib/importers/openoffice.py b/openlp/plugins/songs/lib/importers/openoffice.py index 7a831c02b..79c09a8db 100644 --- a/openlp/plugins/songs/lib/importers/openoffice.py +++ b/openlp/plugins/songs/lib/importers/openoffice.py @@ -144,7 +144,7 @@ class OpenOfficeImport(SongImport): """ self.file_path = file_path url = file_path.as_uri() - properties = tuple(self.create_property('Hidden', True)) + properties = (self.create_property('Hidden', True),) try: self.document = self.desktop.loadComponentFromURL(url, '_blank', 0, properties) if not self.document.supportsService("com.sun.star.presentation.PresentationDocument") and not \ diff --git a/tests/functional/openlp_plugins/presentations/test_impresscontroller.py b/tests/functional/openlp_plugins/presentations/test_impresscontroller.py index 69fa9eddc..40ca51afe 100644 --- a/tests/functional/openlp_plugins/presentations/test_impresscontroller.py +++ b/tests/functional/openlp_plugins/presentations/test_impresscontroller.py @@ -24,7 +24,7 @@ Functional tests to test the Impress class and related methods. import shutil from tempfile import mkdtemp from unittest import TestCase -from unittest.mock import MagicMock, patch +from unittest.mock import MagicMock, call, patch from openlp.core.common.settings import Settings from openlp.plugins.presentations.lib.impresscontroller import ImpressController, ImpressDocument, TextType @@ -86,7 +86,7 @@ class TestImpressController(TestCase, TestMixin): assert result is False @patch('openlp.plugins.presentations.lib.impresscontroller.log') - def test_check_available1(self, mocked_log): + def test_check_available_on_windows(self, mocked_log): """ Test `ImpressController.check_available` on Windows """ @@ -106,7 +106,7 @@ class TestImpressController(TestCase, TestMixin): @patch('openlp.plugins.presentations.lib.impresscontroller.log') @patch('openlp.plugins.presentations.lib.impresscontroller.is_win', return_value=False) - def test_check_available2(self, mocked_is_win, mocked_log): + def test_check_available_on_linux(self, mocked_is_win, mocked_log): """ Test `ImpressController.check_available` when not on Windows """ @@ -122,6 +122,44 @@ class TestImpressController(TestCase, TestMixin): assert mocked_get_com_servicemanager.called is False assert result is True + @patch('openlp.plugins.presentations.lib.impresscontroller.is_win', return_value=True) + def test_start_process_on_windows(self, mocked_is_win): + """ + Test that start_process() on Windows starts the process + """ + # GIVEN: An ImpressController object + controller = ImpressController(plugin=self.mock_plugin) + controller.get_com_servicemanager = MagicMock(return_value=MagicMock()) + + # WHEN: start_process() is called + controller.start_process() + + # THEN: The correct methods should have been called + controller.get_com_servicemanager.assert_called_once() + assert controller.manager._FlagAsMethod.call_args_list == [call('Bridge_GetStruct'), + call('Bridge_GetValueObject')] + + @patch('openlp.plugins.presentations.lib.impresscontroller.is_win', return_value=False) + @patch('openlp.plugins.presentations.lib.impresscontroller.get_uno_command', return_value='libreoffice') + @patch('openlp.plugins.presentations.lib.impresscontroller.QtCore.QProcess') + def test_start_process_on_linux(self, MockQProcess, mocked_get_uno_command, mocked_is_win): + """ + Test that start_process() on Linux starts the process + """ + # GIVEN: An ImpressController object + mocked_process = MagicMock() + MockQProcess.return_value = mocked_process + controller = ImpressController(plugin=self.mock_plugin) + + # WHEN: start_process() is called + controller.start_process() + + # THEN: The correct methods should have been called + mocked_get_uno_command.assert_called_once() + MockQProcess.assert_called_once() + assert controller.process is mocked_process + mocked_process.startDetached.assert_called_once_with('libreoffice') + class TestImpressDocument(TestCase): """