• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python functional.MagicMock类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: paint_event_text_fits_test

    def paint_event_text_fits_test(self):
        """
        Test the paintEvent method when text fits the label
        """
        font = QtGui.QFont()
        metrics = QtGui.QFontMetrics(font)

        with patch('openlp.core.ui.slidecontroller.QtGui.QLabel'), \
                patch('openlp.core.ui.slidecontroller.QtGui.QPainter') as mocked_qpainter:

            # GIVEN: An instance of InfoLabel, with mocked text return, width and rect methods
            info_label = InfoLabel()
            test_string = 'Label Text'
            mocked_rect = MagicMock()
            mocked_text = MagicMock()
            mocked_width = MagicMock()
            mocked_text.return_value = test_string
            info_label.rect = mocked_rect
            info_label.text = mocked_text
            info_label.width = mocked_width

            # WHEN: The instance is wider than its text, and the paintEvent method is called
            info_label.width.return_value = metrics.boundingRect(test_string).width() + 10
            info_label.paintEvent(MagicMock())

            # THEN: The text should be drawn centered with the complete test_string
            mocked_qpainter().drawText.assert_called_once_with(mocked_rect(), QtCore.Qt.AlignCenter, test_string)
开发者ID:crossroadchurch,项目名称:paul,代码行数:27,代码来源:test_slidecontroller.py


示例2: on_slide_selected_index_service_item_command_test

    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,代码行数:28,代码来源:test_slidecontroller.py


示例3: on_slide_selected_index_service_item_not_command_test

    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,代码行数:27,代码来源:test_slidecontroller.py


示例4: test_load_objects

    def test_load_objects(self, mocked_set_case_insensitive_completer):
        """
        Test the _load_objects() method
        """
        # GIVEN: A song edit form and some mocked stuff
        mocked_class = MagicMock()
        mocked_class.name = 'Author'
        mocked_combo = MagicMock()
        mocked_combo.count.return_value = 0
        mocked_cache = MagicMock()
        mocked_object = MagicMock()
        mocked_object.name = 'Charles'
        mocked_object.id = 1
        mocked_manager = MagicMock()
        mocked_manager.get_all_objects.return_value = [mocked_object]
        self.edit_song_form.manager = mocked_manager

        # WHEN: _load_objects() is called
        self.edit_song_form._load_objects(mocked_class, mocked_combo, mocked_cache)

        # THEN: All the correct methods should have been called
        self.edit_song_form.manager.get_all_objects.assert_called_once_with(mocked_class)
        mocked_combo.clear.assert_called_once_with()
        mocked_combo.count.assert_called_once_with()
        mocked_combo.addItem.assert_called_once_with('Charles')
        mocked_cache.append.assert_called_once_with('Charles')
        mocked_combo.setItemData.assert_called_once_with(0, 1)
        mocked_set_case_insensitive_completer.assert_called_once_with(mocked_cache, mocked_combo)
        mocked_combo.setCurrentIndex.assert_called_once_with(-1)
        mocked_combo.setCurrentText.assert_called_once_with('')
开发者ID:imkernel,项目名称:openlp,代码行数:30,代码来源:test_editsongform.py


示例5: on_go_live_service_manager_test

    def on_go_live_service_manager_test(self):
        """
        Test that when the on_go_live() method is called the message is sent to the live controller and focus is
        set correctly.
        """
        # GIVEN: A new SlideController instance and service manager preview then pressing go live should respond
        mocked_display = MagicMock()
        mocked_service_manager = MagicMock()
        mocked_live_controller = MagicMock()
        mocked_preview_widget = MagicMock()
        mocked_service_item = MagicMock()
        mocked_service_item.from_service = True
        mocked_service_item.unique_identifier = 42
        mocked_preview_widget.current_slide_number.return_value = 1
        mocked_preview_widget.slide_count.return_value = 2
        mocked_live_controller.preview_widget = MagicMock()
        Registry.create()
        Registry().register('live_controller', mocked_live_controller)
        Registry().register('service_manager', mocked_service_manager)
        slide_controller = SlideController(None)
        slide_controller.service_item = mocked_service_item
        slide_controller.preview_widget = mocked_preview_widget
        slide_controller.display = mocked_display

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

        # THEN: the service manager should have the service item and the focus set to live
        mocked_service_manager.preview_live.assert_called_once_with(42, 1)
        mocked_live_controller.preview_widget.setFocus.assert_called_once_with()
开发者ID:crossroadchurch,项目名称:paul,代码行数:30,代码来源:test_slidecontroller.py


示例6: test_build_song_footer_base_ccli

    def test_build_song_footer_base_ccli(self):
        """
        Test build songs footer with basic song and a CCLI number
        """
        # GIVEN: A Song and a Service Item and a configured CCLI license
        mock_song = MagicMock()
        mock_song.title = 'My Song'
        mock_song.copyright = 'My copyright'
        service_item = ServiceItem(None)
        Settings().setValue('core/ccli number', '1234')

        # WHEN: I generate the Footer with default settings
        self.media_item.generate_footer(service_item, mock_song)

        # THEN: I get the following Array returned
        self.assertEqual(service_item.raw_footer, ['My Song', 'My copyright', 'CCLI License: 1234'],
                         'The array should be returned correctly with a song, an author, copyright and ccli')

        # WHEN: I amend the CCLI value
        Settings().setValue('core/ccli number', '4321')
        self.media_item.generate_footer(service_item, mock_song)

        # THEN: I would get an amended footer string
        self.assertEqual(service_item.raw_footer, ['My Song', 'My copyright', 'CCLI License: 4321'],
                         'The array should be returned correctly with a song, an author, copyright and amended ccli')
开发者ID:imkernel,项目名称:openlp,代码行数:25,代码来源:test_mediaitem.py


示例7: test_build_song_footer_base_songbook

    def test_build_song_footer_base_songbook(self):
        """
        Test build songs footer with basic song and multiple songbooks
        """
        # GIVEN: A Song and a Service Item
        song = Song()
        song.title = 'My Song'
        song.copyright = 'My copyright'
        song.authors_songs = []
        song.songbook_entries = []
        song.ccli_number = ''
        book1 = MagicMock()
        book1.name = "My songbook"
        book2 = MagicMock()
        book2.name = "Thy songbook"
        song.songbookentries = []
        song.add_songbook_entry(book1, '12')
        song.add_songbook_entry(book2, '502A')
        service_item = ServiceItem(None)

        # WHEN: I generate the Footer with default settings
        self.media_item.generate_footer(service_item, song)

        # THEN: The songbook should not be in the footer
        self.assertEqual(service_item.raw_footer, ['My Song', 'My copyright'])

        # WHEN: I activate the "display songbook" option
        self.media_item.display_songbook = True
        self.media_item.generate_footer(service_item, song)

        # THEN: The songbook should be in the footer
        self.assertEqual(service_item.raw_footer, ['My Song', 'My copyright', 'My songbook #12, Thy songbook #502A'])
开发者ID:imkernel,项目名称:openlp,代码行数:32,代码来源:test_mediaitem.py


示例8: test_check_media

    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)
开发者ID:imkernel,项目名称:openlp,代码行数:33,代码来源:test_systemplayer.py


示例9: test_save_file_raises_permission_error

    def test_save_file_raises_permission_error(self, mocked_save_file_as, mocked_zipfile, mocked_shutil_copy):
        """
        Test that when a PermissionError is raised when trying to save a file, it is handled correctly
        """
        # GIVEN: A service manager, a service to save
        mocked_main_window = MagicMock()
        mocked_main_window.service_manager_settings_section = 'servicemanager'
        Registry().register('main_window', mocked_main_window)
        Registry().register('application', MagicMock())
        service_manager = ServiceManager(None)
        service_manager._file_name = os.path.join('temp', 'filename.osz')
        service_manager._save_lite = False
        service_manager.service_items = []
        service_manager.service_theme = 'Default'
        service_manager.service_manager_list = MagicMock()
        mocked_save_file_as.return_value = True
        mocked_zipfile.ZipFile.return_value = MagicMock()
        mocked_shutil_copy.side_effect = PermissionError

        # WHEN: The service is saved and a PermissionError is thrown
        result = service_manager.save_file()

        # THEN: The "save_as" method is called to save the service
        self.assertTrue(result)
        mocked_save_file_as.assert_called_with()
开发者ID:imkernel,项目名称:openlp,代码行数:25,代码来源:test_servicemanager.py


示例10: build_song_footer_base_songbook_test

    def build_song_footer_base_songbook_test(self):
        """
        Test build songs footer with basic song and a songbook
        """
        # GIVEN: A Song and a Service Item
        mock_song = MagicMock()
        mock_song.title = 'My Song'
        mock_song.copyright = 'My copyright'
        mock_song.book = MagicMock()
        mock_song.book.name = "My songbook"
        mock_song.song_number = 12
        service_item = ServiceItem(None)

        # WHEN: I generate the Footer with default settings
        self.media_item.generate_footer(service_item, mock_song)

        # THEN: The songbook should not be in the footer
        self.assertEqual(service_item.raw_footer, ['My Song', 'My copyright'])

        # WHEN: I activate the "display songbook" option
        self.media_item.display_songbook = True
        self.media_item.generate_footer(service_item, mock_song)

        # THEN: The songbook should be in the footer
        self.assertEqual(service_item.raw_footer, ['My Song', 'My copyright', 'My songbook #12'])
开发者ID:crossroadchurch,项目名称:paul,代码行数:25,代码来源:test_mediaitem.py


示例11: test_build_html_video

    def test_build_html_video(self, MockedSettings, Mocked_build_html):
        # GIVEN: Mocked display
        display = MagicMock()
        mocked_media_controller = MagicMock()
        Registry.create()
        Registry().register('media_controller', mocked_media_controller)
        main_display = MainDisplay(display)
        main_display.frame = MagicMock()
        mocked_settings = MagicMock()
        mocked_settings.value.return_value = False
        MockedSettings.return_value = mocked_settings
        main_display.shake_web_view = MagicMock()
        service_item = MagicMock()
        service_item.theme_data = MagicMock()
        service_item.theme_data.background_type = 'video'
        service_item.theme_data.theme_name = 'name'
        service_item.theme_data.background_filename = 'background_filename'
        mocked_plugin = MagicMock()
        display.plugin_manager = PluginManager()
        display.plugin_manager.plugins = [mocked_plugin]
        main_display.web_view = MagicMock()

        # WHEN: build_html is called with a normal service item and a video theme.
        main_display.build_html(service_item)

        # THEN: the following should had not been called
        self.assertEquals(main_display.web_view.setHtml.call_count, 1, 'setHTML should be called once')
        self.assertEquals(main_display.media_controller.video.call_count, 1,
                          'Media Controller video should have been called once')
开发者ID:imkernel,项目名称:openlp,代码行数:29,代码来源:test_maindisplay.py


示例12: test_process_chapters

    def test_process_chapters(self, mocked_open, mocked_os):
        """
        Test the process_chapters() method
        """
        # GIVEN: A WordProject importer and a bunch of mocked things
        importer = WordProjectBible(MagicMock(), path='.', name='.', filename='kj.zip')
        importer.base_dir = ''
        importer.stop_import_flag = False
        importer.language_id = 'en'
        mocked_open.return_value.__enter__.return_value.read.return_value = CHAPTER_PAGE
        mocked_os.path.join.side_effect = lambda *x: ''.join(x)
        mocked_os.path.normpath.side_effect = lambda x: x
        mocked_db_book = MagicMock()
        mocked_db_book.name = 'Genesis'
        book_id = 1
        book_link = '01/1.htm'

        # WHEN: process_chapters() is called
        with patch.object(importer, 'set_current_chapter') as mocked_set_current_chapter, \
                patch.object(importer, 'process_verses') as mocked_process_verses:
            importer.process_chapters(mocked_db_book, book_id, book_link)

        # THEN: The right methods should have been called
        expected_set_current_chapter_calls = [call('Genesis', ch) for ch in range(1, 51)]
        expected_process_verses_calls = [call(mocked_db_book, 1, ch) for ch in range(1, 51)]
        mocked_os.path.join.assert_called_once_with('', '01/1.htm')
        mocked_open.assert_called_once_with('01/1.htm', encoding='utf-8', errors='ignore')
        assert mocked_set_current_chapter.call_args_list == expected_set_current_chapter_calls
        assert mocked_process_verses.call_args_list == expected_process_verses_calls
开发者ID:imkernel,项目名称:openlp,代码行数:29,代码来源:test_wordprojectimport.py


示例13: paint_event_text_doesnt_fit_test

    def paint_event_text_doesnt_fit_test(self):
        """
        Test the paintEvent method when text fits the label
        """
        font = QtGui.QFont()
        metrics = QtGui.QFontMetrics(font)

        with patch('openlp.core.ui.slidecontroller.QtGui.QLabel'), \
                patch('openlp.core.ui.slidecontroller.QtGui.QPainter') as mocked_qpainter:

            # GIVEN: An instance of InfoLabel, with mocked text return, width and rect methods
            info_label = InfoLabel()
            test_string = 'Label Text'
            mocked_rect = MagicMock()
            mocked_text = MagicMock()
            mocked_width = MagicMock()
            mocked_text.return_value = test_string
            info_label.rect = mocked_rect
            info_label.text = mocked_text
            info_label.width = mocked_width

            # WHEN: The instance is narrower than its text, and the paintEvent method is called
            label_width = metrics.boundingRect(test_string).width() - 10
            info_label.width.return_value = label_width
            info_label.paintEvent(MagicMock())

            # THEN: The text should be drawn aligned left with an elided test_string
            elided_test_string = metrics.elidedText(test_string, QtCore.Qt.ElideRight, label_width)
            mocked_qpainter().drawText.assert_called_once_with(mocked_rect(), QtCore.Qt.AlignLeft, elided_test_string)
开发者ID:crossroadchurch,项目名称:paul,代码行数:29,代码来源:test_slidecontroller.py


示例14: setUp

 def setUp(self):
     mocked_plugin = MagicMock()
     mocked_plugin.settings_section = 'presentations'
     Settings().extend_default_settings(__default_settings__)
     self.file_name = os.path.join(TEST_RESOURCES_PATH, 'presentations', 'test.pptx')
     self.ppc = ImpressController(mocked_plugin)
     self.doc = ImpressDocument(self.ppc, self.file_name)
开发者ID:imkernel,项目名称:openlp,代码行数:7,代码来源:test_impresscontroller.py


示例15: test_write_theme_same_image

    def test_write_theme_same_image(self):
        """
        Test that we don't try to overwrite a theme background image with itself
        """
        # GIVEN: A new theme manager instance, with mocked builtins.open, shutil.copyfile,
        #        theme, check_directory_exists and thememanager-attributes.
        with patch('builtins.open') as mocked_open, \
                patch('openlp.core.ui.thememanager.shutil.copyfile') as mocked_copyfile, \
                patch('openlp.core.ui.thememanager.check_directory_exists') as mocked_check_directory_exists:
            mocked_open.return_value = MagicMock()
            theme_manager = ThemeManager(None)
            theme_manager.old_background_image = None
            theme_manager.generate_and_save_image = MagicMock()
            theme_manager.path = ''
            mocked_theme = MagicMock()
            mocked_theme.theme_name = 'themename'
            mocked_theme.extract_formatted_xml = MagicMock()
            mocked_theme.extract_formatted_xml.return_value = 'fake_theme_xml'.encode()

            # WHEN: Calling _write_theme with path to the same image, but the path written slightly different
            file_name1 = os.path.join(TEST_RESOURCES_PATH, 'church.jpg')
            # Do replacement from end of string to avoid problems with path start
            file_name2 = file_name1[::-1].replace(os.sep, os.sep + os.sep, 2)[::-1]
            theme_manager._write_theme(mocked_theme, file_name1, file_name2)

            # THEN: The mocked_copyfile should not have been called
            self.assertFalse(mocked_copyfile.called, 'shutil.copyfile should not be called')
开发者ID:imkernel,项目名称:openlp,代码行数:27,代码来源:test_thememanager.py


示例16: test_write_theme_diff_images

    def test_write_theme_diff_images(self):
        """
        Test that we do overwrite a theme background image when a new is submitted
        """
        # GIVEN: A new theme manager instance, with mocked builtins.open, shutil.copyfile,
        #        theme, check_directory_exists and thememanager-attributes.
        with patch('builtins.open') as mocked_open, \
                patch('openlp.core.ui.thememanager.shutil.copyfile') as mocked_copyfile, \
                patch('openlp.core.ui.thememanager.check_directory_exists') as mocked_check_directory_exists:
            mocked_open.return_value = MagicMock()
            theme_manager = ThemeManager(None)
            theme_manager.old_background_image = None
            theme_manager.generate_and_save_image = MagicMock()
            theme_manager.path = ''
            mocked_theme = MagicMock()
            mocked_theme.theme_name = 'themename'
            mocked_theme.extract_formatted_xml = MagicMock()
            mocked_theme.extract_formatted_xml.return_value = 'fake_theme_xml'.encode()

            # WHEN: Calling _write_theme with path to different images
            file_name1 = os.path.join(TEST_RESOURCES_PATH, 'church.jpg')
            file_name2 = os.path.join(TEST_RESOURCES_PATH, 'church2.jpg')
            theme_manager._write_theme(mocked_theme, file_name1, file_name2)

            # THEN: The mocked_copyfile should not have been called
            self.assertTrue(mocked_copyfile.called, 'shutil.copyfile should be called')
开发者ID:imkernel,项目名称:openlp,代码行数:26,代码来源:test_thememanager.py


示例17: test_start_presentation

    def test_start_presentation(self, media_mock):
        """
        Find and chose a controller to play a presentations.
        """
        # GIVEN: A single controller and service item wanting to use the controller
        mock_item = MagicMock()
        mock_item.processor = 'Powerpoint'
        mock_item.get_frame_path.return_value = "test.ppt"
        self.media_item.automatic = False
        mocked_controller = MagicMock()
        mocked_controller.available = True
        mocked_controller.supports = ['ppt']
        controllers = {
            'Powerpoint': mocked_controller
        }
        ml = MessageListener(self.media_item)
        ml.media_item = self.media_item
        ml.controllers = controllers
        ml.preview_handler = MagicMock()
        ml.timer = MagicMock()

        # WHEN: request the presentation to start
        ml.startup([mock_item, False, False, False])

        # THEN: The controllers will be setup.
        self.assertTrue(len(controllers), 'We have loaded a controller')
开发者ID:imkernel,项目名称:openlp,代码行数:26,代码来源:test_messagelistener.py


示例18: accept_with_inactive_plugins_test

    def accept_with_inactive_plugins_test(self):
        """
        Test that the accept() method works correctly when some of the plugins are inactive
        """
        # GIVEN: A visible general tab and an invisible theme tab in a Settings Form
        settings_form = SettingsForm(None)
        general_tab = QtGui.QWidget(None)
        general_tab.tab_title = 'mock-general'
        general_tab.tab_title_visible = 'Mock General'
        general_tab.icon_path = ':/icon/openlp-logo-16x16.png'
        mocked_general_save = MagicMock()
        general_tab.save = mocked_general_save
        settings_form.insert_tab(general_tab, is_visible=True)
        themes_tab = QtGui.QWidget(None)
        themes_tab.tab_title = 'mock-themes'
        themes_tab.tab_title_visible = 'Mock Themes'
        themes_tab.icon_path = ':/icon/openlp-logo-16x16.png'
        mocked_theme_save = MagicMock()
        themes_tab.save = mocked_theme_save
        settings_form.insert_tab(themes_tab, is_visible=False)

        # WHEN: The accept() method is called
        settings_form.accept()

        # THEN: The general tab's save() method should have been called, but not the themes tab
        mocked_general_save.assert_called_with()
        self.assertEqual(0, mocked_theme_save.call_count, 'The Themes tab\'s save() should not have been called')
开发者ID:crossroadchurch,项目名称:paul,代码行数:27,代码来源:test_settingsform.py


示例19: pyodbc_exception_test

    def pyodbc_exception_test(self):
        """
        Test that exceptions raised by pyodbc are handled
        """
        # GIVEN: A mocked out SongImport class, a mocked out pyodbc module, a mocked out translate method,
        #       a mocked "manager" and a mocked out log_error method.
        with patch('openlp.plugins.songs.lib.importers.worshipcenterpro.SongImport'), \
                patch('openlp.plugins.songs.lib.importers.worshipcenterpro.pyodbc.connect') as mocked_pyodbc_connect, \
                patch('openlp.plugins.songs.lib.importers.worshipcenterpro.translate') as mocked_translate:
            mocked_manager = MagicMock()
            mocked_log_error = MagicMock()
            mocked_translate.return_value = 'Translated Text'
            importer = WorshipCenterProImport(mocked_manager, filenames=[])
            importer.log_error = mocked_log_error
            importer.import_source = 'import_source'
            pyodbc_errors = [pyodbc.DatabaseError, pyodbc.IntegrityError, pyodbc.InternalError, pyodbc.OperationalError]
            mocked_pyodbc_connect.side_effect = pyodbc_errors

            # WHEN: Calling the do_import method
            for effect in pyodbc_errors:
                return_value = importer.do_import()

                # THEN: do_import should return None, and pyodbc, translate & log_error are called with known calls
                self.assertIsNone(return_value, 'do_import should return None when pyodbc raises an exception.')
                mocked_pyodbc_connect.assert_called_with('DRIVER={Microsoft Access Driver (*.mdb)};DBQ=import_source')
                mocked_translate.assert_called_with('SongsPlugin.WorshipCenterProImport',
                                                    'Unable to connect the WorshipCenter Pro database.')
                mocked_log_error.assert_called_with('import_source', 'Translated Text')
开发者ID:crossroadchurch,项目名称:paul,代码行数:28,代码来源:test_worshipcenterproimport.py


示例20: play_media_wait_state_not_playing_test

    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)
开发者ID:crossroadchurch,项目名称:paul,代码行数:25,代码来源:test_vlcplayer.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python actions.login函数代码示例发布时间:2022-05-27
下一篇:
Python functional.patch函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap