本文整理汇总了Python中tests.functional.MagicMock.return_value方法的典型用法代码示例。如果您正苦于以下问题:Python MagicMock.return_value方法的具体用法?Python MagicMock.return_value怎么用?Python MagicMock.return_value使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tests.functional.MagicMock
的用法示例。
在下文中一共展示了MagicMock.return_value方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_check_file_type_processor_different_from_available
# 需要导入模块: from tests.functional import MagicMock [as 别名]
# 或者: from tests.functional.MagicMock import return_value [as 别名]
def test_check_file_type_processor_different_from_available(self, mocked_uistrings, mocked_get_used_players):
"""
Test that we can play media when players available are different from the processor from the service item
"""
# GIVEN: A mocked UiStrings, get_media_players, controller, display and service_item
mocked_get_used_players.return_value = (['system'])
mocked_ret_uistrings = MagicMock()
mocked_ret_uistrings.Automatic = 'automatic'
mocked_uistrings.return_value = mocked_ret_uistrings
media_controller = MediaController()
mocked_phonon = MagicMock()
mocked_phonon.video_extensions_list = ['*.mp4']
media_controller.media_players = {'system': mocked_phonon}
mocked_controller = MagicMock()
mocked_suffix = MagicMock()
mocked_suffix.return_value = 'mp4'
mocked_controller.media_info.file_info.suffix = mocked_suffix
mocked_display = MagicMock()
mocked_service_item = MagicMock()
mocked_service_item.processor = 'vlc'
# WHEN: calling _check_file_type when the processor for the service item is None
ret = media_controller._check_file_type(mocked_controller, mocked_display, mocked_service_item)
# THEN: it should return True
self.assertTrue(ret, '_check_file_type should return True when the players available are different'
'from the processor from the service item.')
示例2: test_check_file_type_automatic_processor
# 需要导入模块: from tests.functional import MagicMock [as 别名]
# 或者: from tests.functional.MagicMock import return_value [as 别名]
def test_check_file_type_automatic_processor(self, mocked_uistrings, mocked_get_used_players):
"""
Test that we can play media when players are available and we have a automatic processor from the service item
"""
# GIVEN: A mocked UiStrings, get_media_players, controller, display and service_item
mocked_get_used_players.return_value = (['vlc', 'webkit'])
mocked_ret_uistrings = MagicMock()
mocked_ret_uistrings.Automatic = 1
mocked_uistrings.return_value = mocked_ret_uistrings
media_controller = MediaController()
mocked_vlc = MagicMock()
mocked_vlc.video_extensions_list = ['*.mp4']
media_controller.media_players = {'vlc': mocked_vlc, 'webkit': MagicMock()}
mocked_controller = MagicMock()
mocked_suffix = MagicMock()
mocked_suffix.return_value = 'mp4'
mocked_controller.media_info.file_info.suffix = mocked_suffix
mocked_display = MagicMock()
mocked_service_item = MagicMock()
mocked_service_item.processor = 1
# WHEN: calling _check_file_type when the processor for the service item is None
ret = media_controller._check_file_type(mocked_controller, mocked_display, mocked_service_item)
# THEN: it should return True
self.assertTrue(ret, '_check_file_type should return True when mediaplayers are available and '
'the service item has an automatic processor.')
示例3: paint_event_text_doesnt_fit_test
# 需要导入模块: from tests.functional import MagicMock [as 别名]
# 或者: from tests.functional.MagicMock import return_value [as 别名]
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)
示例4: paint_event_text_fits_test
# 需要导入模块: from tests.functional import MagicMock [as 别名]
# 或者: from tests.functional.MagicMock import return_value [as 别名]
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)
示例5: db_file_import_test
# 需要导入模块: from tests.functional import MagicMock [as 别名]
# 或者: from tests.functional.MagicMock import return_value [as 别名]
def db_file_import_test(self):
"""
Test the actual import of real song database files and check that the imported data is correct.
"""
# GIVEN: Test files with a mocked out SongImport class, a mocked out "manager", a mocked out "import_wizard",
# and mocked out "author", "add_copyright", "add_verse", "finish" methods.
with patch('openlp.plugins.songs.lib.importers.easyworship.SongImport'), \
patch('openlp.plugins.songs.lib.importers.easyworship.retrieve_windows_encoding') as \
mocked_retrieve_windows_encoding:
mocked_retrieve_windows_encoding.return_value = 'cp1252'
mocked_manager = MagicMock()
mocked_import_wizard = MagicMock()
mocked_add_author = MagicMock()
mocked_add_verse = MagicMock()
mocked_finish = MagicMock()
mocked_title = MagicMock()
mocked_finish.return_value = True
importer = EasyWorshipSongImportLogger(mocked_manager)
importer.import_wizard = mocked_import_wizard
importer.stop_import_flag = False
importer.add_author = mocked_add_author
importer.add_verse = mocked_add_verse
importer.title = mocked_title
importer.finish = mocked_finish
importer.topics = []
# WHEN: Importing each file
importer.import_source = os.path.join(TEST_PATH, 'Songs.DB')
import_result = importer.do_import()
# THEN: do_import should return none, the song data should be as expected, and finish should have been
# called.
self.assertIsNone(import_result, 'do_import should return None when it has completed')
for song_data in SONG_TEST_DATA:
title = song_data['title']
author_calls = song_data['authors']
song_copyright = song_data['copyright']
ccli_number = song_data['ccli_number']
add_verse_calls = song_data['verses']
verse_order_list = song_data['verse_order_list']
self.assertIn(title, importer._title_assignment_list, 'title for %s should be "%s"' % (title, title))
for author in author_calls:
mocked_add_author.assert_any_call(author)
if song_copyright:
self.assertEqual(importer.copyright, song_copyright)
if ccli_number:
self.assertEqual(importer.ccli_number, ccli_number,
'ccli_number for %s should be %s' % (title, ccli_number))
for verse_text, verse_tag in add_verse_calls:
mocked_add_verse.assert_any_call(verse_text, verse_tag)
if verse_order_list:
self.assertEqual(importer.verse_order_list, verse_order_list,
'verse_order_list for %s should be %s' % (title, verse_order_list))
mocked_finish.assert_called_with()
示例6: file_import_test
# 需要导入模块: from tests.functional import MagicMock [as 别名]
# 或者: from tests.functional.MagicMock import return_value [as 别名]
def file_import_test(self):
"""
Test the actual import of real song files and check that the imported data is correct.
"""
# GIVEN: Test files with a mocked out SongImport class, a mocked out "manager", a mocked out "import_wizard",
# and mocked out "author", "add_copyright", "add_verse", "finish" methods.
with patch('openlp.plugins.songs.lib.importers.songbeamer.SongImport'):
for song_file in SONG_TEST_DATA:
mocked_manager = MagicMock()
mocked_import_wizard = MagicMock()
mocked_add_verse = MagicMock()
mocked_finish = MagicMock()
mocked_finish.return_value = True
importer = SongBeamerImport(mocked_manager, filenames=[])
importer.import_wizard = mocked_import_wizard
importer.stop_import_flag = False
importer.add_verse = mocked_add_verse
importer.finish = mocked_finish
# WHEN: Importing each file
importer.import_source = [os.path.join(TEST_PATH, song_file)]
title = SONG_TEST_DATA[song_file]['title']
add_verse_calls = SONG_TEST_DATA[song_file]['verses']
song_book_name = SONG_TEST_DATA[song_file]['song_book_name']
song_number = SONG_TEST_DATA[song_file]['song_number']
song_authors = SONG_TEST_DATA[song_file]['authors']
# THEN: do_import should return none, the song data should be as expected, and finish should have been
# called.
self.assertIsNone(importer.do_import(), 'do_import should return None when it has completed')
self.assertEqual(importer.title, title, 'title for %s should be "%s"' % (song_file, title))
for verse_text, verse_tag in add_verse_calls:
mocked_add_verse.assert_any_call(verse_text, verse_tag)
if song_book_name:
self.assertEqual(importer.song_book_name, song_book_name,
'song_book_name for %s should be "%s"' % (song_file, song_book_name))
if song_number:
self.assertEqual(importer.song_number, song_number,
'song_number for %s should be %s' % (song_file, song_number))
if song_authors:
for author in importer.authors:
self.assertIn(author, song_authors)
mocked_finish.assert_called_with()
示例7: ews_file_import_test
# 需要导入模块: from tests.functional import MagicMock [as 别名]
# 或者: from tests.functional.MagicMock import return_value [as 别名]
def ews_file_import_test(self):
"""
Test the actual import of song from ews file and check that the imported data is correct.
"""
# GIVEN: Test files with a mocked out SongImport class, a mocked out "manager", a mocked out "import_wizard",
# and mocked out "author", "add_copyright", "add_verse", "finish" methods.
with patch('openlp.plugins.songs.lib.importers.easyworship.SongImport'), \
patch('openlp.plugins.songs.lib.importers.easyworship.retrieve_windows_encoding') \
as mocked_retrieve_windows_encoding:
mocked_retrieve_windows_encoding.return_value = 'cp1252'
mocked_manager = MagicMock()
mocked_import_wizard = MagicMock()
mocked_add_author = MagicMock()
mocked_add_verse = MagicMock()
mocked_finish = MagicMock()
mocked_title = MagicMock()
mocked_finish.return_value = True
importer = EasyWorshipSongImportLogger(mocked_manager)
importer.import_wizard = mocked_import_wizard
importer.stop_import_flag = False
importer.add_author = mocked_add_author
importer.add_verse = mocked_add_verse
importer.title = mocked_title
importer.finish = mocked_finish
importer.topics = []
# WHEN: Importing ews file
importer.import_source = os.path.join(TEST_PATH, 'test1.ews')
import_result = importer.do_import()
# THEN: do_import should return none, the song data should be as expected, and finish should have been
# called.
title = EWS_SONG_TEST_DATA['title']
self.assertIsNone(import_result, 'do_import should return None when it has completed')
self.assertIn(title, importer._title_assignment_list, 'title for should be "%s"' % title)
mocked_add_author.assert_any_call(EWS_SONG_TEST_DATA['authors'][0])
for verse_text, verse_tag in EWS_SONG_TEST_DATA['verses']:
mocked_add_verse.assert_any_call(verse_text, verse_tag)
mocked_finish.assert_called_with()