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


Python MagicMock.id方法代码示例

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


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

示例1: test_display_results_cclinumber

# 需要导入模块: from tests.functional import MagicMock [as 别名]
# 或者: from tests.functional.MagicMock import id [as 别名]
    def test_display_results_cclinumber(self):
        """
        Test displaying song search results sorted by CCLI number with basic song
        """
        # GIVEN: Search results sorted by CCLI number, 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_song = MagicMock()
            mock_song_temp = MagicMock()
            mock_song.id = 1
            mock_song.title = 'My Song'
            mock_song.sort_key = 'My Song'
            mock_song.ccli_number = '12345'
            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.ccli_number = '12346'
            mock_song_temp.temporary = True
            mock_search_results.append(mock_song)
            mock_search_results.append(mock_song_temp)
            mock_qlist_widget = MagicMock()
            MockedQListWidgetItem.return_value = mock_qlist_widget

            # WHEN: I display song search results sorted by CCLI number
            self.media_item.display_results_cclinumber(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('12345 (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,代码行数:35,代码来源:test_mediaitem.py

示例2: test_load_objects

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

示例3: test_display_results_song

# 需要导入模块: from tests.functional import MagicMock [as 别名]
# 或者: from tests.functional.MagicMock import id [as 别名]
    def test_display_results_song(self):
        """
        Test displaying song search results with basic song
        """
        # GIVEN: Search results, 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_song = MagicMock()
            mock_song.id = 1
            mock_song.title = 'My Song'
            mock_song.sort_key = 'My Song'
            mock_song.authors = []
            mock_song_temp = MagicMock()
            mock_song_temp.id = 2
            mock_song_temp.title = 'My Temporary'
            mock_song_temp.sort_key = 'My Temporary'
            mock_song_temp.authors = []
            mock_author = MagicMock()
            mock_author.display_name = 'My Author'
            mock_song.authors.append(mock_author)
            mock_song_temp.authors.append(mock_author)
            mock_song.temporary = False
            mock_song_temp.temporary = True
            mock_search_results.append(mock_song)
            mock_search_results.append(mock_song_temp)
            mock_qlist_widget = MagicMock()
            MockedQListWidgetItem.return_value = mock_qlist_widget
            self.media_item.auto_select_id = 1

            # WHEN: I display song search results
            self.media_item.display_results_song(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()
            self.media_item.save_auto_select_id.assert_called_with()
            MockedQListWidgetItem.assert_called_once_with('My Song (My Author)')
            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)
            self.media_item.list_view.setCurrentItem.assert_called_with(mock_qlist_widget)
开发者ID:imkernel,项目名称:openlp,代码行数:42,代码来源:test_mediaitem.py

示例4: test_build_remote_search

# 需要导入模块: from tests.functional import MagicMock [as 别名]
# 或者: from tests.functional.MagicMock import id [as 别名]
    def test_build_remote_search(self):
        """
        Test results for the remote search api
        """
        # GIVEN: A Song and a search a JSON array should be returned.
        mock_song = MagicMock()
        mock_song.id = 123
        mock_song.title = 'My Song'
        mock_song.search_title = 'My Song'
        mock_song.alternate_title = 'My alternative'
        self.media_item.search_entire = MagicMock()
        self.media_item.search_entire.return_value = [mock_song]

        # WHEN: I process a search
        search_results = self.media_item.search('My Song', False)

        # THEN: The correct formatted results are returned
        self.assertEqual(search_results, [[123, 'My Song', 'My alternative']])
开发者ID:imkernel,项目名称:openlp,代码行数:20,代码来源:test_mediaitem.py

示例5: test_process_verse_no_text

# 需要导入模块: from tests.functional import MagicMock [as 别名]
# 或者: from tests.functional.MagicMock import id [as 别名]
    def test_process_verse_no_text(self):
        """
        Test the process_verse() method when there's no text
        """
        # GIVEN: An importer and a mocked method
        importer = WordProjectBible(MagicMock(), path='.', name='.', filename='kj.zip')
        mocked_db_book = MagicMock()
        mocked_db_book.id = 1
        chapter_number = 1
        verse_number = 1
        verse_text = ''

        # WHEN: process_verse() is called
        with patch.object(importer, 'create_verse') as mocked_create_verse:
            importer.process_verse(mocked_db_book, chapter_number, verse_number, verse_text)

        # THEN: The create_verse() method should NOT have been called
        assert mocked_create_verse.call_count == 0
开发者ID:imkernel,项目名称:openlp,代码行数:20,代码来源:test_wordprojectimport.py

示例6: test_process_verse

# 需要导入模块: from tests.functional import MagicMock [as 别名]
# 或者: from tests.functional.MagicMock import id [as 别名]
    def test_process_verse(self):
        """
        Test the process_verse() method
        """
        # GIVEN: An importer and a mocked method
        importer = WordProjectBible(MagicMock(), path='.', name='.', filename='kj.zip')
        mocked_db_book = MagicMock()
        mocked_db_book.id = 1
        chapter_number = 1
        verse_number = 1
        verse_text = '  In the beginning, God created the heavens and the earth   '

        # WHEN: process_verse() is called
        with patch.object(importer, 'create_verse') as mocked_create_verse:
            importer.process_verse(mocked_db_book, chapter_number, verse_number, verse_text)

        # THEN: The create_verse() method should have been called
        mocked_create_verse.assert_called_once_with(1, 1, 1, 'In the beginning, God created the heavens and the earth')
开发者ID:imkernel,项目名称:openlp,代码行数:20,代码来源:test_wordprojectimport.py


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