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
documentation/build/doctrees
documentation/build/html
*.e4*
*eric[1-9]project
.git
env
# Git files
.gitignore
htmlcov
.idea
*.kate-swp
*.kdev4
.kdev4
*.komodoproject
.komodotools
list
*.log*
*.nja
openlp.cfg
openlp/core/resources.py.old
OpenLP.egg-info
openlp.org 2.0.e4*
openlp.pro
openlp-test-projectordb.sqlite
*.orig
output
*.pyc
__pycache__
.pylint.d
.pytest_cache
*.qm
*.rej
# Rejected diff's
resources/innosetup/Output
resources/windows/warnOpenLP.txt
*.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/serpent.py
output
htmlcov
node_modules
openlp-test-projectordb.sqlite
package-lock.json
.cache
tags
test
tests.kdev4

View File

@ -78,7 +78,7 @@ class Path(PathVariant):
:param onerror: Handler function to handle any errors
:rtype: None
"""
shutil.rmtree(self, ignore_errors, onerror)
shutil.rmtree(str(self), ignore_errors, onerror)
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`
:rtype: str
"""
if isinstance(path, str):
return path
if not isinstance(path, Path) and path is not None:
raise TypeError('parameter \'path\' must be of type Path or NoneType')
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
sys.path.append(os.path.join(os.path.dirname(__file__)))
sys.path.append(os.path.join(os.path.dirname(__file__), 'vendor'))
from serializers import register_classes
@ -48,13 +47,13 @@ try:
import uno
from com.sun.star.beans import PropertyValue
from com.sun.star.task import ErrorCodeIOException
except ImportError as e:
except ImportError:
# But they need to be defined for mocking
print(e)
uno = None
PropertyValue = None
ErrorCodeIOException = Exception
log = logging.getLogger(__name__)
register_classes()
@ -201,8 +200,9 @@ class LibreOfficeServer(object):
"""
Load a presentation
"""
self._file_path = file_path
url = uno.systemPathToFileUrl(file_path)
properties = [self._create_property('Hidden', True)]
properties = (self._create_property('Hidden', True),)
self._document = None
loop_count = 0
while loop_count < 3:

View File

@ -21,12 +21,11 @@
###############################################################################
import logging
import os
from subprocess import Popen
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.path import Path
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.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
else:
macuno_available = False

View File

@ -28,13 +28,13 @@ import os
from PyQt5 import QtCore
from openlp.core.state import State
from openlp.core.api.http import register_endpoint
from openlp.core.common import extension_loader
from openlp.core.common.i18n import translate
from openlp.core.common.settings import Settings
from openlp.core.lib import build_icon
from openlp.core.lib.plugin import Plugin, StringContent
from openlp.core.state import State
from openlp.core.ui.icons import UiIcons
from openlp.plugins.presentations.endpoint import api_presentations_endpoint, presentations_endpoint
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
"""
# Create the cache directory if it doesn't exist, and enable the fault handler to log to an error log file
try:
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')
create_paths(AppLocation.get_directory(AppLocation.CacheDir))
faulthandler.enable((AppLocation.get_directory(AppLocation.CacheDir) / 'error.log').open('wb'))
def start():

View File

@ -243,7 +243,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):
"""

View File

@ -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()

View File

@ -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)