This commit is contained in:
Raoul Snyman 2019-05-17 21:56:15 -07:00
commit 8029a8b767
9 changed files with 74 additions and 86 deletions

View File

@ -1,59 +1,48 @@
*.*~ *.*~
*.~\?~
\#*\#
build
.cache
cover
.coverage
coverage
.directory
.vscode
dist
*.dll *.dll
documentation/build/doctrees
documentation/build/html
*.e4* *.e4*
*eric[1-9]project
.git
env
# Git files
.gitignore
htmlcov
.idea
*.kate-swp *.kate-swp
*.kdev4 *.kdev4
.kdev4
*.komodoproject *.komodoproject
.komodotools
list
*.log* *.log*
*.nja *.nja
openlp.cfg
openlp/core/resources.py.old
OpenLP.egg-info
openlp.org 2.0.e4*
openlp.pro
openlp-test-projectordb.sqlite
*.orig *.orig
output
*.pyc *.pyc
__pycache__
.pylint.d
.pytest_cache
*.qm *.qm
*.rej *.rej
# Rejected diff's
resources/innosetup/Output
resources/windows/warnOpenLP.txt
*.ropeproject *.ropeproject
tags *.~\?~
*eric[1-9]project
.cache
.coverage
.directory
.git
.gitignore
.idea
.kdev4
.komodotools
.pylint.d
.pytest_cache
.vscode
OpenLP.egg-info
\#*\#
__pycache__
build
cover
coverage
dist
env
htmlcov
list
node_modules
openlp-test-projectordb.sqlite
openlp.cfg
openlp.pro
openlp/core/resources.py.old
openlp/plugins/presentations/lib/vendor/Pyro4 openlp/plugins/presentations/lib/vendor/Pyro4
openlp/plugins/presentations/lib/vendor/serpent.py openlp/plugins/presentations/lib/vendor/serpent.py
output output
htmlcov
node_modules
openlp-test-projectordb.sqlite
package-lock.json package-lock.json
.cache tags
test test
tests.kdev4 tests.kdev4

View File

@ -78,7 +78,7 @@ class Path(PathVariant):
:param onerror: Handler function to handle any errors :param onerror: Handler function to handle any errors
:rtype: None :rtype: None
""" """
shutil.rmtree(self, ignore_errors, onerror) shutil.rmtree(str(self), ignore_errors, onerror)
def replace_params(args, kwargs, params): def replace_params(args, kwargs, params):
@ -187,6 +187,8 @@ def path_to_str(path=None):
:return: An empty string if :param:`path` is None, else a string representation of the :param:`path` :return: An empty string if :param:`path` is None, else a string representation of the :param:`path`
:rtype: str :rtype: str
""" """
if isinstance(path, str):
return path
if not isinstance(path, Path) and path is not None: if not isinstance(path, Path) and path is not None:
raise TypeError('parameter \'path\' must be of type Path or NoneType') raise TypeError('parameter \'path\' must be of type Path or NoneType')
if path is None: if path is None:

View File

@ -37,7 +37,6 @@ if sys.platform.startswith('darwin'):
# Add the vendor directory to sys.path so that we can load Pyro4 # Add the vendor directory to sys.path so that we can load Pyro4
sys.path.append(os.path.join(os.path.dirname(__file__)))
sys.path.append(os.path.join(os.path.dirname(__file__), 'vendor')) sys.path.append(os.path.join(os.path.dirname(__file__), 'vendor'))
from serializers import register_classes from serializers import register_classes
@ -48,13 +47,13 @@ try:
import uno import uno
from com.sun.star.beans import PropertyValue from com.sun.star.beans import PropertyValue
from com.sun.star.task import ErrorCodeIOException from com.sun.star.task import ErrorCodeIOException
except ImportError as e: except ImportError:
# But they need to be defined for mocking # But they need to be defined for mocking
print(e)
uno = None uno = None
PropertyValue = None PropertyValue = None
ErrorCodeIOException = Exception ErrorCodeIOException = Exception
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
register_classes() register_classes()
@ -201,8 +200,9 @@ class LibreOfficeServer(object):
""" """
Load a presentation Load a presentation
""" """
self._file_path = file_path
url = uno.systemPathToFileUrl(file_path) url = uno.systemPathToFileUrl(file_path)
properties = [self._create_property('Hidden', True)] properties = (self._create_property('Hidden', True),)
self._document = None self._document = None
loop_count = 0 loop_count = 0
while loop_count < 3: while loop_count < 3:

View File

@ -21,12 +21,11 @@
############################################################################### ###############################################################################
import logging import logging
import os
from subprocess import Popen from subprocess import Popen
from Pyro4 import Proxy from Pyro4 import Proxy
from openlp.core.common import is_macosx, delete_file from openlp.core.common import delete_file, is_macosx
from openlp.core.common.applocation import AppLocation from openlp.core.common.applocation import AppLocation
from openlp.core.common.path import Path from openlp.core.common.path import Path
from openlp.core.common.registry import Registry from openlp.core.common.registry import Registry
@ -34,7 +33,11 @@ from openlp.core.display.screens import ScreenList
from openlp.plugins.presentations.lib.serializers import register_classes from openlp.plugins.presentations.lib.serializers import register_classes
from openlp.plugins.presentations.lib.presentationcontroller import PresentationController, PresentationDocument from openlp.plugins.presentations.lib.presentationcontroller import PresentationController, PresentationDocument
if is_macosx() and os.path.exists('/Applications/LibreOffice.app'):
LIBREOFFICE_PATH = Path('/Applications/LibreOffice.app')
LIBREOFFICE_PYTHON = LIBREOFFICE_PATH / 'Contents' / 'Resources' / 'python'
if is_macosx() and LIBREOFFICE_PATH.exists():
macuno_available = True macuno_available = True
else: else:
macuno_available = False macuno_available = False

View File

@ -28,13 +28,13 @@ import os
from PyQt5 import QtCore from PyQt5 import QtCore
from openlp.core.state import State
from openlp.core.api.http import register_endpoint from openlp.core.api.http import register_endpoint
from openlp.core.common import extension_loader from openlp.core.common import extension_loader
from openlp.core.common.i18n import translate from openlp.core.common.i18n import translate
from openlp.core.common.settings import Settings from openlp.core.common.settings import Settings
from openlp.core.lib import build_icon from openlp.core.lib import build_icon
from openlp.core.lib.plugin import Plugin, StringContent from openlp.core.lib.plugin import Plugin, StringContent
from openlp.core.state import State
from openlp.core.ui.icons import UiIcons from openlp.core.ui.icons import UiIcons
from openlp.plugins.presentations.endpoint import api_presentations_endpoint, presentations_endpoint from openlp.plugins.presentations.endpoint import api_presentations_endpoint, presentations_endpoint
from openlp.plugins.presentations.lib.presentationcontroller import PresentationController from openlp.plugins.presentations.lib.presentationcontroller import PresentationController

View File

@ -42,12 +42,8 @@ def set_up_fault_handling():
""" """
Set up the Python fault handler Set up the Python fault handler
""" """
# Create the cache directory if it doesn't exist, and enable the fault handler to log to an error log file create_paths(AppLocation.get_directory(AppLocation.CacheDir))
try: faulthandler.enable((AppLocation.get_directory(AppLocation.CacheDir) / 'error.log').open('wb'))
create_paths(AppLocation.get_directory(AppLocation.CacheDir))
faulthandler.enable((AppLocation.get_directory(AppLocation.CacheDir) / 'error.log').open('wb'))
except OSError:
log.exception('An exception occurred when enabling the fault handler')
def start(): def start():

View File

@ -243,7 +243,18 @@ class TestPath(TestCase):
# WHEN: Calling `path_to_str` with an invalid Type # WHEN: Calling `path_to_str` with an invalid Type
# THEN: A TypeError should have been raised # THEN: A TypeError should have been raised
with self.assertRaises(TypeError): 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): def test_path_to_str_none(self):
""" """

View File

@ -22,9 +22,9 @@
""" """
Functional tests to test the LibreOffice Pyro server 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(): def test_constructor():
@ -37,7 +37,7 @@ def test_constructor():
# THEN: The server should have been set up correctly # THEN: The server should have been set up correctly
assert server._control is None assert server._control is None
assert server._desktop is None # assert server._desktop is None
assert server._document is None assert server._document is None
assert server._presentation is None assert server._presentation is None
assert server._process is None assert server._process is None
@ -96,7 +96,6 @@ def test_setup_desktop_exception(mocked_uno):
mocked_resolver = MagicMock() mocked_resolver = MagicMock()
mocked_uno_instance = MagicMock() mocked_uno_instance = MagicMock()
MockedServiceManager = MagicMock() MockedServiceManager = MagicMock()
mocked_desktop = MagicMock()
mocked_uno.getComponentContext.return_value = mocked_context mocked_uno.getComponentContext.return_value = mocked_context
mocked_context.ServiceManager.createInstanceWithContext.return_value = mocked_resolver mocked_context.ServiceManager.createInstanceWithContext.return_value = mocked_resolver
mocked_resolver.resolve.side_effect = [Exception, mocked_uno_instance] mocked_resolver.resolve.side_effect = [Exception, mocked_uno_instance]
@ -437,7 +436,6 @@ def test_extract_thumbnails_no_pages(mocked_uno):
temp_folder = '/tmp' temp_folder = '/tmp'
server = LibreOfficeServer() server = LibreOfficeServer()
mocked_document = MagicMock() mocked_document = MagicMock()
mocked_pages = MagicMock()
server._document = mocked_document server._document = mocked_document
mocked_uno.systemPathToFileUrl.side_effect = lambda x: x mocked_uno.systemPathToFileUrl.side_effect = lambda x: x
mocked_document.getDrawPages.return_value = None mocked_document.getDrawPages.return_value = None
@ -861,7 +859,7 @@ def test_goto_slide():
server._control = mocked_control server._control = mocked_control
# WHEN: goto_slide() is called # WHEN: goto_slide() is called
result = server.goto_slide(1) server.goto_slide(1)
# THEN: The slide number should be correct # THEN: The slide number should be correct
mocked_control.gotoSlideIndex.assert_called_once_with(0) 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] mocked_control.isPaused.side_effect = [False, True]
# WHEN: next_step() is called # WHEN: next_step() is called
result = server.next_step() server.next_step()
# THEN: The correct call should be made # THEN: The correct call should be made
mocked_control.gotoNextEffect.assert_called_once_with() mocked_control.gotoNextEffect.assert_called_once_with()
@ -900,7 +898,7 @@ def test_next_step(mocked_sleep):
mocked_control.isPaused.side_effect = [True, True] mocked_control.isPaused.side_effect = [True, True]
# WHEN: next_step() is called # WHEN: next_step() is called
result = server.next_step() server.next_step()
# THEN: The correct call should be made # THEN: The correct call should be made
mocked_control.gotoNextEffect.assert_called_once_with() mocked_control.gotoNextEffect.assert_called_once_with()
@ -919,7 +917,7 @@ def test_previous_step():
server._control = mocked_control server._control = mocked_control
# WHEN: previous_step() is called # WHEN: previous_step() is called
result = server.previous_step() server.previous_step()
# THEN: The correct call should be made # THEN: The correct call should be made
mocked_control.gotoPreviousEffect.assert_called_once_with() mocked_control.gotoPreviousEffect.assert_called_once_with()

View File

@ -22,19 +22,18 @@
""" """
Functional tests to test the Mac LibreOffice class and related methods. Functional tests to test the Mac LibreOffice class and related methods.
""" """
from unittest import TestCase
import os
import shutil import shutil
from tempfile import mkdtemp from tempfile import mkdtemp
from unittest import TestCase
from unittest.mock import MagicMock, patch, call
from openlp.core.common import Settings from openlp.core.common.settings import Settings
from openlp.plugins.presentations.lib.maclocontroller import \ from openlp.core.common.path import Path
MacLOController, MacLODocument, TextType from openlp.plugins.presentations.lib.maclocontroller import MacLOController, MacLODocument
from openlp.plugins.presentations.presentationplugin import __default_settings__ 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.helpers.testmixin import TestMixin
from tests.utils.constants import TEST_RESOURCES_PATH
class TestMacLOController(TestCase, TestMixin): class TestMacLOController(TestCase, TestMixin):
@ -59,21 +58,13 @@ class TestMacLOController(TestCase, TestMixin):
self.destroy_settings() self.destroy_settings()
shutil.rmtree(self.temp_folder) shutil.rmtree(self.temp_folder)
@patch('openlp.plugins.presentations.lib.maclocontroller.AppLocation.get_directory') @patch('openlp.plugins.presentations.lib.maclocontroller.MacLOController._start_server')
@patch('openlp.plugins.presentations.lib.maclocontroller.os') def test_constructor(self, mocked_start_server):
@patch('openlp.plugins.presentations.lib.maclocontroller.Popen')
def test_constructor(self, MockedPopen, mocked_os, mocked_get_directory):
""" """
Test the Constructor from the MacLOController Test the Constructor from the MacLOController
""" """
# GIVEN: No presentation controller # GIVEN: No presentation controller
controller = None 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 # WHEN: The presentation controller object is created
controller = MacLOController(plugin=self.mock_plugin) controller = MacLOController(plugin=self.mock_plugin)
@ -83,9 +74,7 @@ class TestMacLOController(TestCase, TestMixin):
'The name of the presentation controller should be correct' 'The name of the presentation controller should be correct'
assert controller.display_name == 'Impress on macOS', \ assert controller.display_name == 'Impress on macOS', \
'The display name of the presentation controller should be correct' 'The display name of the presentation controller should be correct'
MockedPopen.assert_called_once_with(['/Applications/LibreOffice.app/Contents/Resources/python', mocked_start_server.assert_called_once_with()
'plugins/presentations/lib/libreofficeserver.py'])
assert controller.server_process == mocked_process
@patch('openlp.plugins.presentations.lib.maclocontroller.MacLOController._start_server') @patch('openlp.plugins.presentations.lib.maclocontroller.MacLOController._start_server')
@patch('openlp.plugins.presentations.lib.maclocontroller.Proxy') @patch('openlp.plugins.presentations.lib.maclocontroller.Proxy')
@ -164,7 +153,7 @@ class TestMacLODocument(TestCase):
mocked_plugin = MagicMock() mocked_plugin = MagicMock()
mocked_plugin.settings_section = 'presentations' mocked_plugin.settings_section = 'presentations'
Settings().extend_default_settings(__default_settings__) 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() self.mocked_client = MagicMock()
with patch('openlp.plugins.presentations.lib.maclocontroller.MacLOController._start_server'): with patch('openlp.plugins.presentations.lib.maclocontroller.MacLOController._start_server'):
self.controller = MacLOController(mocked_plugin) self.controller = MacLOController(mocked_plugin)