forked from openlp/openlp
[Media Players] Added better detection for VLC, with thanks to Tomas.
This commit is contained in:
parent
50ceb568e5
commit
851af0b7a5
@ -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
|
||||
|
||||
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user