예제 #1
0
    def test_check_media(self, MockQThread, MockCheckMediaWorker):
        """
        Test the check_media() method of the SystemPlayer
        """
        # GIVEN: A SystemPlayer instance and a mocked thread
        valid_file = '/path/to/video.ogv'
        mocked_application = MagicMock()
        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_check_media_worker = MagicMock()
        mocked_check_media_worker.play = 'play'
        mocked_check_media_worker.result = True
        MockCheckMediaWorker.return_value = mocked_check_media_worker

        # WHEN: check_media() is called with a valid media file
        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()
        self.assertEqual(2, mocked_thread.isRunning.call_count)
        mocked_application.processEvents.assert_called_once_with()
        self.assertTrue(result)
예제 #2
0
    def test_check_media(self, mocked_is_thread_finished, mocked_run_thread,
                         MockCheckMediaWorker):
        """
        Test the check_media() method of the SystemPlayer
        """
        # GIVEN: A SystemPlayer instance and a mocked thread
        valid_file = '/path/to/video.ogv'
        mocked_application = MagicMock()
        Registry().create()
        Registry().register('application', mocked_application)
        player = SystemPlayer(self)
        mocked_is_thread_finished.side_effect = [False, True]
        mocked_check_media_worker = MagicMock()
        mocked_check_media_worker.result = True
        MockCheckMediaWorker.return_value = mocked_check_media_worker

        # WHEN: check_media() is called with a valid media file
        result = player.check_media(valid_file)

        # THEN: It should return True
        MockCheckMediaWorker.assert_called_once_with(valid_file)
        mocked_check_media_worker.setVolume.assert_called_once_with(0)
        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
예제 #3
0
    def test_check_media(self, MockQThread, MockCheckMediaWorker):
        """
        Test the check_media() method of the SystemPlayer
        """
        # GIVEN: A SystemPlayer instance and a mocked thread
        valid_file = '/path/to/video.ogv'
        mocked_application = MagicMock()
        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_check_media_worker = MagicMock()
        mocked_check_media_worker.play = 'play'
        mocked_check_media_worker.result = True
        MockCheckMediaWorker.return_value = mocked_check_media_worker

        # WHEN: check_media() is called with a valid media file
        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()
        self.assertEqual(2, mocked_thread.isRunning.call_count)
        mocked_application.processEvents.assert_called_once_with()
        self.assertTrue(result)