本文整理汇总了Python中Tribler.Test.Core.base_test.MockObject.path方法的典型用法代码示例。如果您正苦于以下问题:Python MockObject.path方法的具体用法?Python MockObject.path怎么用?Python MockObject.path使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tribler.Test.Core.base_test.MockObject
的用法示例。
在下文中一共展示了MockObject.path方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_on_metadata_received_alert
# 需要导入模块: from Tribler.Test.Core.base_test import MockObject [as 别名]
# 或者: from Tribler.Test.Core.base_test.MockObject import path [as 别名]
def test_on_metadata_received_alert(self):
"""
Testing whether the right operations happen when we receive metadata
"""
test_deferred = Deferred()
def mocked_checkpoint():
test_deferred.callback(None)
mocked_file = MockObject()
mocked_file.path = 'test'
self.libtorrent_download_impl.handle.trackers = lambda: []
self.libtorrent_download_impl.handle.save_resume_data = lambda: None
torrent_dict = {'name': 'test', 'piece length': 42, 'pieces': '', 'files': []}
get_info_from_handle(self.libtorrent_download_impl.handle).metadata = lambda: lt.bencode(torrent_dict)
get_info_from_handle(self.libtorrent_download_impl.handle).files = lambda: [mocked_file]
self.libtorrent_download_impl.checkpoint = mocked_checkpoint
self.libtorrent_download_impl.session = MockObject()
self.libtorrent_download_impl.session.lm = MockObject()
self.libtorrent_download_impl.session.lm.rtorrent_handler = None
self.libtorrent_download_impl.session.lm.torrent_db = None
self.libtorrent_download_impl.handle.save_path = lambda: None
self.libtorrent_download_impl.handle.prioritize_files = lambda _: None
self.libtorrent_download_impl.get_save_path = lambda: ''
self.libtorrent_download_impl.get_share_mode = lambda: False
self.libtorrent_download_impl.on_metadata_received_alert(None)
return test_deferred
示例2: test_selected_files
# 需要导入模块: from Tribler.Test.Core.base_test import MockObject [as 别名]
# 或者: from Tribler.Test.Core.base_test.MockObject import path [as 别名]
def test_selected_files(self):
"""
Test whether the selected files are set correctly
"""
def mocked_set_file_prios(_):
mocked_set_file_prios.called = True
mocked_set_file_prios.called = False
mocked_file = MockObject()
mocked_file.path = 'my/path'
mock_torrent_info = MockObject()
mock_torrent_info.files = lambda: [mocked_file, mocked_file]
self.libtorrent_download_impl.handle.prioritize_files = mocked_set_file_prios
self.libtorrent_download_impl.handle.get_torrent_info = lambda: mock_torrent_info
self.libtorrent_download_impl.handle.rename_file = lambda *_: None
self.libtorrent_download_impl.get_share_mode = lambda: False
self.libtorrent_download_impl.tdef.get_infohash = lambda: 'a' * 20
self.libtorrent_download_impl.orig_files = ['a', 'b']
self.libtorrent_download_impl.get_save_path = lambda: 'my/path'
self.libtorrent_download_impl.set_selected_files(['a'])
self.assertTrue(mocked_set_file_prios.called)
self.libtorrent_download_impl.get_share_mode = lambda: False
mocked_set_file_prios.called = False
self.assertFalse(mocked_set_file_prios.called)
示例3: test_on_metadata_received_alert
# 需要导入模块: from Tribler.Test.Core.base_test import MockObject [as 别名]
# 或者: from Tribler.Test.Core.base_test.MockObject import path [as 别名]
def test_on_metadata_received_alert(self):
"""
Testing whether the right operations happen when we receive metadata
"""
test_deferred = Deferred()
def mocked_checkpoint():
test_deferred.callback(None)
mocked_file = MockObject()
mocked_file.path = 'test'
self.libtorrent_download_impl.handle.trackers = lambda: []
self.libtorrent_download_impl.handle.save_resume_data = lambda: None
self.libtorrent_download_impl.handle.rename_file = lambda *_: None
with open(os.path.join(TESTS_DATA_DIR, "bak_single.torrent"), mode='rb') as torrent_file:
encoded_metainfo = torrent_file.read()
decoded_metainfo = bdecode(encoded_metainfo)
get_info_from_handle(self.libtorrent_download_impl.handle).metadata = lambda: bencode(decoded_metainfo['info'])
get_info_from_handle(self.libtorrent_download_impl.handle).files = lambda: [mocked_file]
self.libtorrent_download_impl.checkpoint = mocked_checkpoint
self.libtorrent_download_impl.session = MockObject()
self.libtorrent_download_impl.session.lm = MockObject()
self.libtorrent_download_impl.session.lm.torrent_db = None
self.libtorrent_download_impl.handle.save_path = lambda: None
self.libtorrent_download_impl.handle.prioritize_files = lambda _: None
self.libtorrent_download_impl.get_save_path = lambda: ''
self.libtorrent_download_impl.get_share_mode = lambda: False
self.libtorrent_download_impl.on_metadata_received_alert(None)
return test_deferred
示例4: test_selected_files_no_files
# 需要导入模块: from Tribler.Test.Core.base_test import MockObject [as 别名]
# 或者: from Tribler.Test.Core.base_test.MockObject import path [as 别名]
def test_selected_files_no_files(self):
"""
Test that no files are selected if torrent info is not available.
"""
def mocked_set_file_prios(_):
mocked_set_file_prios.called = True
mocked_set_file_prios.called = False
mocked_file = MockObject()
mocked_file.path = 'my/path'
mock_torrent_info = MockObject()
self.libtorrent_download_impl.handle.prioritize_files = mocked_set_file_prios
self.libtorrent_download_impl.handle.get_torrent_info = lambda: mock_torrent_info
self.libtorrent_download_impl.handle.rename_file = lambda *_: None
self.libtorrent_download_impl.tdef.get_infohash = lambda: 'a' * 20
self.libtorrent_download_impl.orig_files = ['a', 'b']
self.libtorrent_download_impl.get_save_path = lambda: 'my/path'
# If share mode is not enabled and everything else is fine, file priority should be set
# when set_selected_files() is called. But in this test, no files attribute is set in torrent info
# in order to test AttributeError, therfore, no call to set file priority is expected.
self.libtorrent_download_impl.get_share_mode = lambda: False
self.libtorrent_download_impl.set_selected_files(['a'])
self.assertFalse(mocked_set_file_prios.called)
示例5: test_get_dest_files
# 需要导入模块: from Tribler.Test.Core.base_test import MockObject [as 别名]
# 或者: from Tribler.Test.Core.base_test.MockObject import path [as 别名]
def test_get_dest_files(self):
"""
Testing whether the right list of files is returned when fetching files from a download
"""
self.libtorrent_download_impl.handle.file_priority = lambda _: 123
mocked_file = MockObject()
mocked_file.path = 'test'
mock_torrent_info = MockObject()
mock_torrent_info.files = lambda: [mocked_file]
self.libtorrent_download_impl.handle.get_torrent_info = lambda: mock_torrent_info
dest_files = self.libtorrent_download_impl.get_dest_files()
self.assertIsInstance(dest_files[0], tuple)
self.assertEqual(dest_files[0][0], 'test')
示例6: test_metadata_received_invalid_torrent_with_value_error
# 需要导入模块: from Tribler.Test.Core.base_test import MockObject [as 别名]
# 或者: from Tribler.Test.Core.base_test.MockObject import path [as 别名]
def test_metadata_received_invalid_torrent_with_value_error(self):
"""
Testing whether the right operations happen when we receive metadata but the torrent info is invalid and throws
Value Error
"""
def mocked_checkpoint():
raise RuntimeError("This code should not be reached!")
mocked_file = MockObject()
mocked_file.path = 'test'
# The line below should trigger Value Error
self.libtorrent_download_impl.handle.trackers = lambda: [{'url': 'no-DHT'}]
get_info_from_handle(self.libtorrent_download_impl.handle).metadata = lambda: lt.bencode({})
get_info_from_handle(self.libtorrent_download_impl.handle).files = lambda: [mocked_file]
self.libtorrent_download_impl.checkpoint = mocked_checkpoint
self.libtorrent_download_impl.on_metadata_received_alert(None)