本文整理汇总了Python中piece.Piece.check_if_finished方法的典型用法代码示例。如果您正苦于以下问题:Python Piece.check_if_finished方法的具体用法?Python Piece.check_if_finished怎么用?Python Piece.check_if_finished使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类piece.Piece
的用法示例。
在下文中一共展示了Piece.check_if_finished方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_piece_info_hash
# 需要导入模块: from piece import Piece [as 别名]
# 或者: from piece.Piece import check_if_finished [as 别名]
def test_piece_info_hash(self):
test_bytes = '\x00\x01\x02'
test_hash = hashlib.sha1(test_bytes).digest()
piece = Piece(fake_client, 1, 3, test_hash, test_dir)
piece.write_file = StringIO()
self.assertEqual(piece.num_blocks, 1)
self.assertFalse(piece.check_if_finished())
self.assertTrue(piece.not_all_blocks_requested())
piece.add_block(0, test_bytes)
self.assertTrue(piece.check_if_finished())
self.assertTrue(piece.check_info_hash())
示例2: test_piece_info_hash_out_of_order
# 需要导入模块: from piece import Piece [as 别名]
# 或者: from piece.Piece import check_if_finished [as 别名]
def test_piece_info_hash_out_of_order(self):
test_bytes = '\x00\x01\x02'
empty_block = '\x00' * 2**14
test_hash = hashlib.sha1(empty_block + test_bytes).digest()
piece = Piece(fake_client, 1, 2**14 + 3, test_hash, test_dir)
piece.write_file = StringIO()
self.assertEqual(piece.num_blocks, 2)
self.assertFalse(piece.check_if_finished())
piece.add_block(2**14, test_bytes)
self.assertFalse(piece.check_if_finished())
piece.add_block(0, empty_block)
self.assertTrue(piece.check_if_finished())
self.assertTrue(piece.check_info_hash())
示例3: test_piece_queue_random
# 需要导入模块: from piece import Piece [as 别名]
# 或者: from piece.Piece import check_if_finished [as 别名]
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())