コード例 #1
0
ファイル: test_download_state.py プロジェクト: hbiyik/tribler
    def test_getters_setters_1(self):
        """
        Testing various getters and setters in DownloadState
        """
        self.mock_download.get_peerlist = lambda: []
        self.mock_download.session = MockObject()
        self.mock_download.session = MockObject()
        self.mock_download.session.tunnel_community = MockObject()
        self.mock_download.session.tunnel_community.get_candidates = lambda _: []
        self.mock_download.config = MockObject()
        self.mock_download.config.get_hops = lambda: 0
        download_state = DownloadState(self.mock_download, None, None)

        self.assertEqual(download_state.get_download(), self.mock_download)
        self.assertEqual(download_state.get_progress(), 0)
        self.assertEqual(download_state.get_status(), DLSTATUS_WAITING4HASHCHECK)
        self.assertIsNone(download_state.get_error())
        self.assertEqual(download_state.get_current_speed(UPLOAD), 0)
        self.assertEqual(download_state.get_total_transferred(UPLOAD), 0)
        self.assertEqual(download_state.get_num_seeds_peers(), (0, 0))
        self.assertEqual(download_state.get_peerlist(), [])

        self.mock_download.config.get_hops = lambda: 1
        download_state = DownloadState(self.mock_download, None, None)
        self.assertEqual(download_state.get_status(), DLSTATUS_EXIT_NODES)
コード例 #2
0
def test_getters_setters_2(mock_download, mock_lt_status):
    """
    Testing various getters and setters in DownloadState
    """
    download_state = DownloadState(mock_download, mock_lt_status, None)

    assert download_state.get_status() == DLSTATUS_DOWNLOADING
    assert download_state.get_current_speed(UPLOAD) == 123
    assert download_state.get_current_speed(DOWNLOAD) == 43
    assert download_state.get_total_transferred(UPLOAD) == 100
    assert download_state.get_total_transferred(DOWNLOAD) == 200
    assert download_state.get_seeding_ratio() == 0.5
    assert download_state.get_eta() == 0.25
    assert download_state.get_num_seeds_peers() == (5, 5)
    assert download_state.get_pieces_complete() == []
    assert download_state.get_pieces_total_complete() == (0, 0)
    assert download_state.get_seeding_time() == 10

    mock_lt_status.num_pieces = 6
    mock_lt_status.pieces = [1, 1, 1, 0, 0, 0]
    assert download_state.get_pieces_complete() == [1, 1, 1, 0, 0, 0]
    assert download_state.get_pieces_total_complete() == (6, 3)

    mock_download.config.get_selected_files = lambda: ['test']
    assert download_state.get_selected_files() == ['test']
    assert download_state.get_progress() == 0.75
コード例 #3
0
def test_getters_setters_1(mock_download):
    """
    Testing various getters and setters in DownloadState
    """
    mock_download.get_peerlist = lambda: []
    mock_download.session.tunnel_community.get_candidates = lambda _: []
    mock_download.config.get_hops = lambda: 0
    download_state = DownloadState(mock_download, None, None)

    assert download_state.get_download() == mock_download
    assert download_state.get_progress() == 0
    assert download_state.get_status() == DLSTATUS_WAITING4HASHCHECK
    assert download_state.get_error() is None
    assert download_state.get_current_speed(UPLOAD) == 0
    assert download_state.get_total_transferred(UPLOAD) == 0
    assert download_state.get_num_seeds_peers() == (0, 0)
    assert download_state.get_peerlist() == []

    mock_download.config.get_hops = lambda: 1
    download_state = DownloadState(mock_download, None, None)
    assert download_state.get_status() == DLSTATUS_EXIT_NODES
コード例 #4
0
ファイル: test_download_state.py プロジェクト: hbiyik/tribler
    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)

        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_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.config = MockObject()
        self.mock_download.config.get_selected_files = lambda: ['test']
        self.assertEqual(download_state.get_selected_files(), ['test'])
        self.assertEqual(download_state.get_progress(), 0.75)