本文整理汇总了Python中Tribler.Test.Core.base_test.MockObject.torrent_file方法的典型用法代码示例。如果您正苦于以下问题:Python MockObject.torrent_file方法的具体用法?Python MockObject.torrent_file怎么用?Python MockObject.torrent_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tribler.Test.Core.base_test.MockObject
的用法示例。
在下文中一共展示了MockObject.torrent_file方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_got_metainfo
# 需要导入模块: from Tribler.Test.Core.base_test import MockObject [as 别名]
# 或者: from Tribler.Test.Core.base_test.MockObject import torrent_file [as 别名]
def test_got_metainfo(self):
"""
Testing whether the callback is correctly invoked when we received metainfo
"""
test_deferred = Deferred()
self.ltmgr.initialize()
def metainfo_cb(metainfo):
self.assertDictEqual(metainfo, {'info': {'pieces': ['a']}, 'leechers': 0,
'nodes': [], 'seeders': 0, 'initial peers': []})
test_deferred.callback(None)
fake_handle = MockObject()
torrent_info = MockObject()
torrent_info.metadata = lambda: bencode({'pieces': ['a']})
torrent_info.trackers = lambda: []
fake_handle.get_peer_info = lambda: []
fake_handle.torrent_file = lambda: torrent_info
self.ltmgr.ltsession_metainfo.remove_torrent = lambda *_: None
self.ltmgr.metainfo_requests['a' * 20] = {
'handle': fake_handle,
'timeout_callbacks': [],
'callbacks': [metainfo_cb],
'notify': False
}
self.ltmgr.got_metainfo("a" * 20)
return test_deferred
示例2: test_get_metainfo
# 需要导入模块: from Tribler.Test.Core.base_test import MockObject [as 别名]
# 或者: from Tribler.Test.Core.base_test.MockObject import torrent_file [as 别名]
def test_get_metainfo(self):
"""
Testing the metainfo fetching method
"""
test_deferred = Deferred()
def metainfo_cb(metainfo):
self.assertEqual(metainfo, {'info': {'pieces': ['a']}, 'leechers': 0,
'nodes': [], 'seeders': 0, 'initial peers': []})
test_deferred.callback(None)
infohash = "a" * 20
self.ltmgr.initialize()
torrent_info = MockObject()
torrent_info.metadata = lambda: bencode({'pieces': ['a']})
torrent_info.trackers = lambda: []
fake_handle = MockObject()
fake_handle.is_valid = lambda: True
fake_handle.has_metadata = lambda: True
fake_handle.get_peer_info = lambda: []
fake_handle.torrent_file = lambda: torrent_info
self.ltmgr.ltsession_metainfo.add_torrent = lambda *_: fake_handle
self.ltmgr.ltsession_metainfo.remove_torrent = lambda *_: None
fake_alert = type('lt.metadata_received_alert', (object,), dict(handle=fake_handle))
self.ltmgr.ltsession_metainfo.pop_alerts = lambda: [fake_alert]
self.ltmgr.get_metainfo(unhexlify(infohash), metainfo_cb)
return test_deferred
示例3: test_get_info_from_handle
# 需要导入模块: from Tribler.Test.Core.base_test import MockObject [as 别名]
# 或者: from Tribler.Test.Core.base_test.MockObject import torrent_file [as 别名]
def test_get_info_from_handle(self):
mock_handle = MockObject()
def mock_get_torrent_file():
raise RuntimeError
mock_handle.torrent_file = mock_get_torrent_file
self.assertIsNone(get_info_from_handle(mock_handle))