当前位置: 首页>>代码示例>>Python>>正文


Python MockObject.meta方法代码示例

本文整理汇总了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)
开发者ID:synctext,项目名称:tribler,代码行数:29,代码来源:test_channel_conversion.py

示例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')
开发者ID:synctext,项目名称:tribler,代码行数:19,代码来源:test_channel_conversion.py


注:本文中的Tribler.Test.Core.base_test.MockObject.meta方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。