Beispiel #1
0
 def test_piece_queue_random(self):
     test_bytes = '\x00'
     test_hash = hashlib.sha1(test_bytes).digest()
     piece = Piece(fake_client, 1, 1, test_hash, test_dir)
     piece_queue = PieceQueue([piece])
     test_piece = piece_queue.get_next_random()
     self.assertEqual(test_piece.index, piece.index)
     test_piece.add_block(0, test_bytes)
     self.assertTrue(piece.check_if_finished())
     self.assertTrue(piece.check_info_hash())
Beispiel #2
0
 def test_piece_queue_random_five(self):
     pieces = []
     test_bytes_list = ['\x00', '\x01', '\x02', '\x03', '\x04']
     for i in range(5):
         test_bytes = test_bytes_list[i]
         test_hash = hashlib.sha1(test_bytes).digest()
         piece = Piece(fake_client, i, 1, test_hash, test_dir)
         pieces.append(piece)
     piece_queue = PieceQueue(pieces)
     for i in xrange(5):
         test_piece = piece_queue.get_next_random()
         self.assertEqual(test_piece.index, pieces[test_piece.index].index)
Beispiel #3
0
 def test_piece_queue_random_two(self):
     test_bytes0 = '\x00'
     test_hash0 = hashlib.sha1(test_bytes0).digest()
     piece0 = Piece(fake_client, 0, 1, test_hash0, test_dir)
     test_bytes1 = '\x01'
     test_hash1 = hashlib.sha1(test_bytes1).digest()
     piece1 = Piece(fake_client, 1, 1, test_hash1, test_dir)
     pieces = [piece0, piece1]
     piece_queue = PieceQueue(pieces)
     test_piece = piece_queue.get_next_random()
     # print test_piece.index
     # print pieces[test_piece.index].index
     self.assertEqual(test_piece.index, pieces[test_piece.index].index)