forked from openlp/openlp
Fix the tests I now added back in
This commit is contained in:
parent
7e99381dba
commit
c5b7b46a55
@ -171,7 +171,7 @@ class TestSystemPlayer(TestCase):
|
||||
|
||||
# WHEN: The load() method is run
|
||||
with patch.object(player, 'check_media') as mocked_check_media, \
|
||||
patch.object(player, 'volume') as mocked_volume:
|
||||
patch.object(player, 'volume'):
|
||||
mocked_check_media.return_value = False
|
||||
result = player.load(mocked_display)
|
||||
|
||||
@ -461,8 +461,9 @@ class TestSystemPlayer(TestCase):
|
||||
assert expected_info == result
|
||||
|
||||
@patch('openlp.core.ui.media.systemplayer.CheckMediaWorker')
|
||||
@patch('openlp.core.ui.media.systemplayer.QtCore.QThread')
|
||||
def test_check_media(self, MockQThread, MockCheckMediaWorker):
|
||||
@patch('openlp.core.ui.media.systemplayer.run_thread')
|
||||
@patch('openlp.core.ui.media.systemplayer.is_thread_finished')
|
||||
def test_check_media(self, mocked_is_thread_finished, mocked_run_thread, MockCheckMediaWorker):
|
||||
"""
|
||||
Test the check_media() method of the SystemPlayer
|
||||
"""
|
||||
@ -472,12 +473,8 @@ class TestSystemPlayer(TestCase):
|
||||
Registry().create()
|
||||
Registry().register('application', mocked_application)
|
||||
player = SystemPlayer(self)
|
||||
mocked_thread = MagicMock()
|
||||
mocked_thread.isRunning.side_effect = [True, False]
|
||||
mocked_thread.quit = 'quit' # actually supposed to be a slot, but it's all mocked out anyway
|
||||
MockQThread.return_value = mocked_thread
|
||||
mocked_is_thread_finished.side_effect = [False, True]
|
||||
mocked_check_media_worker = MagicMock()
|
||||
mocked_check_media_worker.play = 'play'
|
||||
mocked_check_media_worker.result = True
|
||||
MockCheckMediaWorker.return_value = mocked_check_media_worker
|
||||
|
||||
@ -485,14 +482,11 @@ class TestSystemPlayer(TestCase):
|
||||
result = player.check_media(valid_file)
|
||||
|
||||
# THEN: It should return True
|
||||
MockQThread.assert_called_once_with()
|
||||
MockCheckMediaWorker.assert_called_once_with(valid_file)
|
||||
mocked_check_media_worker.setVolume.assert_called_once_with(0)
|
||||
mocked_check_media_worker.moveToThread.assert_called_once_with(mocked_thread)
|
||||
mocked_check_media_worker.finished.connect.assert_called_once_with('quit')
|
||||
mocked_thread.started.connect.assert_called_once_with('play')
|
||||
mocked_thread.start.assert_called_once_with()
|
||||
assert 2 == mocked_thread.isRunning.call_count
|
||||
mocked_run_thread.assert_called_once_with(mocked_check_media_worker, 'check_media')
|
||||
mocked_is_thread_finished.assert_called_with('check_media')
|
||||
assert mocked_is_thread_finished.call_count == 2, 'is_thread_finished() should have been called twice'
|
||||
mocked_application.processEvents.assert_called_once_with()
|
||||
assert result is True
|
||||
|
||||
@ -523,12 +517,12 @@ class TestCheckMediaWorker(TestCase):
|
||||
|
||||
# WHEN: signals() is called with media and BufferedMedia
|
||||
with patch.object(worker, 'stop') as mocked_stop, \
|
||||
patch.object(worker, 'finished') as mocked_finished:
|
||||
patch.object(worker, 'quit') as mocked_quit:
|
||||
worker.signals('media', worker.BufferedMedia)
|
||||
|
||||
# THEN: The worker should exit and the result should be True
|
||||
mocked_stop.assert_called_once_with()
|
||||
mocked_finished.emit.assert_called_once_with()
|
||||
mocked_quit.emit.assert_called_once_with()
|
||||
assert worker.result is True
|
||||
|
||||
def test_signals_error(self):
|
||||
@ -540,10 +534,10 @@ class TestCheckMediaWorker(TestCase):
|
||||
|
||||
# WHEN: signals() is called with error and BufferedMedia
|
||||
with patch.object(worker, 'stop') as mocked_stop, \
|
||||
patch.object(worker, 'finished') as mocked_finished:
|
||||
patch.object(worker, 'quit') as mocked_quit:
|
||||
worker.signals('error', None)
|
||||
|
||||
# THEN: The worker should exit and the result should be True
|
||||
mocked_stop.assert_called_once_with()
|
||||
mocked_finished.emit.assert_called_once_with()
|
||||
mocked_quit.emit.assert_called_once_with()
|
||||
assert worker.result is False
|
||||
|
Loading…
Reference in New Issue
Block a user