本文整理汇总了Python中Tribler.Test.Core.base_test.MockObject.meta方法的典型用法代码示例。如果您正苦于以下问题:Python MockObject.meta方法的具体用法?Python MockObject.meta怎么用?Python MockObject.meta使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tribler.Test.Core.base_test.MockObject
的用法示例。
在下文中一共展示了MockObject.meta方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_encode_torrent
# 需要导入模块: from Tribler.Test.Core.base_test import MockObject [as 别名]
# 或者: from Tribler.Test.Core.base_test.MockObject import meta [as 别名]
def test_encode_torrent(self):
"""
Test the encoding of a torrent file
"""
message = MockObject()
message.payload = MockObject()
message.payload.name = u'test'
message.payload.infohash = 'a' * 20
message.payload.timestamp = 1234
message.payload.files = [(u'a', 1234)]
message.payload.trackers = ['udp://tracker.openbittorrent.com:80/announce', 'http://google.com']
meta = self.channel_community.get_meta_message(u"torrent")
msg = MockObject()
msg.meta = meta
decoded_message = self.conversion._decode_torrent(msg, 0, self.conversion._encode_torrent(message)[0])[1]
self.assertEqual(len(decoded_message.files), 1)
self.assertEqual(len(decoded_message.trackers), 1)
message.payload.files = [(u'a', 1234)] * 1000
message.payload.trackers = ['udp://tracker.openbittorrent.com:80/announce'] * 100
decoded_message = self.conversion._decode_torrent(msg, 0, self.conversion._encode_torrent(message)[0])[1]
self.assertGreaterEqual(len(decoded_message.files), 133)
self.assertEqual(len(decoded_message.trackers), 10)
示例2: test_decode_torrent
# 需要导入模块: from Tribler.Test.Core.base_test import MockObject [as 别名]
# 或者: from Tribler.Test.Core.base_test.MockObject import meta [as 别名]
def test_decode_torrent(self):
"""
Test the decoding of a torrent message
"""
self.assertRaises(DropPacket, self.conversion._decode_torrent, None, 0, "abcd")
self.assertRaises(DropPacket, self.conversion._decode_torrent, None, 0, zlib.compress("abcd"))
# Test a successful decoding
meta = self.channel_community.get_meta_message(u"torrent")
msg = MockObject()
msg.meta = meta
torrent_msg = encode((pack('!20sQ', 'a' * 20, 12345), u'torrent', ((u'a', 1234),), ('http://track.er',)))
_, msg = self.conversion._decode_torrent(msg, 0, zlib.compress(torrent_msg))
self.assertEqual(msg.infohash, 'a' * 20)
self.assertEqual(msg.name, u'torrent')