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


Python MockObject.torrent_file方法代码示例

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

示例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
开发者ID:Tribler,项目名称:tribler,代码行数:34,代码来源:test_libtorrent_mgr.py

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


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