[Media Players] Added better detection for VLC, with thanks to Tomas.

Note: I made a test, but this is untestable because of the hidden import inside the function.

lp:~raoul-snyman/openlp/ubuntu-vlc-bug (revision 2563)
[SUCCESS] https//ci.openlp.io/job/Branch-01-Pull/1162/
[SUCCESS] https//ci.openlp.io/job/Branch-02-Functional-Tests/1085/
[SUCCESS] https//ci.openlp.io/job/Branch-03-Interface-Tests/1026/
[SUCCESS] https//ci.openlp.io/job/Branch-04a-Windows_Functional_Tests/873/
[SUCCESS] htt...

bzr-revno: 2566
This commit is contained in:
raoul@snyman.info 2015-10-28 21:44:28 +00:00 committed by Tim Bentley
commit 3285088814
2 changed files with 22 additions and 5 deletions

View File

@ -84,7 +84,9 @@ def get_vlc():
pass
if is_vlc_available:
try:
vlc_instance = vlc.Instance()
VERSION = vlc.libvlc_get_version().decode('UTF-8')
vlc_instance.release()
except:
VERSION = '0.0.0'
# LooseVersion does not work when a string contains letter and digits (e. g. 2.0.5 Twoflower).
@ -95,6 +97,9 @@ def get_vlc():
if is_vlc_available:
return vlc
else:
# The vlc module may have been imported. Remove it if it has.
if 'openlp.core.ui.media.vendor.vlc' in sys.modules:
del sys.modules['openlp.core.ui.media.vendor.vlc']
return None

View File

@ -25,7 +25,7 @@ Package to test the openlp.core.ui.media.vlcplayer package.
import os
import sys
from datetime import datetime, timedelta
from unittest import TestCase
from unittest import TestCase, skip
from openlp.core.common import Registry
from openlp.core.ui.media import MediaState, MediaType
@ -50,6 +50,22 @@ class TestVLCPlayer(TestCase, TestMixin):
del sys.modules['openlp.core.ui.media.vendor.vlc']
MockDateTime.revert()
@skip('No way to test this')
@patch('openlp.core.ui.media.vlcplayer.vlc')
def get_vlc_fails_and_removes_module_test(self, mocked_vlc):
"""
Test that when the VLC import fails, it removes the module from sys.modules
"""
# GIVEN: We're on OS X and we don't have the VLC plugin path set
mocked_vlc.Instance.side_effect = NameError
mocked_vlc.libvlc_get_version.return_value = b'0.0.0'
# WHEN: An checking if the player is available
get_vlc()
# THEN: The extra environment variable should be there
self.assertNotIn('openlp.core.ui.media.vendor.vlc', sys.modules)
@patch('openlp.core.ui.media.vlcplayer.is_macosx')
def fix_vlc_22_plugin_path_test(self, mocked_is_macosx):
"""
@ -74,10 +90,6 @@ class TestVLCPlayer(TestCase, TestMixin):
"""
# GIVEN: We're not on OS X and we don't have the VLC plugin path set
mocked_is_macosx.return_value = False
if 'VLC_PLUGIN_PATH' in os.environ:
del os.environ['VLC_PLUGIN_PATH']
if 'openlp.core.ui.media.vendor.vlc' in sys.modules:
del sys.modules['openlp.core.ui.media.vendor.vlc']
# WHEN: An checking if the player is available
get_vlc()