diff --git a/openlp/plugins/presentations/lib/libreofficeserver.py b/openlp/plugins/presentations/lib/libreofficeserver.py index 6bfa8435d..245a04f8e 100644 --- a/openlp/plugins/presentations/lib/libreofficeserver.py +++ b/openlp/plugins/presentations/lib/libreofficeserver.py @@ -128,7 +128,8 @@ class LibreOfficeServer(object): '--minimized', '--nodefault', '--nofirststartwizard', - '--accept=socket,host=localhost,port=2002;urp;StarOffice.ServiceManager' + '--accept=pipe,name=openlp_pipe;urp;' + # '--accept=socket,host=localhost,port=2002;urp;StarOffice.ServiceManager' ] self._process = Popen(uno_command) diff --git a/openlp/plugins/presentations/lib/maclocontroller.py b/openlp/plugins/presentations/lib/maclocontroller.py index b5d936efc..3adc1ead1 100644 --- a/openlp/plugins/presentations/lib/maclocontroller.py +++ b/openlp/plugins/presentations/lib/maclocontroller.py @@ -21,23 +21,26 @@ ############################################################################### import logging -import os -import time -from pathlib import Path from subprocess import Popen -from openlp.core.common import AppLocation, Registry, delete_file, is_macosx +from Pyro4 import Proxy -if is_macosx() and os.path.exists('/Applications/LibreOffice.app'): +from openlp.core.common import delete_file, is_macosx +from openlp.core.common.applocation import AppLocation +from openlp.core.common.path import Path +from openlp.core.common.registry import Registry + +LIBREOFFICE_PATH = Path('/Applications/LibreOffice.app') +LIBREOFFICE_PYTHON = LIBREOFFICE_PATH / 'Contents' / 'Resources' / 'python' + +if is_macosx() and LIBREOFFICE_PATH.exists(): macuno_available = True else: macuno_available = False -from PyQt5 import QtCore -from Pyro4 import Proxy -from openlp.core.lib import ScreenList -from .presentationcontroller import PresentationController, PresentationDocument, TextType +from openlp.core.display.screens import ScreenList +from .presentationcontroller import PresentationController, PresentationDocument log = logging.getLogger(__name__) diff --git a/tests/functional/openlp_core/common/test_path.py b/tests/functional/openlp_core/common/test_path.py index 8581d9b49..7341ede38 100644 --- a/tests/functional/openlp_core/common/test_path.py +++ b/tests/functional/openlp_core/common/test_path.py @@ -245,7 +245,18 @@ class TestPath(TestCase): # WHEN: Calling `path_to_str` with an invalid Type # THEN: A TypeError should have been raised with self.assertRaises(TypeError): - path_to_str(str()) + path_to_str(57) + + def test_path_to_str_wth_str(self): + """ + Test that `path_to_str` just returns a str when given a str + """ + # GIVEN: The `path_to_str` function + # WHEN: Calling `path_to_str` with a str + result = path_to_str('/usr/bin') + + # THEN: The string should be returned + assert result == '/usr/bin' def test_path_to_str_none(self): """ @@ -397,7 +408,7 @@ class TestPath(TestCase): try: create_paths(mocked_path) assert False, 'create_paths should have thrown an exception' - except: + except Exception: # THEN: `create_paths` raises an exception pass diff --git a/tests/functional/openlp_plugins/presentations/test_libreofficeserver.py b/tests/functional/openlp_plugins/presentations/test_libreofficeserver.py index d350ee9e1..cb98705f4 100644 --- a/tests/functional/openlp_plugins/presentations/test_libreofficeserver.py +++ b/tests/functional/openlp_plugins/presentations/test_libreofficeserver.py @@ -22,9 +22,9 @@ """ Functional tests to test the LibreOffice Pyro server """ -from openlp.plugins.presentations.lib.libreofficeserver import LibreOfficeServer, TextType, main +from unittest.mock import MagicMock, patch, call -from tests.functional import MagicMock, patch, call +from openlp.plugins.presentations.lib.libreofficeserver import LibreOfficeServer, TextType, main def test_constructor(): @@ -37,7 +37,7 @@ def test_constructor(): # THEN: The server should have been set up correctly assert server._control is None - assert server._desktop is None + # assert server._desktop is None assert server._document is None assert server._presentation is None assert server._process is None @@ -96,7 +96,6 @@ def test_setup_desktop_exception(mocked_uno): mocked_resolver = MagicMock() mocked_uno_instance = MagicMock() MockedServiceManager = MagicMock() - mocked_desktop = MagicMock() mocked_uno.getComponentContext.return_value = mocked_context mocked_context.ServiceManager.createInstanceWithContext.return_value = mocked_resolver mocked_resolver.resolve.side_effect = [Exception, mocked_uno_instance] @@ -437,7 +436,6 @@ def test_extract_thumbnails_no_pages(mocked_uno): temp_folder = '/tmp' server = LibreOfficeServer() mocked_document = MagicMock() - mocked_pages = MagicMock() server._document = mocked_document mocked_uno.systemPathToFileUrl.side_effect = lambda x: x mocked_document.getDrawPages.return_value = None @@ -861,7 +859,7 @@ def test_goto_slide(): server._control = mocked_control # WHEN: goto_slide() is called - result = server.goto_slide(1) + server.goto_slide(1) # THEN: The slide number should be correct mocked_control.gotoSlideIndex.assert_called_once_with(0) @@ -879,7 +877,7 @@ def test_next_step_when_paused(mocked_sleep): mocked_control.isPaused.side_effect = [False, True] # WHEN: next_step() is called - result = server.next_step() + server.next_step() # THEN: The correct call should be made mocked_control.gotoNextEffect.assert_called_once_with() @@ -900,7 +898,7 @@ def test_next_step(mocked_sleep): mocked_control.isPaused.side_effect = [True, True] # WHEN: next_step() is called - result = server.next_step() + server.next_step() # THEN: The correct call should be made mocked_control.gotoNextEffect.assert_called_once_with() @@ -919,7 +917,7 @@ def test_previous_step(): server._control = mocked_control # WHEN: previous_step() is called - result = server.previous_step() + server.previous_step() # THEN: The correct call should be made mocked_control.gotoPreviousEffect.assert_called_once_with() diff --git a/tests/functional/openlp_plugins/presentations/test_maclocontroller.py b/tests/functional/openlp_plugins/presentations/test_maclocontroller.py index 11a74ce0f..e295dfd86 100644 --- a/tests/functional/openlp_plugins/presentations/test_maclocontroller.py +++ b/tests/functional/openlp_plugins/presentations/test_maclocontroller.py @@ -22,19 +22,18 @@ """ Functional tests to test the Mac LibreOffice class and related methods. """ -from unittest import TestCase -import os import shutil from tempfile import mkdtemp +from unittest import TestCase +from unittest.mock import MagicMock, patch, call -from openlp.core.common import Settings -from openlp.plugins.presentations.lib.maclocontroller import \ - MacLOController, MacLODocument, TextType +from openlp.core.common.settings import Settings +from openlp.core.common.path import Path +from openlp.plugins.presentations.lib.maclocontroller import MacLOController, MacLODocument from openlp.plugins.presentations.presentationplugin import __default_settings__ -from tests.functional import MagicMock, patch, call -from tests.utils.constants import TEST_RESOURCES_PATH from tests.helpers.testmixin import TestMixin +from tests.utils.constants import TEST_RESOURCES_PATH class TestMacLOController(TestCase, TestMixin): @@ -59,21 +58,13 @@ class TestMacLOController(TestCase, TestMixin): self.destroy_settings() shutil.rmtree(self.temp_folder) - @patch('openlp.plugins.presentations.lib.maclocontroller.AppLocation.get_directory') - @patch('openlp.plugins.presentations.lib.maclocontroller.os') - @patch('openlp.plugins.presentations.lib.maclocontroller.Popen') - def test_constructor(self, MockedPopen, mocked_os, mocked_get_directory): + @patch('openlp.plugins.presentations.lib.maclocontroller.MacLOController._start_server') + def test_constructor(self, mocked_start_server): """ Test the Constructor from the MacLOController """ # GIVEN: No presentation controller controller = None - mocked_process = MagicMock() - mocked_get_directory.return_value = 'plugins' - mocked_os.path.join.side_effect = lambda *x: '/'.join(x) - mocked_os.path.dirname.return_value = '' - mocked_os.path.exists.return_value = True - MockedPopen.return_value = mocked_process # WHEN: The presentation controller object is created controller = MacLOController(plugin=self.mock_plugin) @@ -83,9 +74,7 @@ class TestMacLOController(TestCase, TestMixin): 'The name of the presentation controller should be correct' assert controller.display_name == 'Impress on macOS', \ 'The display name of the presentation controller should be correct' - MockedPopen.assert_called_once_with(['/Applications/LibreOffice.app/Contents/Resources/python', - 'plugins/presentations/lib/libreofficeserver.py']) - assert controller.server_process == mocked_process + mocked_start_server.assert_called_once_with() @patch('openlp.plugins.presentations.lib.maclocontroller.MacLOController._start_server') @patch('openlp.plugins.presentations.lib.maclocontroller.Proxy') @@ -164,7 +153,7 @@ class TestMacLODocument(TestCase): mocked_plugin = MagicMock() mocked_plugin.settings_section = 'presentations' Settings().extend_default_settings(__default_settings__) - self.file_name = os.path.join(TEST_RESOURCES_PATH, 'presentations', 'test.odp') + self.file_name = Path(TEST_RESOURCES_PATH) / 'presentations' / 'test.odp' self.mocked_client = MagicMock() with patch('openlp.plugins.presentations.lib.maclocontroller.MacLOController._start_server'): self.controller = MacLOController(mocked_plugin)