forked from openlp/openlp
Add tests around pausing
This commit is contained in:
parent
dd9e12d2b5
commit
9232e75582
@ -402,6 +402,76 @@ class TestVLCPlayer(TestCase, TestMixin):
|
||||
mocked_display.size.assert_called_with()
|
||||
mocked_display.vlc_widget.resize.assert_called_with((10, 10))
|
||||
|
||||
@patch('openlp.core.ui.media.vlcplayer.get_vlc')
|
||||
def pause_test(self, mocked_get_vlc):
|
||||
"""
|
||||
Test that the pause method works correctly
|
||||
"""
|
||||
# GIVEN: A mocked out get_vlc method
|
||||
mocked_vlc = MagicMock()
|
||||
mocked_vlc.State.Playing = 1
|
||||
mocked_vlc.State.Paused = 2
|
||||
mocked_get_vlc.return_value = mocked_vlc
|
||||
mocked_display = MagicMock()
|
||||
mocked_display.vlc_media.get_state.return_value = 1
|
||||
vlc_player = VlcPlayer(None)
|
||||
|
||||
# WHEN: The media is paused
|
||||
with patch.object(vlc_player, 'media_state_wait') as mocked_media_state_wait:
|
||||
mocked_media_state_wait.return_value = True
|
||||
vlc_player.pause(mocked_display)
|
||||
|
||||
# THEN: The pause method should exit early
|
||||
mocked_display.vlc_media.get_state.assert_called_with()
|
||||
mocked_display.vlc_media_player.pause.assert_called_with()
|
||||
mocked_media_state_wait.assert_called_with(mocked_display, 2)
|
||||
self.assertEqual(MediaState.Paused, vlc_player.state)
|
||||
|
||||
@patch('openlp.core.ui.media.vlcplayer.get_vlc')
|
||||
def pause_not_playing_test(self, mocked_get_vlc):
|
||||
"""
|
||||
Test the pause method when the player is not playing
|
||||
"""
|
||||
# GIVEN: A mocked out get_vlc method
|
||||
mocked_vlc = MagicMock()
|
||||
mocked_vlc.State.Playing = 1
|
||||
mocked_get_vlc.return_value = mocked_vlc
|
||||
mocked_display = MagicMock()
|
||||
mocked_display.vlc_media.get_state.return_value = 2
|
||||
vlc_player = VlcPlayer(None)
|
||||
|
||||
# WHEN: The media is paused
|
||||
vlc_player.pause(mocked_display)
|
||||
|
||||
# THEN: The pause method should exit early
|
||||
mocked_display.vlc_media.get_state.assert_called_with()
|
||||
self.assertEqual(0, mocked_display.vlc_media_player.pause.call_count)
|
||||
|
||||
@patch('openlp.core.ui.media.vlcplayer.get_vlc')
|
||||
def pause_fail_test(self, mocked_get_vlc):
|
||||
"""
|
||||
Test the pause method when the player fails to pause the media
|
||||
"""
|
||||
# GIVEN: A mocked out get_vlc method
|
||||
mocked_vlc = MagicMock()
|
||||
mocked_vlc.State.Playing = 1
|
||||
mocked_vlc.State.Paused = 2
|
||||
mocked_get_vlc.return_value = mocked_vlc
|
||||
mocked_display = MagicMock()
|
||||
mocked_display.vlc_media.get_state.return_value = 1
|
||||
vlc_player = VlcPlayer(None)
|
||||
|
||||
# WHEN: The media is paused
|
||||
with patch.object(vlc_player, 'media_state_wait') as mocked_media_state_wait:
|
||||
mocked_media_state_wait.return_value = False
|
||||
vlc_player.pause(mocked_display)
|
||||
|
||||
# THEN: The pause method should exit early
|
||||
mocked_display.vlc_media.get_state.assert_called_with()
|
||||
mocked_display.vlc_media_player.pause.assert_called_with()
|
||||
mocked_media_state_wait.assert_called_with(mocked_display, 2)
|
||||
self.assertNotEqual(MediaState.Paused, vlc_player.state)
|
||||
|
||||
@patch('openlp.core.ui.media.vlcplayer.threading')
|
||||
def stop_test(self, mocked_threading):
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user