本文整理汇总了Python中Tribler.Test.Core.base_test.MockObject.get_peer_info方法的典型用法代码示例。如果您正苦于以下问题:Python MockObject.get_peer_info方法的具体用法?Python MockObject.get_peer_info怎么用?Python MockObject.get_peer_info使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tribler.Test.Core.base_test.MockObject
的用法示例。
在下文中一共展示了MockObject.get_peer_info方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_metainfo
# 需要导入模块: from Tribler.Test.Core.base_test import MockObject [as 别名]
# 或者: from Tribler.Test.Core.base_test.MockObject import get_peer_info [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
示例2: test_got_metainfo
# 需要导入模块: from Tribler.Test.Core.base_test import MockObject [as 别名]
# 或者: from Tribler.Test.Core.base_test.MockObject import get_peer_info [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
示例3: test_update_torrent
# 需要导入模块: from Tribler.Test.Core.base_test import MockObject [as 别名]
# 或者: from Tribler.Test.Core.base_test.MockObject import get_peer_info [as 别名]
def test_update_torrent(self):
"""
Test updating a torrent when a circuit breaks
"""
self.nodes[0].overlay.active_data_circuits = lambda: True
self.nodes[0].overlay.readd_bittorrent_peers = lambda *_: None
mock_handle = MockObject()
mock_handle.get_peer_info = lambda: {2, 3}
peers = {1, 2}
self.nodes[0].overlay.update_torrent(peers, mock_handle, 'a')
self.assertIn('a', self.nodes[0].overlay.bittorrent_peers)
# Test adding peers
self.nodes[0].overlay.bittorrent_peers['a'] = {4}
self.nodes[0].overlay.update_torrent(peers, mock_handle, 'a')