forked from openlp/openlp
Add some tests
This commit is contained in:
parent
2a1778c878
commit
fda7ab562c
@ -159,7 +159,7 @@ class VlcPlayer(MediaPlayer):
|
|||||||
# framework and not the old Carbon.
|
# framework and not the old Carbon.
|
||||||
display.vlc_media_player.set_nsobject(win_id)
|
display.vlc_media_player.set_nsobject(win_id)
|
||||||
else:
|
else:
|
||||||
# for Linux using the X Server
|
# for Linux/*BSD using the X Server
|
||||||
display.vlc_media_player.set_xwindow(win_id)
|
display.vlc_media_player.set_xwindow(win_id)
|
||||||
self.has_own_widget = True
|
self.has_own_widget = True
|
||||||
|
|
||||||
|
@ -42,4 +42,4 @@ else:
|
|||||||
# Only one QApplication can be created. Use QtGui.QApplication.instance() when you need to "create" a QApplication.
|
# Only one QApplication can be created. Use QtGui.QApplication.instance() when you need to "create" a QApplication.
|
||||||
application = QtGui.QApplication([])
|
application = QtGui.QApplication([])
|
||||||
|
|
||||||
__all__ = ['MagicMock', 'patch', 'mock_open', 'call', 'application']
|
__all__ = ['ANY', 'MagicMock', 'patch', 'mock_open', 'call', 'application']
|
||||||
|
@ -26,15 +26,25 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
from tests.functional import patch
|
|
||||||
|
|
||||||
from openlp.core.ui.media.vlcplayer import AUDIO_EXT, VIDEO_EXT, VlcPlayer, get_vlc
|
from openlp.core.ui.media.vlcplayer import AUDIO_EXT, VIDEO_EXT, VlcPlayer, get_vlc
|
||||||
|
|
||||||
|
from tests.functional import MagicMock, patch
|
||||||
|
|
||||||
|
|
||||||
class TestVLCPlayer(TestCase):
|
class TestVLCPlayer(TestCase):
|
||||||
"""
|
"""
|
||||||
Test the functions in the :mod:`vlcplayer` module.
|
Test the functions in the :mod:`vlcplayer` module.
|
||||||
"""
|
"""
|
||||||
|
def setUp(self):
|
||||||
|
"""
|
||||||
|
Common setup for all the tests
|
||||||
|
"""
|
||||||
|
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']
|
||||||
|
|
||||||
def init_test(self):
|
def init_test(self):
|
||||||
"""
|
"""
|
||||||
Test that the VLC player class initialises correctly
|
Test that the VLC player class initialises correctly
|
||||||
@ -53,6 +63,252 @@ class TestVLCPlayer(TestCase):
|
|||||||
self.assertListEqual(AUDIO_EXT, vlc_player.audio_extensions_list)
|
self.assertListEqual(AUDIO_EXT, vlc_player.audio_extensions_list)
|
||||||
self.assertListEqual(VIDEO_EXT, vlc_player.video_extensions_list)
|
self.assertListEqual(VIDEO_EXT, vlc_player.video_extensions_list)
|
||||||
|
|
||||||
|
@patch('openlp.core.ui.media.vlcplayer.is_win')
|
||||||
|
@patch('openlp.core.ui.media.vlcplayer.is_macosx')
|
||||||
|
@patch('openlp.core.ui.media.vlcplayer.get_vlc')
|
||||||
|
@patch('openlp.core.ui.media.vlcplayer.QtGui')
|
||||||
|
@patch('openlp.core.ui.media.vlcplayer.Settings')
|
||||||
|
def setup_test(self, MockedSettings, MockedQtGui, mocked_get_vlc, mocked_is_macosx, mocked_is_win):
|
||||||
|
"""
|
||||||
|
Test the setup method
|
||||||
|
"""
|
||||||
|
# GIVEN: A bunch of mocked out stuff and a VlcPlayer object
|
||||||
|
mocked_is_macosx.return_value = False
|
||||||
|
mocked_is_win.return_value = False
|
||||||
|
mocked_settings = MagicMock()
|
||||||
|
mocked_settings.value.return_value = True
|
||||||
|
MockedSettings.return_value = mocked_settings
|
||||||
|
mocked_qframe = MagicMock()
|
||||||
|
mocked_qframe.winId.return_value = 2
|
||||||
|
MockedQtGui.QFrame.NoFrame = 1
|
||||||
|
MockedQtGui.QFrame.return_value = mocked_qframe
|
||||||
|
mocked_media_player_new = MagicMock()
|
||||||
|
mocked_instance = MagicMock()
|
||||||
|
mocked_instance.media_player_new.return_value = mocked_media_player_new
|
||||||
|
mocked_vlc = MagicMock()
|
||||||
|
mocked_vlc.Instance.return_value = mocked_instance
|
||||||
|
mocked_get_vlc.return_value = mocked_vlc
|
||||||
|
mocked_display = MagicMock()
|
||||||
|
mocked_display.has_audio = False
|
||||||
|
mocked_display.controller.is_live = True
|
||||||
|
mocked_display.size.return_value = (10, 10)
|
||||||
|
vlc_player = VlcPlayer(None)
|
||||||
|
|
||||||
|
# WHEN: setup() is run
|
||||||
|
vlc_player.setup(mocked_display)
|
||||||
|
|
||||||
|
# THEN: The VLC widget should be set up correctly
|
||||||
|
self.assertEqual(mocked_display.vlc_widget, mocked_qframe)
|
||||||
|
mocked_qframe.setFrameStyle.assert_called_with(1)
|
||||||
|
mocked_settings.value.assert_called_with('advanced/hide mouse')
|
||||||
|
mocked_vlc.Instance.assert_called_with('--no-video-title-show --no-audio --no-video-title-show '
|
||||||
|
'--mouse-hide-timeout=0')
|
||||||
|
self.assertEqual(mocked_display.vlc_instance, mocked_instance)
|
||||||
|
mocked_instance.media_player_new.assert_called_with()
|
||||||
|
self.assertEqual(mocked_display.vlc_media_player, mocked_media_player_new)
|
||||||
|
mocked_display.size.assert_called_with()
|
||||||
|
mocked_qframe.resize.assert_called_with((10, 10))
|
||||||
|
mocked_qframe.raise_.assert_called_with()
|
||||||
|
mocked_qframe.hide.assert_called_with()
|
||||||
|
mocked_media_player_new.set_xwindow.assert_called_with(2)
|
||||||
|
self.assertTrue(vlc_player.has_own_widget)
|
||||||
|
|
||||||
|
@patch('openlp.core.ui.media.vlcplayer.is_win')
|
||||||
|
@patch('openlp.core.ui.media.vlcplayer.is_macosx')
|
||||||
|
@patch('openlp.core.ui.media.vlcplayer.get_vlc')
|
||||||
|
@patch('openlp.core.ui.media.vlcplayer.QtGui')
|
||||||
|
@patch('openlp.core.ui.media.vlcplayer.Settings')
|
||||||
|
def setup_has_audio_test(self, MockedSettings, MockedQtGui, mocked_get_vlc, mocked_is_macosx, mocked_is_win):
|
||||||
|
"""
|
||||||
|
Test the setup method when has_audio is True
|
||||||
|
"""
|
||||||
|
# GIVEN: A bunch of mocked out stuff and a VlcPlayer object
|
||||||
|
mocked_is_macosx.return_value = False
|
||||||
|
mocked_is_win.return_value = False
|
||||||
|
mocked_settings = MagicMock()
|
||||||
|
mocked_settings.value.return_value = True
|
||||||
|
MockedSettings.return_value = mocked_settings
|
||||||
|
mocked_qframe = MagicMock()
|
||||||
|
mocked_qframe.winId.return_value = 2
|
||||||
|
MockedQtGui.QFrame.NoFrame = 1
|
||||||
|
MockedQtGui.QFrame.return_value = mocked_qframe
|
||||||
|
mocked_media_player_new = MagicMock()
|
||||||
|
mocked_instance = MagicMock()
|
||||||
|
mocked_instance.media_player_new.return_value = mocked_media_player_new
|
||||||
|
mocked_vlc = MagicMock()
|
||||||
|
mocked_vlc.Instance.return_value = mocked_instance
|
||||||
|
mocked_get_vlc.return_value = mocked_vlc
|
||||||
|
mocked_display = MagicMock()
|
||||||
|
mocked_display.has_audio = True
|
||||||
|
mocked_display.controller.is_live = True
|
||||||
|
mocked_display.size.return_value = (10, 10)
|
||||||
|
vlc_player = VlcPlayer(None)
|
||||||
|
|
||||||
|
# WHEN: setup() is run
|
||||||
|
vlc_player.setup(mocked_display)
|
||||||
|
|
||||||
|
# THEN: The VLC widget should be set up correctly
|
||||||
|
self.assertEqual(mocked_display.vlc_widget, mocked_qframe)
|
||||||
|
mocked_qframe.setFrameStyle.assert_called_with(1)
|
||||||
|
mocked_settings.value.assert_called_with('advanced/hide mouse')
|
||||||
|
mocked_vlc.Instance.assert_called_with('--no-video-title-show --mouse-hide-timeout=0')
|
||||||
|
self.assertEqual(mocked_display.vlc_instance, mocked_instance)
|
||||||
|
mocked_instance.media_player_new.assert_called_with()
|
||||||
|
self.assertEqual(mocked_display.vlc_media_player, mocked_media_player_new)
|
||||||
|
mocked_display.size.assert_called_with()
|
||||||
|
mocked_qframe.resize.assert_called_with((10, 10))
|
||||||
|
mocked_qframe.raise_.assert_called_with()
|
||||||
|
mocked_qframe.hide.assert_called_with()
|
||||||
|
mocked_media_player_new.set_xwindow.assert_called_with(2)
|
||||||
|
self.assertTrue(vlc_player.has_own_widget)
|
||||||
|
|
||||||
|
@patch('openlp.core.ui.media.vlcplayer.is_win')
|
||||||
|
@patch('openlp.core.ui.media.vlcplayer.is_macosx')
|
||||||
|
@patch('openlp.core.ui.media.vlcplayer.get_vlc')
|
||||||
|
@patch('openlp.core.ui.media.vlcplayer.QtGui')
|
||||||
|
@patch('openlp.core.ui.media.vlcplayer.Settings')
|
||||||
|
def setup_visible_mouse_test(self, MockedSettings, MockedQtGui, mocked_get_vlc, mocked_is_macosx, mocked_is_win):
|
||||||
|
"""
|
||||||
|
Test the setup method when Settings().value("hide mouse") is False
|
||||||
|
"""
|
||||||
|
# GIVEN: A bunch of mocked out stuff and a VlcPlayer object
|
||||||
|
mocked_is_macosx.return_value = False
|
||||||
|
mocked_is_win.return_value = False
|
||||||
|
mocked_settings = MagicMock()
|
||||||
|
mocked_settings.value.return_value = False
|
||||||
|
MockedSettings.return_value = mocked_settings
|
||||||
|
mocked_qframe = MagicMock()
|
||||||
|
mocked_qframe.winId.return_value = 2
|
||||||
|
MockedQtGui.QFrame.NoFrame = 1
|
||||||
|
MockedQtGui.QFrame.return_value = mocked_qframe
|
||||||
|
mocked_media_player_new = MagicMock()
|
||||||
|
mocked_instance = MagicMock()
|
||||||
|
mocked_instance.media_player_new.return_value = mocked_media_player_new
|
||||||
|
mocked_vlc = MagicMock()
|
||||||
|
mocked_vlc.Instance.return_value = mocked_instance
|
||||||
|
mocked_get_vlc.return_value = mocked_vlc
|
||||||
|
mocked_display = MagicMock()
|
||||||
|
mocked_display.has_audio = False
|
||||||
|
mocked_display.controller.is_live = True
|
||||||
|
mocked_display.size.return_value = (10, 10)
|
||||||
|
vlc_player = VlcPlayer(None)
|
||||||
|
|
||||||
|
# WHEN: setup() is run
|
||||||
|
vlc_player.setup(mocked_display)
|
||||||
|
|
||||||
|
# THEN: The VLC widget should be set up correctly
|
||||||
|
self.assertEqual(mocked_display.vlc_widget, mocked_qframe)
|
||||||
|
mocked_qframe.setFrameStyle.assert_called_with(1)
|
||||||
|
mocked_settings.value.assert_called_with('advanced/hide mouse')
|
||||||
|
mocked_vlc.Instance.assert_called_with('--no-video-title-show --no-audio --no-video-title-show')
|
||||||
|
self.assertEqual(mocked_display.vlc_instance, mocked_instance)
|
||||||
|
mocked_instance.media_player_new.assert_called_with()
|
||||||
|
self.assertEqual(mocked_display.vlc_media_player, mocked_media_player_new)
|
||||||
|
mocked_display.size.assert_called_with()
|
||||||
|
mocked_qframe.resize.assert_called_with((10, 10))
|
||||||
|
mocked_qframe.raise_.assert_called_with()
|
||||||
|
mocked_qframe.hide.assert_called_with()
|
||||||
|
mocked_media_player_new.set_xwindow.assert_called_with(2)
|
||||||
|
self.assertTrue(vlc_player.has_own_widget)
|
||||||
|
|
||||||
|
@patch('openlp.core.ui.media.vlcplayer.is_win')
|
||||||
|
@patch('openlp.core.ui.media.vlcplayer.is_macosx')
|
||||||
|
@patch('openlp.core.ui.media.vlcplayer.get_vlc')
|
||||||
|
@patch('openlp.core.ui.media.vlcplayer.QtGui')
|
||||||
|
@patch('openlp.core.ui.media.vlcplayer.Settings')
|
||||||
|
def setup_windows_test(self, MockedSettings, MockedQtGui, mocked_get_vlc, mocked_is_macosx, mocked_is_win):
|
||||||
|
"""
|
||||||
|
Test the setup method when running on Windows
|
||||||
|
"""
|
||||||
|
# GIVEN: A bunch of mocked out stuff and a VlcPlayer object
|
||||||
|
mocked_is_macosx.return_value = False
|
||||||
|
mocked_is_win.return_value = True
|
||||||
|
mocked_settings = MagicMock()
|
||||||
|
mocked_settings.value.return_value = False
|
||||||
|
MockedSettings.return_value = mocked_settings
|
||||||
|
mocked_qframe = MagicMock()
|
||||||
|
mocked_qframe.winId.return_value = 2
|
||||||
|
MockedQtGui.QFrame.NoFrame = 1
|
||||||
|
MockedQtGui.QFrame.return_value = mocked_qframe
|
||||||
|
mocked_media_player_new = MagicMock()
|
||||||
|
mocked_instance = MagicMock()
|
||||||
|
mocked_instance.media_player_new.return_value = mocked_media_player_new
|
||||||
|
mocked_vlc = MagicMock()
|
||||||
|
mocked_vlc.Instance.return_value = mocked_instance
|
||||||
|
mocked_get_vlc.return_value = mocked_vlc
|
||||||
|
mocked_display = MagicMock()
|
||||||
|
mocked_display.has_audio = False
|
||||||
|
mocked_display.controller.is_live = True
|
||||||
|
mocked_display.size.return_value = (10, 10)
|
||||||
|
vlc_player = VlcPlayer(None)
|
||||||
|
|
||||||
|
# WHEN: setup() is run
|
||||||
|
vlc_player.setup(mocked_display)
|
||||||
|
|
||||||
|
# THEN: The VLC widget should be set up correctly
|
||||||
|
self.assertEqual(mocked_display.vlc_widget, mocked_qframe)
|
||||||
|
mocked_qframe.setFrameStyle.assert_called_with(1)
|
||||||
|
mocked_settings.value.assert_called_with('advanced/hide mouse')
|
||||||
|
mocked_vlc.Instance.assert_called_with('--no-video-title-show --no-audio --no-video-title-show')
|
||||||
|
self.assertEqual(mocked_display.vlc_instance, mocked_instance)
|
||||||
|
mocked_instance.media_player_new.assert_called_with()
|
||||||
|
self.assertEqual(mocked_display.vlc_media_player, mocked_media_player_new)
|
||||||
|
mocked_display.size.assert_called_with()
|
||||||
|
mocked_qframe.resize.assert_called_with((10, 10))
|
||||||
|
mocked_qframe.raise_.assert_called_with()
|
||||||
|
mocked_qframe.hide.assert_called_with()
|
||||||
|
mocked_media_player_new.set_hwnd.assert_called_with(2)
|
||||||
|
self.assertTrue(vlc_player.has_own_widget)
|
||||||
|
|
||||||
|
@patch('openlp.core.ui.media.vlcplayer.is_win')
|
||||||
|
@patch('openlp.core.ui.media.vlcplayer.is_macosx')
|
||||||
|
@patch('openlp.core.ui.media.vlcplayer.get_vlc')
|
||||||
|
@patch('openlp.core.ui.media.vlcplayer.QtGui')
|
||||||
|
@patch('openlp.core.ui.media.vlcplayer.Settings')
|
||||||
|
def setup_osx_test(self, MockedSettings, MockedQtGui, mocked_get_vlc, mocked_is_macosx, mocked_is_win):
|
||||||
|
"""
|
||||||
|
Test the setup method when running on OS X
|
||||||
|
"""
|
||||||
|
# GIVEN: A bunch of mocked out stuff and a VlcPlayer object
|
||||||
|
mocked_is_macosx.return_value = True
|
||||||
|
mocked_is_win.return_value = False
|
||||||
|
mocked_settings = MagicMock()
|
||||||
|
mocked_settings.value.return_value = False
|
||||||
|
MockedSettings.return_value = mocked_settings
|
||||||
|
mocked_qframe = MagicMock()
|
||||||
|
mocked_qframe.winId.return_value = 2
|
||||||
|
MockedQtGui.QFrame.NoFrame = 1
|
||||||
|
MockedQtGui.QFrame.return_value = mocked_qframe
|
||||||
|
mocked_media_player_new = MagicMock()
|
||||||
|
mocked_instance = MagicMock()
|
||||||
|
mocked_instance.media_player_new.return_value = mocked_media_player_new
|
||||||
|
mocked_vlc = MagicMock()
|
||||||
|
mocked_vlc.Instance.return_value = mocked_instance
|
||||||
|
mocked_get_vlc.return_value = mocked_vlc
|
||||||
|
mocked_display = MagicMock()
|
||||||
|
mocked_display.has_audio = False
|
||||||
|
mocked_display.controller.is_live = True
|
||||||
|
mocked_display.size.return_value = (10, 10)
|
||||||
|
vlc_player = VlcPlayer(None)
|
||||||
|
|
||||||
|
# WHEN: setup() is run
|
||||||
|
vlc_player.setup(mocked_display)
|
||||||
|
|
||||||
|
# THEN: The VLC widget should be set up correctly
|
||||||
|
self.assertEqual(mocked_display.vlc_widget, mocked_qframe)
|
||||||
|
mocked_qframe.setFrameStyle.assert_called_with(1)
|
||||||
|
mocked_settings.value.assert_called_with('advanced/hide mouse')
|
||||||
|
mocked_vlc.Instance.assert_called_with('--no-video-title-show --no-audio --no-video-title-show')
|
||||||
|
self.assertEqual(mocked_display.vlc_instance, mocked_instance)
|
||||||
|
mocked_instance.media_player_new.assert_called_with()
|
||||||
|
self.assertEqual(mocked_display.vlc_media_player, mocked_media_player_new)
|
||||||
|
mocked_display.size.assert_called_with()
|
||||||
|
mocked_qframe.resize.assert_called_with((10, 10))
|
||||||
|
mocked_qframe.raise_.assert_called_with()
|
||||||
|
mocked_qframe.hide.assert_called_with()
|
||||||
|
mocked_media_player_new.set_nsobject.assert_called_with(2)
|
||||||
|
self.assertTrue(vlc_player.has_own_widget)
|
||||||
|
|
||||||
@patch('openlp.core.ui.media.vlcplayer.is_macosx')
|
@patch('openlp.core.ui.media.vlcplayer.is_macosx')
|
||||||
def fix_vlc_22_plugin_path_test(self, mocked_is_macosx):
|
def fix_vlc_22_plugin_path_test(self, mocked_is_macosx):
|
||||||
"""
|
"""
|
||||||
@ -60,10 +316,6 @@ class TestVLCPlayer(TestCase):
|
|||||||
"""
|
"""
|
||||||
# GIVEN: We're on OS X and we don't have the VLC plugin path set
|
# GIVEN: We're on OS X and we don't have the VLC plugin path set
|
||||||
mocked_is_macosx.return_value = True
|
mocked_is_macosx.return_value = True
|
||||||
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
|
# WHEN: An checking if the player is available
|
||||||
get_vlc()
|
get_vlc()
|
||||||
|
Loading…
Reference in New Issue
Block a user