From 28222ed0f87b83b2893f4d5614102c9c6d1dc1b1 Mon Sep 17 00:00:00 2001 From: Phill Ridout Date: Sun, 25 Jan 2015 22:00:14 +0000 Subject: [PATCH 1/7] fix check_available to work on feature detection --- openlp/core/ui/media/webkitplayer.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/openlp/core/ui/media/webkitplayer.py b/openlp/core/ui/media/webkitplayer.py index 9673240a6..d33aec7c0 100644 --- a/openlp/core/ui/media/webkitplayer.py +++ b/openlp/core/ui/media/webkitplayer.py @@ -22,11 +22,11 @@ """ The :mod:`~openlp.core.ui.media.webkit` module contains our WebKit video player """ -from PyQt4 import QtGui +from PyQt4 import QtGui, QtWebKit import logging -from openlp.core.common import Settings, is_macosx +from openlp.core.common import Settings from openlp.core.lib import translate from openlp.core.ui.media import MediaState from openlp.core.ui.media.mediaplayer import MediaPlayer @@ -224,11 +224,9 @@ class WebkitPlayer(MediaPlayer): """ Check the availability of the media player """ - # At the moment we don't have support for webkitplayer on Mac OS X - if is_macosx(): - return False - else: - return True + web = QtWebKit.QWebPage() + return web.mainFrame().evaluateJavaScript( + "Object.prototype.toString.call(document.createElement('video'));") == '[object HTMLVideoElement]' def load(self, display): """ From 34f8cbc09b56eb1eb8e8d6c08cbd491814890dbc Mon Sep 17 00:00:00 2001 From: Phill Ridout Date: Sun, 25 Jan 2015 22:12:33 +0000 Subject: [PATCH 2/7] Typos & tests --- tests/functional/test_init.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/tests/functional/test_init.py b/tests/functional/test_init.py index a5ec608ef..b681ef4b8 100644 --- a/tests/functional/test_init.py +++ b/tests/functional/test_init.py @@ -24,6 +24,7 @@ Package to test the openlp.core.__init__ package. """ from optparse import Values import os +import sys from unittest import TestCase from unittest.mock import MagicMock, patch @@ -122,8 +123,23 @@ class TestInit(TestCase, TestMixin): options = ['-e', '-l', 'debug', '-pd', '-s', 'style', 'extra', 'qt', 'args'] # WHEN: Calling parse_options - resluts = parse_options(options) + results = parse_options(options) # THEN: A tuple should be returned with the parsed options and left over args - self.assertEqual(resluts, (Values({'no_error_form': True, 'dev_version': True, 'portable': True, + self.assertEqual(results, (Values({'no_error_form': True, 'dev_version': True, 'portable': True, + 'style': 'style', 'loglevel': 'debug'}), ['extra', 'qt', 'args'])) + + def parse_options_valid_argv_short_options_test(self): + """ + Test that parse_options parses valid short options correctly when passed through sys.argv + """ + # GIVEN: A list of valid options + options = ['-e', '-l', 'debug', '-pd', '-s', 'style', 'extra', 'qt', 'args'] + + # WHEN: Passing in the options through sys.argv and calling parse_args with None + with patch.object(sys, 'argv', options): + results = parse_options(None) + + # THEN: parse_args should return a tuple of valid options and of left over options that OpenLP does not use + self.assertEqual(results, (Values({'no_error_form': True, 'dev_version': True, 'portable': True, 'style': 'style', 'loglevel': 'debug'}), ['extra', 'qt', 'args'])) From 3dc248e556a14e36e884db75665262acd72d8066 Mon Sep 17 00:00:00 2001 From: Phill Ridout Date: Sun, 25 Jan 2015 22:13:35 +0000 Subject: [PATCH 3/7] Typo --- tests/functional/test_init.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/functional/test_init.py b/tests/functional/test_init.py index b681ef4b8..d1f399c62 100644 --- a/tests/functional/test_init.py +++ b/tests/functional/test_init.py @@ -119,7 +119,7 @@ class TestInit(TestCase, TestMixin): """ Test that parse_options parses short options correctly """ - # GIVEN: A list of vaild short options + # GIVEN: A list of valid short options options = ['-e', '-l', 'debug', '-pd', '-s', 'style', 'extra', 'qt', 'args'] # WHEN: Calling parse_options From 1712464e8c828403b32821fca2a1f42793fb78dd Mon Sep 17 00:00:00 2001 From: Phill Ridout Date: Mon, 26 Jan 2015 20:42:19 +0000 Subject: [PATCH 4/7] Fix up tests --- openlp/core/ui/media/webkitplayer.py | 8 ++++- .../openlp_core_ui_media/test_webkitplayer.py | 34 +++++++++++-------- tests/functional/test_init.py | 2 +- 3 files changed, 27 insertions(+), 17 deletions(-) diff --git a/openlp/core/ui/media/webkitplayer.py b/openlp/core/ui/media/webkitplayer.py index d33aec7c0..86c20e11d 100644 --- a/openlp/core/ui/media/webkitplayer.py +++ b/openlp/core/ui/media/webkitplayer.py @@ -222,9 +222,15 @@ class WebkitPlayer(MediaPlayer): def check_available(self): """ - Check the availability of the media player + Check the availability of the media player. + + :return: boolean. True if available """ web = QtWebKit.QWebPage() + # This script should return '[object HTMLVideoElement]' if the html5 video is available in webkit. Otherwise it + # should return '[object HTMLUnknownElement]' + mf = web.mainFrame() + return web.mainFrame().evaluateJavaScript( "Object.prototype.toString.call(document.createElement('video'));") == '[object HTMLVideoElement]' diff --git a/tests/functional/openlp_core_ui_media/test_webkitplayer.py b/tests/functional/openlp_core_ui_media/test_webkitplayer.py index 89e79bb0e..9de430f04 100644 --- a/tests/functional/openlp_core_ui_media/test_webkitplayer.py +++ b/tests/functional/openlp_core_ui_media/test_webkitplayer.py @@ -23,7 +23,7 @@ Package to test the openlp.core.ui.media.webkitplayer package. """ from unittest import TestCase -from tests.functional import patch +from tests.functional import MagicMock, patch from openlp.core.ui.media.webkitplayer import WebkitPlayer @@ -33,32 +33,36 @@ class TestWebkitPlayer(TestCase): Test the functions in the :mod:`webkitplayer` module. """ - def check_available_mac_test(self): + def check_available_video_disabled_test(self): """ - Simple test of webkitplayer availability on Mac OS X + Test of webkit video unavailability """ - # GIVEN: A WebkitPlayer and a mocked is_macosx - with patch('openlp.core.ui.media.webkitplayer.is_macosx') as mocked_is_macosx: - mocked_is_macosx.return_value = True + # GIVEN: A WebkitPlayer instance and a mocked QWebPage + mocked_qwebpage = MagicMock() + mocked_qwebpage.mainFrame().evaluateJavaScript.return_value = '[object HTMLUnknownElement]' + with patch('openlp.core.ui.media.webkitplayer.QtWebKit.QWebPage', **{'return_value': mocked_qwebpage}): webkit_player = WebkitPlayer(None) # WHEN: An checking if the player is available available = webkit_player.check_available() - # THEN: The player should not be available on Mac OS X - self.assertEqual(False, available, 'The WebkitPlayer should not be available on Mac OS X.') + # THEN: The player should not be available when '[object HTMLUnknownElement]' is returned + self.assertEqual(False, available, + 'The WebkitPlayer should not be available when video feature detection fails') - def check_available_non_mac_test(self): + def check_available_video_enabled_test(self): """ - Simple test of webkitplayer availability when not on Mac OS X + Test of webkit video availability """ - # GIVEN: A WebkitPlayer and a mocked is_macosx - with patch('openlp.core.ui.media.webkitplayer.is_macosx') as mocked_is_macosx: - mocked_is_macosx.return_value = False + # GIVEN: A WebkitPlayer instance and a mocked QWebPage + mocked_qwebpage = MagicMock() + mocked_qwebpage.mainFrame().evaluateJavaScript.return_value = '[object HTMLUnknownElement]' + with patch('openlp.core.ui.media.webkitplayer.QtWebKit.QWebPage', **{'return_value': mocked_qwebpage}): webkit_player = WebkitPlayer(None) # WHEN: An checking if the player is available available = webkit_player.check_available() - # THEN: The player should be available when not on Mac OS X - self.assertEqual(True, available, 'The WebkitPlayer should be available when not on Mac OS X.') + # THEN: The player should be available when '[object HTMLVideoElement]' is returned + self.assertEqual(True, available, + 'The WebkitPlayer should be available when video feature detection passes') diff --git a/tests/functional/test_init.py b/tests/functional/test_init.py index d1f399c62..62e25aab6 100644 --- a/tests/functional/test_init.py +++ b/tests/functional/test_init.py @@ -134,7 +134,7 @@ class TestInit(TestCase, TestMixin): Test that parse_options parses valid short options correctly when passed through sys.argv """ # GIVEN: A list of valid options - options = ['-e', '-l', 'debug', '-pd', '-s', 'style', 'extra', 'qt', 'args'] + options = ['openlp.py', '-e', '-l', 'debug', '-pd', '-s', 'style', 'extra', 'qt', 'args'] # WHEN: Passing in the options through sys.argv and calling parse_args with None with patch.object(sys, 'argv', options): From 091cb079e74e0a276c08c69e58d1c4c0465c221f Mon Sep 17 00:00:00 2001 From: Phill Ridout Date: Mon, 26 Jan 2015 20:43:53 +0000 Subject: [PATCH 5/7] Fix up tests --- tests/functional/openlp_core_ui_media/test_webkitplayer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/functional/openlp_core_ui_media/test_webkitplayer.py b/tests/functional/openlp_core_ui_media/test_webkitplayer.py index 9de430f04..cea0aa4ad 100644 --- a/tests/functional/openlp_core_ui_media/test_webkitplayer.py +++ b/tests/functional/openlp_core_ui_media/test_webkitplayer.py @@ -56,7 +56,7 @@ class TestWebkitPlayer(TestCase): """ # GIVEN: A WebkitPlayer instance and a mocked QWebPage mocked_qwebpage = MagicMock() - mocked_qwebpage.mainFrame().evaluateJavaScript.return_value = '[object HTMLUnknownElement]' + mocked_qwebpage.mainFrame().evaluateJavaScript.return_value = '[object HTMLVideoElement]' with patch('openlp.core.ui.media.webkitplayer.QtWebKit.QWebPage', **{'return_value': mocked_qwebpage}): webkit_player = WebkitPlayer(None) From 2815bc46e3183a723e59f3666bdecc18089e9972 Mon Sep 17 00:00:00 2001 From: Phill Ridout Date: Mon, 26 Jan 2015 21:04:29 +0000 Subject: [PATCH 6/7] typo --- openlp/plugins/bibles/lib/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openlp/plugins/bibles/lib/__init__.py b/openlp/plugins/bibles/lib/__init__.py index 1d7216ee5..a8becc041 100644 --- a/openlp/plugins/bibles/lib/__init__.py +++ b/openlp/plugins/bibles/lib/__init__.py @@ -178,7 +178,7 @@ def update_reference_separators(): default_separators = [ '|'.join([ translate('BiblesPlugin', ':', 'Verse identifier e.g. Genesis 1 : 1 = Genesis Chapter 1 Verse 1'), - translate('BiblesPlugin', 'v','Verse identifier e.g. Genesis 1 v 1 = Genesis Chapter 1 Verse 1'), + translate('BiblesPlugin', 'v', 'Verse identifier e.g. Genesis 1 v 1 = Genesis Chapter 1 Verse 1'), translate('BiblesPlugin', 'V', 'Verse identifier e.g. Genesis 1 V 1 = Genesis Chapter 1 Verse 1'), translate('BiblesPlugin', 'verse', 'Verse identifier e.g. Genesis 1 verse 1 = Genesis Chapter 1 Verse 1'), translate('BiblesPlugin', 'verses', From bfe1824cb45ba1c6ee09fb5525050cfd82477458 Mon Sep 17 00:00:00 2001 From: Phill Ridout Date: Mon, 26 Jan 2015 21:18:23 +0000 Subject: [PATCH 7/7] removed redundant code --- openlp/core/ui/media/webkitplayer.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/openlp/core/ui/media/webkitplayer.py b/openlp/core/ui/media/webkitplayer.py index 86c20e11d..338a1eae5 100644 --- a/openlp/core/ui/media/webkitplayer.py +++ b/openlp/core/ui/media/webkitplayer.py @@ -229,8 +229,6 @@ class WebkitPlayer(MediaPlayer): web = QtWebKit.QWebPage() # This script should return '[object HTMLVideoElement]' if the html5 video is available in webkit. Otherwise it # should return '[object HTMLUnknownElement]' - mf = web.mainFrame() - return web.mainFrame().evaluateJavaScript( "Object.prototype.toString.call(document.createElement('video'));") == '[object HTMLVideoElement]'