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


Python MockObject.pieces方法代码示例

本文整理汇总了Python中Tribler.Test.Core.base_test.MockObject.pieces方法的典型用法代码示例。如果您正苦于以下问题:Python MockObject.pieces方法的具体用法?Python MockObject.pieces怎么用?Python MockObject.pieces使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Tribler.Test.Core.base_test.MockObject的用法示例。


在下文中一共展示了MockObject.pieces方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_getters_setters_2

# 需要导入模块: from Tribler.Test.Core.base_test import MockObject [as 别名]
# 或者: from Tribler.Test.Core.base_test.MockObject import pieces [as 别名]
    def test_getters_setters_2(self):
        """
        Testing various getters and setters in DownloadState
        """
        lt_status = MockObject()
        lt_status.state = 3
        lt_status.upload_rate = 123
        lt_status.download_rate = 43
        lt_status.total_upload = 100
        lt_status.total_download = 200
        lt_status.all_time_upload = 100
        lt_status.all_time_download = 200
        lt_status.list_peers = 10
        lt_status.list_seeds = 5
        lt_status.progress = 0.75
        lt_status.error = False
        lt_status.paused = False
        lt_status.state = 3
        lt_status.num_pieces = 0
        lt_status.pieces = []
        lt_status.finished_time = 10

        download_state = DownloadState(self.mock_download, lt_status, None, {'vod_prebuf_frac_consec': 43,
                                                                             'vod_prebuf_frac': 44})

        self.assertEqual(download_state.get_status(), DLSTATUS_DOWNLOADING)
        self.assertEqual(download_state.get_current_speed(UPLOAD), 123)
        self.assertEqual(download_state.get_current_speed(DOWNLOAD), 43)
        self.assertEqual(download_state.get_total_transferred(UPLOAD), 100)
        self.assertEqual(download_state.get_total_transferred(DOWNLOAD), 200)
        self.assertEqual(download_state.get_vod_prebuffering_progress_consec(), 43)
        self.assertEqual(download_state.get_vod_prebuffering_progress(), 44)
        self.assertTrue(download_state.is_vod())
        self.assertEqual(download_state.get_seeding_ratio(), 0.5)
        self.assertEqual(download_state.get_eta(), 0.25)
        self.assertEqual(download_state.get_num_seeds_peers(), (5, 5))
        self.assertEqual(download_state.get_pieces_complete(), [])
        self.assertEqual(download_state.get_pieces_total_complete(), (0, 0))
        self.assertEqual(download_state.get_seeding_time(), 10)

        lt_status.num_pieces = 6
        lt_status.pieces = [1, 1, 1, 0, 0, 0]
        self.assertEqual(download_state.get_pieces_complete(), [1, 1, 1, 0, 0, 0])
        self.assertEqual(download_state.get_pieces_total_complete(), (6, 3))

        self.mock_download.get_selected_files = lambda: ['test']
        self.assertEqual(download_state.get_selected_files(), ['test'])
        self.assertEqual(download_state.get_progress(), 0.75)
开发者ID:synctext,项目名称:tribler,代码行数:50,代码来源:test_downloadstate.py

示例2: setUp

# 需要导入模块: from Tribler.Test.Core.base_test import MockObject [as 别名]
# 或者: from Tribler.Test.Core.base_test.MockObject import pieces [as 别名]
    def setUp(self):
        TriblerCoreTest.setUp(self)
        self.libtorrent_download_impl = LibtorrentDownloadImpl(None, None)
        mock_handle = MockObject()
        mock_status = MockObject()
        mock_status.pieces = [True, False, True, True, False]
        torrent_info = MockObject()
        file_info = MockObject()
        file_info.size = 1234
        torrent_info.file_at = lambda _: file_info
        map_file_result = MockObject()
        map_file_result.piece = 123
        torrent_info.map_file = lambda _dummy1, _dummy2, _dummy3: map_file_result
        torrent_info.num_pieces = lambda: 5

        mock_handle.is_valid = lambda: True
        mock_handle.status = lambda: mock_status
        mock_handle.get_torrent_info = lambda: torrent_info
        mock_handle.set_sequential_download = lambda _: None
        mock_handle.set_priority = lambda _: None
        mock_handle.prioritize_pieces = lambda _: None

        self.libtorrent_download_impl.handle = mock_handle

        # Create a fake tdef
        self.libtorrent_download_impl.tdef = MockObject()
        self.libtorrent_download_impl.tdef.get_name = lambda: "ubuntu.iso"
        self.libtorrent_download_impl.tdef.is_multifile_torrent = lambda: False
开发者ID:synctext,项目名称:tribler,代码行数:30,代码来源:test_libtorrent_download_impl.py

示例3: create_mock_status

# 需要导入模块: from Tribler.Test.Core.base_test import MockObject [as 别名]
# 或者: from Tribler.Test.Core.base_test.MockObject import pieces [as 别名]
 def create_mock_status(self):
     status = MockObject()
     status.state = 3
     status.upload_rate = 123
     status.download_rate = 43
     status.upload_payload_rate = 123
     status.download_payload_rate = 43
     status.total_upload = 100
     status.total_download = 200
     status.all_time_upload = 100
     status.all_time_download = 200
     status.list_peers = 10
     status.list_seeds = 5
     status.progress = 0.75
     status.error = False
     status.paused = False
     status.state = 3
     status.num_pieces = 0
     status.pieces = []
     return status
开发者ID:synctext,项目名称:tribler,代码行数:22,代码来源:test_downloads_endpoint.py

示例4: test_get_availability

# 需要导入模块: from Tribler.Test.Core.base_test import MockObject [as 别名]
# 或者: from Tribler.Test.Core.base_test.MockObject import pieces [as 别名]
    def test_get_availability(self):
        """
        Testing whether the right availability of a file is returned
        """
        mock_ltstate = MockObject()
        mock_ltstate.pieces = [True]
        download_state = DownloadState(self.mock_download, mock_ltstate, None, 0.6)
        download_state.get_peerlist = lambda: []

        self.assertEqual(download_state.get_availability(), 0)
        download_state.get_peerlist = lambda: [{'completed': 1.0}]
        self.assertEqual(download_state.get_availability(), 1.0)
        download_state.get_peerlist = lambda: [{'completed': 0.6}]
        self.assertEqual(download_state.get_availability(), 0.0)
        download_state.lt_status.pieces = [0, 0, 0, 0, 0]
        download_state.get_peerlist = lambda: [{'completed': 0}, {'have': [1, 1, 1, 1, 0]}]
        self.assertEqual(download_state.get_availability(), 0.8)

        # Test whether inaccurate piece information from other peers is ignored
        download_state.get_peerlist = lambda: [{'completed': 0.5, 'have': [1, 0]},
                                               {'completed': 0.9, 'have': [1, 0, 1]}]
        self.assertEqual(download_state.get_availability(), 0.0)
开发者ID:Tribler,项目名称:tribler,代码行数:24,代码来源:test_downloadstate.py


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