本文整理汇总了Python中tests.functional.MagicMock.controller方法的典型用法代码示例。如果您正苦于以下问题:Python MagicMock.controller方法的具体用法?Python MagicMock.controller怎么用?Python MagicMock.controller使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tests.functional.MagicMock
的用法示例。
在下文中一共展示了MagicMock.controller方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update_ui_dvd_test
# 需要导入模块: from tests.functional import MagicMock [as 别名]
# 或者: from tests.functional.MagicMock import controller [as 别名]
def update_ui_dvd_test(self, mocked_get_vlc):
"""
Test updating the UI for a CD or DVD
"""
# GIVEN: A whole bunch of mocks
mocked_vlc = MagicMock()
mocked_vlc.State.Ended = 1
mocked_get_vlc.return_value = mocked_vlc
mocked_controller = MagicMock()
mocked_controller.media_info.start_time = 100
mocked_controller.media_info.end_time = 300
mocked_controller.seek_slider.isSliderDown.return_value = False
mocked_display = MagicMock()
mocked_display.controller = mocked_controller
mocked_display.vlc_media.get_state.return_value = 1
mocked_display.vlc_media_player.get_time.return_value = 400000
mocked_display.controller.media_info.media_type = MediaType.DVD
vlc_player = VlcPlayer(None)
# WHEN: update_ui() is called
with patch.object(vlc_player, 'stop') as mocked_stop, \
patch.object(vlc_player, 'set_visible') as mocked_set_visible:
vlc_player.update_ui(mocked_display)
# THEN: Certain methods should be called
mocked_stop.assert_called_with(mocked_display)
self.assertEqual(2, mocked_stop.call_count)
mocked_display.vlc_media_player.get_time.assert_called_with()
mocked_set_visible.assert_called_with(mocked_display, False)
mocked_controller.seek_slider.setSliderPosition.assert_called_with(300000)
expected_calls = [call(True), call(False)]
self.assertEqual(expected_calls, mocked_controller.seek_slider.blockSignals.call_args_list)
示例2: play_media_wait_state_not_playing_test
# 需要导入模块: from tests.functional import MagicMock [as 别名]
# 或者: from tests.functional.MagicMock import controller [as 别名]
def play_media_wait_state_not_playing_test(self, mocked_get_vlc, mocked_threading):
"""
Test the play() method when media_wait_state() returns False
"""
# GIVEN: A bunch of mocked out things
mocked_thread = MagicMock()
mocked_threading.Thread.return_value = mocked_thread
mocked_vlc = MagicMock()
mocked_get_vlc.return_value = mocked_vlc
mocked_controller = MagicMock()
mocked_controller.media_info.start_time = 0
mocked_display = MagicMock()
mocked_display.controller = mocked_controller
vlc_player = VlcPlayer(None)
vlc_player.state = MediaState.Paused
# WHEN: play() is called
with patch.object(vlc_player, 'media_state_wait') as mocked_media_state_wait, \
patch.object(vlc_player, 'volume') as mocked_volume:
mocked_media_state_wait.return_value = False
result = vlc_player.play(mocked_display)
# THEN: A thread should be started, but the method should return False
mocked_thread.start.assert_called_with()
self.assertFalse(result)
示例3: play_test
# 需要导入模块: from tests.functional import MagicMock [as 别名]
# 或者: from tests.functional.MagicMock import controller [as 别名]
def play_test(self, mocked_get_vlc, mocked_threading):
"""
Test the play() method
"""
# GIVEN: A bunch of mocked out things
mocked_thread = MagicMock()
mocked_threading.Thread.return_value = mocked_thread
mocked_vlc = MagicMock()
mocked_get_vlc.return_value = mocked_vlc
mocked_controller = MagicMock()
mocked_controller.media_info.start_time = 0
mocked_controller.media_info.media_type = MediaType.Video
mocked_controller.media_info.volume = 100
mocked_media = MagicMock()
mocked_media.get_duration.return_value = 50000
mocked_display = MagicMock()
mocked_display.controller = mocked_controller
mocked_display.vlc_media_player.get_media.return_value = mocked_media
vlc_player = VlcPlayer(None)
vlc_player.state = MediaState.Paused
# WHEN: play() is called
with patch.object(vlc_player, 'media_state_wait') as mocked_media_state_wait, \
patch.object(vlc_player, 'volume') as mocked_volume:
mocked_media_state_wait.return_value = True
result = vlc_player.play(mocked_display)
# THEN: A bunch of things should happen to play the media
mocked_thread.start.assert_called_with()
self.assertEqual(50, mocked_controller.media_info.length)
mocked_volume.assert_called_with(mocked_display, 100)
mocked_controller.seek_slider.setMaximum.assert_called_with(50000)
self.assertEqual(MediaState.Playing, vlc_player.state)
mocked_display.vlc_widget.raise_.assert_called_with()
self.assertTrue(result, 'The value returned from play() should be True')
示例4: load_test
# 需要导入模块: from tests.functional import MagicMock [as 别名]
# 或者: from tests.functional.MagicMock import controller [as 别名]
def load_test(self, mocked_normcase, mocked_get_vlc):
"""
Test loading a video into VLC
"""
# GIVEN: A mocked out get_vlc() method
media_path = '/path/to/media.mp4'
mocked_normcase.side_effect = lambda x: x
mocked_vlc = MagicMock()
mocked_get_vlc.return_value = mocked_vlc
mocked_controller = MagicMock()
mocked_controller.media_info.volume = 100
mocked_controller.media_info.media_type = MediaType.Video
mocked_controller.media_info.file_info.absoluteFilePath.return_value = media_path
mocked_vlc_media = MagicMock()
mocked_media = MagicMock()
mocked_media.get_duration.return_value = 10000
mocked_display = MagicMock()
mocked_display.controller = mocked_controller
mocked_display.vlc_instance.media_new_path.return_value = mocked_vlc_media
mocked_display.vlc_media_player.get_media.return_value = mocked_media
vlc_player = VlcPlayer(None)
# WHEN: A video is loaded into VLC
with patch.object(vlc_player, 'volume') as mocked_volume:
result = vlc_player.load(mocked_display)
# THEN: The video should be loaded
mocked_normcase.assert_called_with(media_path)
mocked_display.vlc_instance.media_new_path.assert_called_with(media_path)
self.assertEqual(mocked_vlc_media, mocked_display.vlc_media)
mocked_display.vlc_media_player.set_media.assert_called_with(mocked_vlc_media)
mocked_vlc_media.parse.assert_called_with()
mocked_volume.assert_called_with(mocked_display, 100)
self.assertEqual(10, mocked_controller.media_info.length)
self.assertTrue(result)
示例5: load_audio_cd_on_windows_test
# 需要导入模块: from tests.functional import MagicMock [as 别名]
# 或者: from tests.functional.MagicMock import controller [as 别名]
def load_audio_cd_on_windows_test(self, mocked_normcase, mocked_get_vlc, mocked_is_win):
"""
Test loading an audio CD into VLC on Windows
"""
# GIVEN: A mocked out get_vlc() method
mocked_is_win.return_value = True
media_path = '/dev/sr0'
mocked_normcase.side_effect = lambda x: x
mocked_vlc = MagicMock()
mocked_get_vlc.return_value = mocked_vlc
mocked_controller = MagicMock()
mocked_controller.media_info.volume = 100
mocked_controller.media_info.media_type = MediaType.CD
mocked_controller.media_info.file_info.absoluteFilePath.return_value = media_path
mocked_controller.media_info.title_track = 1
mocked_vlc_media = MagicMock()
mocked_media = MagicMock()
mocked_media.get_duration.return_value = 10000
mocked_display = MagicMock()
mocked_display.controller = mocked_controller
mocked_display.vlc_instance.media_new_location.return_value = mocked_vlc_media
mocked_display.vlc_media_player.get_media.return_value = mocked_media
mocked_subitems = MagicMock()
mocked_subitems.count.return_value = 1
mocked_subitems.item_at_index.return_value = mocked_vlc_media
mocked_vlc_media.subitems.return_value = mocked_subitems
vlc_player = VlcPlayer(None)
# WHEN: An audio CD is loaded into VLC
with patch.object(vlc_player, 'volume') as mocked_volume, \
patch.object(vlc_player, 'media_state_wait') as mocked_media_state_wait:
result = vlc_player.load(mocked_display)
# THEN: The video should be loaded
mocked_normcase.assert_called_with(media_path)
mocked_display.vlc_instance.media_new_location.assert_called_with('cdda:///' + media_path)
self.assertEqual(mocked_vlc_media, mocked_display.vlc_media)
mocked_display.vlc_media_player.set_media.assert_called_with(mocked_vlc_media)
mocked_vlc_media.parse.assert_called_with()
mocked_volume.assert_called_with(mocked_display, 100)
self.assertEqual(10, mocked_controller.media_info.length)
self.assertTrue(result)
示例6: test_play_dvd
# 需要导入模块: from tests.functional import MagicMock [as 别名]
# 或者: from tests.functional.MagicMock import controller [as 别名]
def test_play_dvd(self, mocked_get_vlc, mocked_threading):
"""
Test the play() method with a DVD
"""
# GIVEN: A bunch of mocked out things
mocked_thread = MagicMock()
mocked_threading.Thread.return_value = mocked_thread
mocked_vlc = MagicMock()
mocked_get_vlc.return_value = mocked_vlc
mocked_controller = MagicMock()
mocked_controller.media_info.start_time = 0
mocked_controller.media_info.end_time = 50
mocked_controller.media_info.media_type = MediaType.DVD
mocked_controller.media_info.volume = 100
mocked_controller.media_info.title_track = 1
mocked_controller.media_info.audio_track = 1
mocked_controller.media_info.subtitle_track = 1
mocked_display = MagicMock()
mocked_display.controller = mocked_controller
vlc_player = VlcPlayer(None)
vlc_player.set_state(MediaState.Paused, mocked_display)
# WHEN: play() is called
with patch.object(vlc_player, 'media_state_wait') as mocked_media_state_wait, \
patch.object(vlc_player, 'volume') as mocked_volume:
mocked_media_state_wait.return_value = True
result = vlc_player.play(mocked_display)
# THEN: A bunch of things should happen to play the media
mocked_thread.start.assert_called_with()
mocked_display.vlc_media_player.set_title.assert_called_with(1)
mocked_display.vlc_media_player.play.assert_called_with()
mocked_display.vlc_media_player.audio_set_track.assert_called_with(1)
mocked_display.vlc_media_player.video_set_spu.assert_called_with(1)
mocked_volume.assert_called_with(mocked_display, 100)
self.assertEqual(MediaState.Playing, vlc_player.get_live_state())
mocked_display.vlc_widget.raise_.assert_called_with()
self.assertTrue(result, 'The value returned from play() should be True')