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


Python MagicMock.name方法代码示例

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


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

示例1: test_load_objects

# 需要导入模块: from tests.functional import MagicMock [as 别名]
# 或者: from tests.functional.MagicMock import name [as 别名]
    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,代码行数:32,代码来源:test_editsongform.py

示例2: test_build_song_footer_base_songbook

# 需要导入模块: from tests.functional import MagicMock [as 别名]
# 或者: from tests.functional.MagicMock import name [as 别名]
    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,代码行数:34,代码来源:test_mediaitem.py

示例3: on_slide_selected_index_service_item_not_command_test

# 需要导入模块: from tests.functional import MagicMock [as 别名]
# 或者: from tests.functional.MagicMock import name [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

示例4: on_slide_selected_index_service_item_command_test

# 需要导入模块: from tests.functional import MagicMock [as 别名]
# 或者: from tests.functional.MagicMock import name [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

示例5: test_display_results_topic

# 需要导入模块: from tests.functional import MagicMock [as 别名]
# 或者: from tests.functional.MagicMock import name [as 别名]
    def test_display_results_topic(self):
        """
        Test displaying song search results grouped by topic with basic song
        """
        # GIVEN: Search results grouped by topic, plus a mocked QtListWidgetItem
        with patch('openlp.core.lib.QtWidgets.QListWidgetItem') as MockedQListWidgetItem, \
                patch('openlp.core.lib.QtCore.Qt.UserRole') as MockedUserRole:
            mock_search_results = []
            mock_topic = MagicMock()
            mock_song = MagicMock()
            mock_song_temp = MagicMock()
            mock_topic.name = 'My Topic'
            mock_topic.songs = []
            mock_song.id = 1
            mock_song.title = 'My Song'
            mock_song.sort_key = 'My Song'
            mock_song.temporary = False
            mock_song_temp.id = 2
            mock_song_temp.title = 'My Temporary'
            mock_song_temp.sort_key = 'My Temporary'
            mock_song_temp.temporary = True
            mock_topic.songs.append(mock_song)
            mock_topic.songs.append(mock_song_temp)
            mock_search_results.append(mock_topic)
            mock_qlist_widget = MagicMock()
            MockedQListWidgetItem.return_value = mock_qlist_widget

            # WHEN: I display song search results grouped by topic
            self.media_item.display_results_topic(mock_search_results)

            # THEN: The current list view is cleared, the widget is created, and the relevant attributes set
            self.media_item.list_view.clear.assert_called_with()
            MockedQListWidgetItem.assert_called_once_with('My Topic (My Song)')
            mock_qlist_widget.setData.assert_called_once_with(MockedUserRole, mock_song.id)
            self.media_item.list_view.addItem.assert_called_once_with(mock_qlist_widget)
开发者ID:imkernel,项目名称:openlp,代码行数:37,代码来源:test_mediaitem.py

示例6: test_process_chapters

# 需要导入模块: from tests.functional import MagicMock [as 别名]
# 或者: from tests.functional.MagicMock import name [as 别名]
    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,代码行数:31,代码来源:test_wordprojectimport.py

示例7: get_plugin_by_name_exists_test

# 需要导入模块: from tests.functional import MagicMock [as 别名]
# 或者: from tests.functional.MagicMock import name [as 别名]
    def get_plugin_by_name_exists_test(self):
        """
        Test running the get_plugin_by_name() method to find a plugin that exists
        """
        # GIVEN: A PluginManager instance and a list with a mocked up plugin whose status is set to Active
        mocked_plugin = MagicMock()
        mocked_plugin.name = 'Mocked Plugin'
        plugin_manager = PluginManager()
        plugin_manager.plugins = [mocked_plugin]

        # WHEN: We run finalise_plugins()
        result = plugin_manager.get_plugin_by_name('Mocked Plugin')

        # THEN: The is_active() and finalise() methods should have been called
        self.assertEqual(result, mocked_plugin, 'The result for get_plugin_by_name should be the mocked plugin')
开发者ID:crossroadchurch,项目名称:paul,代码行数:17,代码来源:test_pluginmanager.py

示例8: test_simple_import

# 需要导入模块: from tests.functional import MagicMock [as 别名]
# 或者: from tests.functional.MagicMock import name [as 别名]
    def test_simple_import(self, mocked_pysword_modules, mocked_application):
        """
        Test that a simple SWORD import works
        """
        # GIVEN: Test files with a mocked out "manager", "import_wizard", and mocked functions
        #       get_book_ref_id_by_name, create_verse, create_book, session and get_language.
        #       Also mocked pysword structures
        mocked_manager = MagicMock()
        mocked_import_wizard = MagicMock()
        importer = SwordBible(mocked_manager, path='.', name='.', filename='', sword_key='', sword_path='')
        result_file = open(os.path.join(TEST_PATH, 'dk1933.json'), 'rb')
        test_data = json.loads(result_file.read().decode())
        importer.wizard = mocked_import_wizard
        importer.get_book_ref_id_by_name = MagicMock()
        importer.create_verse = MagicMock()
        importer.create_book = MagicMock()
        importer.session = MagicMock()
        importer.get_language = MagicMock(return_value='Danish')
        mocked_bible = MagicMock()
        mocked_genesis = MagicMock()
        mocked_genesis.name = 'Genesis'
        mocked_genesis.num_chapters = 1
        books = {'ot': [mocked_genesis]}
        mocked_structure = MagicMock()
        mocked_structure.get_books.return_value = books
        mocked_bible.get_structure.return_value = mocked_structure
        mocked_bible.get_iter.return_value = [verse[1] for verse in test_data['verses']]
        mocked_module = MagicMock()
        mocked_module.get_bible_from_module.return_value = mocked_bible
        mocked_pysword_modules.SwordModules.return_value = mocked_module

        # WHEN: Importing bible file
        importer.do_import()

        # THEN: The create_verse() method should have been called with each verse in the file.
        self.assertTrue(importer.create_verse.called)
        for verse_tag, verse_text in test_data['verses']:
            importer.create_verse.assert_any_call(importer.create_book().id, 1, int(verse_tag), verse_text)
开发者ID:imkernel,项目名称:openlp,代码行数:40,代码来源:test_swordimport.py

示例9: test_process_verses

# 需要导入模块: from tests.functional import MagicMock [as 别名]
# 或者: from tests.functional.MagicMock import name [as 别名]
    def test_process_verses(self, mocked_open, mocked_os):
        """
        Test the process_verses() 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_db_book = MagicMock()
        mocked_db_book.name = 'Genesis'
        book_number = 1
        chapter_number = 1

        # WHEN: process_verses() is called
        with patch.object(importer, 'process_verse') as mocked_process_verse:
            importer.process_verses(mocked_db_book, book_number, chapter_number)

        # THEN: All the right methods should have been called
        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_process_verse.call_count == 31
开发者ID:imkernel,项目名称:openlp,代码行数:26,代码来源:test_wordprojectimport.py


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