当前位置: 首页>>代码示例>>Python>>正文


Python MagicMock.assert_called_once_with方法代码示例

本文整理汇总了Python中tests.functional.MagicMock.assert_called_once_with方法的典型用法代码示例。如果您正苦于以下问题:Python MagicMock.assert_called_once_with方法的具体用法?Python MagicMock.assert_called_once_with怎么用?Python MagicMock.assert_called_once_with使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tests.functional.MagicMock的用法示例。


在下文中一共展示了MagicMock.assert_called_once_with方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: on_slide_selected_index_service_item_not_command_test

# 需要导入模块: from tests.functional import MagicMock [as 别名]
# 或者: from tests.functional.MagicMock import assert_called_once_with [as 别名]
    def on_slide_selected_index_service_item_not_command_test(self, mocked_execute):
        """
        Test that when there is a service item but it's not a command, the preview widget is updated
        """
        # GIVEN: A mocked service item and a slide controller with a service item
        mocked_item = MagicMock()
        mocked_item.is_command.return_value = False
        mocked_item.name = 'Mocked Item'
        mocked_update_preview = MagicMock()
        mocked_preview_widget = MagicMock()
        mocked_slide_selected = MagicMock()
        Registry.create()
        slide_controller = SlideController(None)
        slide_controller.service_item = mocked_item
        slide_controller.update_preview = mocked_update_preview
        slide_controller.preview_widget = mocked_preview_widget
        slide_controller.slide_selected = mocked_slide_selected

        # WHEN: The method is called
        slide_controller.on_slide_selected_index([7])

        # THEN: It should have sent a notification
        mocked_item.is_command.assert_called_once_with()
        self.assertEqual(0, mocked_execute.call_count, 'Execute should not have been called')
        self.assertEqual(0, mocked_update_preview.call_count, 'Update preview should not have been called')
        mocked_preview_widget.change_slide.assert_called_once_with(7)
        mocked_slide_selected.assert_called_once_with()
开发者ID:crossroadchurch,项目名称:paul,代码行数:29,代码来源:test_slidecontroller.py

示例2: on_slide_selected_index_service_item_command_test

# 需要导入模块: from tests.functional import MagicMock [as 别名]
# 或者: from tests.functional.MagicMock import assert_called_once_with [as 别名]
    def on_slide_selected_index_service_item_command_test(self, mocked_execute):
        """
        Test that when there is a command service item, the command is executed
        """
        # GIVEN: A mocked service item and a slide controller with a service item
        mocked_item = MagicMock()
        mocked_item.is_command.return_value = True
        mocked_item.name = 'Mocked Item'
        mocked_update_preview = MagicMock()
        mocked_preview_widget = MagicMock()
        mocked_slide_selected = MagicMock()
        Registry.create()
        slide_controller = SlideController(None)
        slide_controller.service_item = mocked_item
        slide_controller.update_preview = mocked_update_preview
        slide_controller.preview_widget = mocked_preview_widget
        slide_controller.slide_selected = mocked_slide_selected
        slide_controller.is_live = True

        # WHEN: The method is called
        slide_controller.on_slide_selected_index([9])

        # THEN: It should have sent a notification
        mocked_item.is_command.assert_called_once_with()
        mocked_execute.assert_called_once_with('mocked item_slide', [mocked_item, True, 9])
        mocked_update_preview.assert_called_once_with()
        self.assertEqual(0, mocked_preview_widget.change_slide.call_count, 'Change slide should not have been called')
        self.assertEqual(0, mocked_slide_selected.call_count, 'slide_selected should not have been called')
开发者ID:crossroadchurch,项目名称:paul,代码行数:30,代码来源:test_slidecontroller.py

示例3: set_text_test

# 需要导入模块: from tests.functional import MagicMock [as 别名]
# 或者: from tests.functional.MagicMock import assert_called_once_with [as 别名]
    def set_text_test(self, mocked_super):
        """
        Test the reimplemented setText method
        """
        # GIVEN: An instance of InfoLabel and mocked setToolTip method
        info_label = InfoLabel()
        set_tool_tip_mock = MagicMock()
        info_label.setToolTip = set_tool_tip_mock

        # WHEN: Calling the instance method setText
        info_label.setText('Label Text')

        # THEN: The setToolTip and super class setText methods should have been called with the same text
        set_tool_tip_mock.assert_called_once_with('Label Text')
        mocked_super().setText.assert_called_once_with('Label Text')
开发者ID:crossroadchurch,项目名称:paul,代码行数:17,代码来源:test_slidecontroller.py

示例4: test_event

# 需要导入模块: from tests.functional import MagicMock [as 别名]
# 或者: from tests.functional.MagicMock import assert_called_once_with [as 别名]
    def test_event(self):
        """
        Test the reimplemented event method
        """
        # GIVEN: A file path and a QEvent.
        file_path = os.path.join(TEST_PATH, 'church.jpg')
        mocked_file_method = MagicMock(return_value=file_path)
        event = QtCore.QEvent(QtCore.QEvent.FileOpen)
        event.file = mocked_file_method

        # WHEN: Call the vent method.
        result = self.openlp.event(event)

        # THEN: The path should be inserted.
        self.assertTrue(result, "The method should have returned True.")
        mocked_file_method.assert_called_once_with()
        self.assertEqual(self.openlp.args[0], file_path, "The path should be in args.")
开发者ID:imkernel,项目名称:openlp,代码行数:19,代码来源:test_init.py

示例5: service_next_test

# 需要导入模块: from tests.functional import MagicMock [as 别名]
# 或者: from tests.functional.MagicMock import assert_called_once_with [as 别名]
    def service_next_test(self):
        """
        Check that calling the service_next() method adds the next key to the queue and processes the queue
        """
        # GIVEN: A new SlideController instance and mocked out methods
        mocked_keypress_queue = MagicMock()
        mocked_process_queue = MagicMock()
        slide_controller = SlideController(None)
        slide_controller.keypress_queue = mocked_keypress_queue
        slide_controller._process_queue = mocked_process_queue

        # WHEN: The service_next() method is called
        slide_controller.service_next()

        # THEN: The keypress is added to the queue and the queue is processed
        mocked_keypress_queue.append.assert_called_once_with(ServiceItemAction.Next)
        mocked_process_queue.assert_called_once_with()
开发者ID:crossroadchurch,项目名称:paul,代码行数:19,代码来源:test_slidecontroller.py

示例6: update_slide_limits_test

# 需要导入模块: from tests.functional import MagicMock [as 别名]
# 或者: from tests.functional.MagicMock import assert_called_once_with [as 别名]
    def update_slide_limits_test(self, MockedSettings):
        """
        Test that calling the update_slide_limits() method updates the slide limits
        """
        # GIVEN: A mocked out Settings object, a new SlideController and a mocked out main_window
        mocked_value = MagicMock(return_value=10)
        MockedSettings.return_value = MagicMock(value=mocked_value)
        mocked_main_window = MagicMock(advanced_settings_section='advanced')
        Registry.create()
        Registry().register('main_window', mocked_main_window)
        slide_controller = SlideController(None)

        # WHEN: update_slide_limits() is called
        slide_controller.update_slide_limits()

        # THEN: The value of slide_limits should be 10
        mocked_value.assert_called_once_with('advanced/slide limits')
        self.assertEqual(10, slide_controller.slide_limits, 'Slide limits should have been updated to 10')
开发者ID:crossroadchurch,项目名称:paul,代码行数:20,代码来源:test_slidecontroller.py

示例7: add_service_item_without_song_edit_test

# 需要导入模块: from tests.functional import MagicMock [as 别名]
# 或者: from tests.functional.MagicMock import assert_called_once_with [as 别名]
    def add_service_item_without_song_edit_test(self):
        """
        Test the add_service_item() method when song_edit is False
        """
        # GIVEN: A slide controller and a new item to add
        mocked_item = MagicMock()
        mocked_process_item = MagicMock()
        slide_controller = SlideController(None)
        slide_controller._process_item = mocked_process_item
        slide_controller.song_edit = False
        slide_controller.selected_row = 2

        # WHEN: The item is added to the service
        slide_controller.add_service_item(mocked_item)

        # THEN: The item is processed, the slide number is correct, and the song is not editable (or something)
        mocked_item.render.assert_called_once_with()
        self.assertFalse(slide_controller.song_edit, 'song_edit should be False')
        mocked_process_item.assert_called_once_with(mocked_item, 0)
开发者ID:crossroadchurch,项目名称:paul,代码行数:21,代码来源:test_slidecontroller.py

示例8: enable_tool_bar_preview_test

# 需要导入模块: from tests.functional import MagicMock [as 别名]
# 或者: from tests.functional.MagicMock import assert_called_once_with [as 别名]
    def enable_tool_bar_preview_test(self):
        """
        Check that when enable_tool_bar on a preview slide controller is called, enable_preview_tool_bar is called
        """
        # GIVEN: Mocked out enable methods and a real slide controller which is set to live
        mocked_enable_live_tool_bar = MagicMock()
        mocked_enable_preview_tool_bar = MagicMock()
        slide_controller = SlideController(None)
        slide_controller.is_live = False
        slide_controller.enable_live_tool_bar = mocked_enable_live_tool_bar
        slide_controller.enable_preview_tool_bar = mocked_enable_preview_tool_bar
        mocked_service_item = MagicMock()

        # WHEN: enable_tool_bar() is called
        slide_controller.enable_tool_bar(mocked_service_item)

        # THEN: The enable_preview_tool_bar() method is called, not enable_live_tool_bar()
        mocked_enable_preview_tool_bar.assert_called_once_with(mocked_service_item)
        self.assertEqual(0, mocked_enable_live_tool_bar.call_count, 'The live method should not have been called')
开发者ID:crossroadchurch,项目名称:paul,代码行数:21,代码来源:test_slidecontroller.py

示例9: replace_service_manager_item_same_item_test

# 需要导入模块: from tests.functional import MagicMock [as 别名]
# 或者: from tests.functional.MagicMock import assert_called_once_with [as 别名]
    def replace_service_manager_item_same_item_test(self):
        """
        Test that when the service item is the same, the service item is reprocessed
        """
        # GIVEN: A slide controller and a new item to add
        mocked_item = MagicMock()
        mocked_preview_widget = MagicMock()
        mocked_preview_widget.current_slide_number.return_value = 7
        mocked_process_item = MagicMock()
        slide_controller = SlideController(None)
        slide_controller.preview_widget = mocked_preview_widget
        slide_controller._process_item = mocked_process_item
        slide_controller.service_item = mocked_item

        # WHEN: The service item is replaced
        slide_controller.replace_service_manager_item(mocked_item)

        # THEN: The service item should not be processed
        mocked_preview_widget.current_slide_number.assert_called_with()
        mocked_process_item.assert_called_once_with(mocked_item, 7)
开发者ID:crossroadchurch,项目名称:paul,代码行数:22,代码来源:test_slidecontroller.py

示例10: toggle_display_desktop_test

# 需要导入模块: from tests.functional import MagicMock [as 别名]
# 或者: from tests.functional.MagicMock import assert_called_once_with [as 别名]
    def toggle_display_desktop_test(self):
        """
        Check that the toggle_display('desktop') method calls the on_hide_display() method
        """
        # GIVEN: A new SlideController instance.
        mocked_on_blank_display = MagicMock()
        mocked_on_theme_display = MagicMock()
        mocked_on_hide_display = MagicMock()
        slide_controller = SlideController(None)
        slide_controller.on_blank_display = mocked_on_blank_display
        slide_controller.on_theme_display = mocked_on_theme_display
        slide_controller.on_hide_display = mocked_on_hide_display

        # WHEN: toggle_display() is called with an argument of "desktop"
        slide_controller.toggle_display('desktop')

        # THEN: Only on_hide_display() should have been called with an argument of True
        mocked_on_hide_display.assert_called_once_with(True)
        self.assertEqual(0, mocked_on_blank_display.call_count, 'on_blank_display should not have been called')
        self.assertEqual(0, mocked_on_theme_display.call_count, 'on_theme_display should not have been called')
开发者ID:crossroadchurch,项目名称:paul,代码行数:22,代码来源:test_slidecontroller.py

示例11: refresh_service_item_image_test

# 需要导入模块: from tests.functional import MagicMock [as 别名]
# 或者: from tests.functional.MagicMock import assert_called_once_with [as 别名]
    def refresh_service_item_image_test(self):
        """
        Test that the refresh_service_item() method refreshes a image service item
        """
        # GIVEN: A mock service item and a fresh slide controller
        mocked_service_item = MagicMock()
        mocked_service_item.is_text.return_value = False
        mocked_service_item.is_image.return_value = True
        mocked_process_item = MagicMock()
        slide_controller = SlideController(None)
        slide_controller.service_item = mocked_service_item
        slide_controller._process_item = mocked_process_item
        slide_controller.selected_row = 5

        # WHEN: The refresh_service_item method() is called
        slide_controller.refresh_service_item()

        # THEN: The item should be re-processed
        mocked_service_item.is_text.assert_called_once_with()
        mocked_service_item.is_image.assert_called_once_with()
        mocked_service_item.render.assert_called_once_with()
        mocked_process_item.assert_called_once_with(mocked_service_item, 5)
开发者ID:crossroadchurch,项目名称:paul,代码行数:24,代码来源:test_slidecontroller.py

示例12: toggle_display_show_test

# 需要导入模块: from tests.functional import MagicMock [as 别名]
# 或者: from tests.functional.MagicMock import assert_called_once_with [as 别名]
    def toggle_display_show_test(self):
        """
        Check that the toggle_display('show') method calls all the on_X_display() methods
        """
        # GIVEN: A new SlideController instance.
        mocked_on_blank_display = MagicMock()
        mocked_on_theme_display = MagicMock()
        mocked_on_hide_display = MagicMock()
        slide_controller = SlideController(None)
        slide_controller.on_blank_display = mocked_on_blank_display
        slide_controller.on_theme_display = mocked_on_theme_display
        slide_controller.on_hide_display = mocked_on_hide_display

        # WHEN: toggle_display() is called with an argument of "show"
        slide_controller.toggle_display('show')

        # THEN: All the on_X_display() methods should have been called with an argument of False
        mocked_on_blank_display.assert_called_once_with(False)
        mocked_on_theme_display.assert_called_once_with(False)
        mocked_on_hide_display.assert_called_once_with(False)
开发者ID:crossroadchurch,项目名称:paul,代码行数:22,代码来源:test_slidecontroller.py


注:本文中的tests.functional.MagicMock.assert_called_once_with方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。