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

Python patch.object函数代码示例

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

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



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

示例1: 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


示例2: test_do_import_breaks_on_stop

    def test_do_import_breaks_on_stop(self, mocked_pyodbc):
        """
        Test the MediaShoutImport do_import stops when the user presses the cancel button
        """
        SongRecord = namedtuple('SongRecord', 'Record, Title, Author, Copyright, SongID, CCLI, Notes')
        song = SongRecord(1, 'Amazing Grace', 'William Wilberforce', 'Public Domain', 1, '654321', '')

        # GIVEN: A MediaShoutImport instance and a bunch of stuff mocked out
        importer = MediaShoutImport(MagicMock(), filename='mediashout.db')
        mocked_cursor = MagicMock()
        mocked_cursor.fetchall.return_value = [song]
        mocked_connection = MagicMock()
        mocked_connection.cursor.return_value = mocked_cursor
        mocked_pyodbc.connect.return_value = mocked_connection

        # WHEN: do_import is called, but cancelled
        with patch.object(importer, 'import_wizard') as mocked_import_wizard, \
                patch.object(importer, 'process_song') as mocked_process_song:
            importer.stop_import_flag = True
            importer.do_import()

        # THEN: The songs should have been imported
        mocked_cursor.execute.assert_called_once_with(
            'SELECT Record, Title, Author, Copyright, SongID, CCLI, Notes FROM Songs ORDER BY Title')
        mocked_process_song.assert_not_called()
开发者ID:imkernel,项目名称:openlp,代码行数:25,代码来源:test_mediashout.py


示例3: update_ui_dvd_test

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


示例4: 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


示例5: test_update_ui

    def test_update_ui(self):
        """
        Test the update_ui() method on the SystemPlayer
        """
        # GIVEN: A SystemPlayer instance
        player = SystemPlayer(self)
        player.state = MediaState.Playing
        mocked_display = MagicMock()
        mocked_display.media_player.state.return_value = QtMultimedia.QMediaPlayer.PausedState
        mocked_display.controller.media_info.end_time = 1
        mocked_display.media_player.position.return_value = 2
        mocked_display.controller.seek_slider.isSliderDown.return_value = False

        # WHEN: update_ui() is called
        with patch.object(player, 'stop') as mocked_stop, \
                patch.object(player, 'set_visible') as mocked_set_visible:
            player.update_ui(mocked_display)

        # THEN: The UI is updated
        expected_stop_calls = [call(mocked_display), call(mocked_display)]
        expected_position_calls = [call(), call()]
        expected_block_signals_calls = [call(True), call(False)]
        mocked_display.media_player.state.assert_called_once_with()
        self.assertEqual(2, mocked_stop.call_count)
        self.assertEqual(expected_stop_calls, mocked_stop.call_args_list)
        self.assertEqual(2, mocked_display.media_player.position.call_count)
        self.assertEqual(expected_position_calls, mocked_display.media_player.position.call_args_list)
        mocked_set_visible.assert_called_once_with(mocked_display, False)
        mocked_display.controller.seek_slider.isSliderDown.assert_called_once_with()
        self.assertEqual(expected_block_signals_calls,
                         mocked_display.controller.seek_slider.blockSignals.call_args_list)
        mocked_display.controller.seek_slider.setSliderPosition.assert_called_once_with(2)
开发者ID:imkernel,项目名称:openlp,代码行数:32,代码来源:test_systemplayer.py


示例6: get_language_accepted_test

    def get_language_accepted_test(self):
        """
        Test the BibleImport.get_language method when the user accepts the dialog box
        """
        # GIVEN: A mocked LanguageForm with an exec method which returns QtDialog.Accepted an instance of BibleDB and
        #       a combobox with the selected item data as 10
        with patch.object(BibleDB, 'save_meta'), patch.object(BibleDB, '_setup'), \
                patch('openlp.plugins.bibles.forms.LanguageForm') as mocked_language_form:

            # The integer value of QtDialog.Accepted is 1. Using the enumeration causes a seg fault for some reason
            mocked_language_form_instance = MagicMock(**{'exec.return_value': 1,
                                                         'language_combo_box.itemData.return_value': 10})
            mocked_language_form.return_value = mocked_language_form_instance
            instance = BibleImport(MagicMock())
            mocked_wizard = MagicMock()
            instance.wizard = mocked_wizard

            # WHEN: Calling get_language()
            result = instance.get_language('Bible Name')

            # THEN: get_language() should return the id of the selected language in the combo box
            mocked_language_form.assert_called_once_with(mocked_wizard)
            mocked_language_form_instance.exec.assert_called_once_with('Bible Name')
            self.assertEqual(result, 10, 'get_language() should return the id of the language the user has chosen when '
                                         'they accept the dialog box')
开发者ID:imkernel,项目名称:openlp,代码行数:25,代码来源:test_bibleimport.py


示例7: test_play_is_preview

    def test_play_is_preview(self, mocked_functools):
        """
        Test the play() method of the SystemPlayer on the preview display
        """
        # GIVEN: A SystemPlayer instance and a mocked display
        mocked_functools.partial.return_value = 'function'
        player = SystemPlayer(self)
        mocked_display = MagicMock()
        mocked_display.controller.is_live = False
        mocked_display.controller.media_info.start_time = 1
        mocked_display.controller.media_info.volume = 1

        # WHEN: play() is called
        with patch.object(player, 'get_preview_state') as mocked_get_preview_state, \
                patch.object(player, 'seek') as mocked_seek, \
                patch.object(player, 'volume') as mocked_volume, \
                patch.object(player, 'set_state') as mocked_set_state:
            mocked_get_preview_state.return_value = QtMultimedia.QMediaPlayer.PlayingState
            result = player.play(mocked_display)

        # THEN: the media file is played
        mocked_get_preview_state.assert_called_once_with()
        mocked_display.media_player.play.assert_called_once_with()
        mocked_seek.assert_called_once_with(mocked_display, 1000)
        mocked_volume.assert_called_once_with(mocked_display, 1)
        mocked_display.media_player.durationChanged.connect.assert_called_once_with('function')
        mocked_set_state.assert_called_once_with(MediaState.Playing, mocked_display)
        mocked_display.video_widget.raise_.assert_called_once_with()
        self.assertTrue(result)
开发者ID:imkernel,项目名称:openlp,代码行数:29,代码来源:test_systemplayer.py


示例8: play_test

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


示例9: validate_xml_file_success_test

    def validate_xml_file_success_test(self):
        """
        Test that validate_xml_file returns True with valid XML
        """
        # GIVEN: Some test data with an OpenSong Bible "bible" root tag
        with patch.object(BibleImport, 'parse_xml', return_value=objectify.fromstring('<bible></bible>')), \
                patch.object(BibleImport, 'is_compressed', return_value=False):
            importer = BibleImport(MagicMock(), path='.', name='.', filename='')

            # WHEN: Calling validate_xml_file
            result = importer.validate_xml_file('file.name', 'bible')

            # THEN: True should be returned
            self.assertTrue(result)
开发者ID:imkernel,项目名称:openlp,代码行数:14,代码来源:test_bibleimport.py


示例10: test_on_search_results_widget_selection_changed

    def test_on_search_results_widget_selection_changed(self):
        """
        Test that the view button is updated when the search results list is changed
        """
        # GIVEN: A SongSelect form
        ssform = SongSelectForm(None, MagicMock(), MagicMock())

        # WHEN: There is at least 1 item selected
        with patch.object(ssform, 'search_results_widget') as mocked_search_results_widget, \
                patch.object(ssform, 'view_button') as mocked_view_button:
            mocked_search_results_widget.selectedItems.return_value = [1]
            ssform.on_search_results_widget_selection_changed()

        # THEN: The view button should be enabled
        mocked_view_button.setEnabled.assert_called_with(True)
开发者ID:imkernel,项目名称:openlp,代码行数:15,代码来源:test_songselect.py


示例11: test_on_back_button_clicked

    def test_on_back_button_clicked(self):
        """
        Test that when the back button is clicked, the stacked widget is set back one page
        """
        # GIVEN: A SongSelect form
        ssform = SongSelectForm(None, MagicMock(), MagicMock())

        # WHEN: The back button is clicked
        with patch.object(ssform, 'stacked_widget') as mocked_stacked_widget, \
                patch.object(ssform, 'search_combobox') as mocked_search_combobox:
            ssform.on_back_button_clicked()

        # THEN: The stacked widget should be set back one page
        mocked_stacked_widget.setCurrentIndex.assert_called_with(1)
        mocked_search_combobox.setFocus.assert_called_with()
开发者ID:imkernel,项目名称:openlp,代码行数:15,代码来源:test_songselect.py


示例12: validate_xml_file_parse_xml_fails_test

    def validate_xml_file_parse_xml_fails_test(self):
        """
        Test that validate_xml_file raises a ValidationError when parse_xml returns None
        """
        # GIVEN: A mocked parse_xml which returns None
        with patch.object(BibleImport, 'parse_xml', return_value=None), \
                patch.object(BibleImport, 'is_compressed', return_value=False):
            importer = BibleImport(MagicMock(), path='.', name='.', filename='')

            # WHEN: Calling validate_xml_file
            # THEN: ValidationError should be raised, with the message 'Error when opening file'
            #       the user that an OpenSong bible was found
            with self.assertRaises(ValidationError) as context:
                importer.validate_xml_file('file.name', 'xbible')
            self.assertEqual(context.exception.msg, 'Error when opening file')
开发者ID:imkernel,项目名称:openlp,代码行数:15,代码来源:test_bibleimport.py


示例13: test_on_search_shortcut_triggered_shows_media_manager

    def test_on_search_shortcut_triggered_shows_media_manager(self):
        """
        Test that the media manager is made visible when the search shortcut is triggered
        """
        # GIVEN: A build main window set up for testing
        with patch.object(self.main_window, 'media_manager_dock') as mocked_media_manager_dock, \
                patch.object(self.main_window, 'media_tool_box') as mocked_media_tool_box:
            mocked_media_manager_dock.isVisible.return_value = False
            mocked_media_tool_box.currentWidget.return_value = None

            # WHEN: The search shortcut is triggered
            self.main_window.on_search_shortcut_triggered()

            # THEN: The media manager dock is made visible
            mocked_media_manager_dock.setVisible.assert_called_with(True)
开发者ID:imkernel,项目名称:openlp,代码行数:15,代码来源:test_mainwindow.py


示例14: load_test

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


示例15: test_on_view_button_clicked

    def test_on_view_button_clicked(self):
        """
        Test that a song is retrieved when the view button is clicked
        """
        # GIVEN: A SongSelect form
        ssform = SongSelectForm(None, MagicMock(), MagicMock())
        expected_song = {'title': 'Amazing Grace'}

        # WHEN: A song result is double-clicked
        with patch.object(ssform, '_view_song') as mocked_view_song, \
                patch.object(ssform, 'search_results_widget') as mocked_search_results_widget:
            mocked_search_results_widget.currentItem.return_value = expected_song
            ssform.on_view_button_clicked()

        # THEN: The song is fetched and shown to the user
        mocked_view_song.assert_called_with(expected_song)
开发者ID:imkernel,项目名称:openlp,代码行数:16,代码来源:test_songselect.py


示例16: test_on_cancel_button_clicked

    def test_on_cancel_button_clicked(self):
        """
        Test that the cancel button click slot shuts down the threads correctly
        """
        # GIVEN: A FRW, some mocked threads and workers (that isn't quite done) and other mocked stuff
        frw = FirstTimeForm(None)
        frw.initialize(MagicMock())
        mocked_worker = MagicMock()
        mocked_thread = MagicMock()
        mocked_thread.isRunning.side_effect = [True, False]
        frw.theme_screenshot_workers.append(mocked_worker)
        frw.theme_screenshot_threads.append(mocked_thread)
        with patch('openlp.core.ui.firsttimeform.time') as mocked_time, \
                patch.object(frw.application, 'set_normal_cursor') as mocked_set_normal_cursor:

            # WHEN: on_cancel_button_clicked() is called
            frw.on_cancel_button_clicked()

            # THEN: The right things should be called in the right order
            self.assertTrue(frw.was_cancelled, 'The was_cancelled property should have been set to True')
            mocked_worker.set_download_canceled.assert_called_with(True)
            mocked_thread.isRunning.assert_called_with()
            self.assertEqual(2, mocked_thread.isRunning.call_count, 'isRunning() should have been called twice')
            mocked_time.sleep.assert_called_with(0.1)
            self.assertEqual(1, mocked_time.sleep.call_count, 'sleep() should have only been called once')
            mocked_set_normal_cursor.assert_called_with()
开发者ID:imkernel,项目名称:openlp,代码行数:26,代码来源:test_firsttimeform.py


示例17: test_signals_error

    def test_signals_error(self):
        """
        Test the signals() signal of the CheckMediaWorker class with a "error" origin
        """
        # GIVEN: A CheckMediaWorker instance
        worker = CheckMediaWorker('file.ogv')

        # WHEN: signals() is called with error and BufferedMedia
        with patch.object(worker, 'stop') as mocked_stop, \
                patch.object(worker, 'finished') as mocked_finished:
            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()
        self.assertFalse(worker.result)
开发者ID:imkernel,项目名称:openlp,代码行数:16,代码来源:test_systemplayer.py


示例18: test_on_send_report_button_clicked

    def test_on_send_report_button_clicked(self,
                                           mocked_qt,
                                           mocked_add_query_item,
                                           mocked_qurl,
                                           mocked_file_dialog,
                                           mocked_ui_exception_dialog,
                                           mocked_python_version,
                                           mocked_platform,
                                           mocked_is_linux,
                                           mocked_etree,
                                           mocked_bs4,
                                           mocked_sqlalchemy,
                                           mocked_application_version,
                                           mocked_openlurl,
                                           mocked_qversion,
                                           ):
        """
        Test send report  creates the proper system information text
        """
        # GIVEN: Test environment
        mocked_etree.__version__ = 'ETree Test'
        mocked_bs4.__version__ = 'BeautifulSoup Test'
        mocked_sqlalchemy.__version__ = 'SqlAlchemy Test'
        mocked_python_version.return_value = 'Python Test'
        mocked_platform.return_value = 'Nose Test'
        mocked_qversion.return_value = 'Qt5 test'
        mocked_is_linux.return_value = False
        mocked_application_version.return_value = 'Trunk Test'
        mocked_qt.PYQT_VERSION_STR = 'PyQt5 Test'
        mocked_is_linux.return_value = False
        mocked_application_version.return_value = 'Trunk Test'

        test_form = exceptionform.ExceptionForm()
        test_form.file_attachment = None

        with patch.object(test_form, '_pyuno_import') as mock_pyuno:
            with patch.object(test_form.exception_text_edit, 'toPlainText') as mock_traceback:
                with patch.object(test_form.description_text_edit, 'toPlainText') as mock_description:
                    mock_pyuno.return_value = 'UNO Bridge Test'
                    mock_traceback.return_value = 'openlp: Traceback Test'
                    mock_description.return_value = 'Description Test'

                    # WHEN: on_save_report_button_clicked called
                    test_form.on_send_report_button_clicked()

        # THEN: Verify strings were formatted properly
        mocked_add_query_item.assert_called_with('body', MAIL_ITEM_TEXT)
开发者ID:imkernel,项目名称:openlp,代码行数:47,代码来源:test_exceptionform.py


示例19: test_on_save_report_button_clicked

    def test_on_save_report_button_clicked(self,
                                           mocked_qt,
                                           mocked_save_filename,
                                           mocked_python_version,
                                           mocked_platform,
                                           mocked_is_linux,
                                           mocked_etree,
                                           mocked_bs4,
                                           mocked_sqlalchemy,
                                           mocked_application_version,
                                           mocked_openlurl,
                                           mocked_qversion,
                                           ):
        """
        Test save report saves the correct information to a file
        """
        mocked_etree.__version__ = 'ETree Test'
        mocked_bs4.__version__ = 'BeautifulSoup Test'
        mocked_sqlalchemy.__version__ = 'SqlAlchemy Test'
        mocked_python_version.return_value = 'Python Test'
        mocked_platform.return_value = 'Nose Test'
        mocked_qversion.return_value = 'Qt5 test'
        mocked_qt.PYQT_VERSION_STR = 'PyQt5 Test'
        mocked_is_linux.return_value = False
        mocked_application_version.return_value = 'Trunk Test'
        mocked_save_filename.return_value = ['testfile.txt', ]

        test_form = exceptionform.ExceptionForm()
        test_form.file_attachment = None

        with patch.object(test_form, '_pyuno_import') as mock_pyuno:
            with patch.object(test_form.exception_text_edit, 'toPlainText') as mock_traceback:
                with patch.object(test_form.description_text_edit, 'toPlainText') as mock_description:
                    with patch("openlp.core.ui.exceptionform.open", mock_open(), create=True) as mocked_open:
                        mock_pyuno.return_value = 'UNO Bridge Test'
                        mock_traceback.return_value = 'openlp: Traceback Test'
                        mock_description.return_value = 'Description Test'

                        # WHEN: on_save_report_button_clicked called
                        test_form.on_save_report_button_clicked()

        # THEN: Verify proper calls to save file
        # self.maxDiff = None
        check_text = "call().write({text})".format(text=MAIL_ITEM_TEXT.__repr__())
        write_text = "{text}".format(text=mocked_open.mock_calls[1])
        mocked_open.assert_called_with('testfile.txt', 'w')
        self.assertEquals(check_text, write_text, "Saved information should match test text")
开发者ID:imkernel,项目名称:openlp,代码行数:47,代码来源:test_exceptionform.py


示例20: test_on_search_shortcut_triggered_focuses_widget

    def test_on_search_shortcut_triggered_focuses_widget(self):
        """
        Test that the focus is set on the widget when the search shortcut is triggered
        """
        # GIVEN: A build main window set up for testing
        with patch.object(self.main_window, 'media_manager_dock') as mocked_media_manager_dock, \
                patch.object(self.main_window, 'media_tool_box') as mocked_media_tool_box:
            mocked_media_manager_dock.isVisible.return_value = True
            mocked_widget = MagicMock()
            mocked_media_tool_box.currentWidget.return_value = mocked_widget

            # WHEN: The search shortcut is triggered
            self.main_window.on_search_shortcut_triggered()

            # THEN: The media manager dock is made visible
            self.assertEqual(0, mocked_media_manager_dock.setVisible.call_count)
            mocked_widget.on_focus.assert_called_with()
开发者ID:imkernel,项目名称:openlp,代码行数:17,代码来源:test_mainwindow.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python test_runner.feature_name函数代码示例发布时间:2022-05-27
下一篇:
Python conftest.register_spec函数代码示例发布时间: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