本文整理汇总了Python中piece.Piece.not_all_blocks_requested方法的典型用法代码示例。如果您正苦于以下问题:Python Piece.not_all_blocks_requested方法的具体用法?Python Piece.not_all_blocks_requested怎么用?Python Piece.not_all_blocks_requested使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类piece.Piece
的用法示例。
在下文中一共展示了Piece.not_all_blocks_requested方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_piece_one_block
# 需要导入模块: from piece import Piece [as 别名]
# 或者: from piece.Piece import not_all_blocks_requested [as 别名]
def test_piece_one_block(self):
piece = Piece(fake_client, 1, 2**14, 'abc', test_dir)
self.assertEqual(piece.num_blocks, 1)
self.assertTrue(piece.not_all_blocks_requested())
block_info = piece.get_next_block()
self.assertEqual(block_info[0], 1)
self.assertEqual(block_info[1], 0)
self.assertEqual(block_info[2], 2**14)
self.assertFalse(piece.not_all_blocks_requested())
示例2: test_piece_two_blocks
# 需要导入模块: from piece import Piece [as 别名]
# 或者: from piece.Piece import not_all_blocks_requested [as 别名]
def test_piece_two_blocks(self):
piece = Piece(fake_client, 1, 2**14 + 2, 'abcd', test_dir)
self.assertEqual(piece.num_blocks, 2)
self.assertTrue(piece.not_all_blocks_requested())
block = piece.get_next_block()
self.assertTrue(piece.not_all_blocks_requested())
block = piece.get_next_block()
self.assertEqual(block[1], 2**14, '2nd block should begin at byte 2**14')
self.assertEqual(block[2], 2, '2nd block should have length 2')
self.assertFalse(piece.not_all_blocks_requested())
示例3: test_piece_one_short_block
# 需要导入模块: from piece import Piece [as 别名]
# 或者: from piece.Piece import not_all_blocks_requested [as 别名]
def test_piece_one_short_block(self):
piece = Piece(fake_client, 1, 2, 'abcd', test_dir)
self.assertEqual(piece.num_blocks, 1)
self.assertTrue(piece.not_all_blocks_requested())
block = piece.get_next_block()
self.assertEqual(block[2], 2)
(block_info, peer) = piece.get_next_block_and_peer_to_request()
self.assertEqual(peer, None)
self.assertEqual(block_info[0], 1)
self.assertEqual(block_info[1], 0)
self.assertEqual(block_info[2], 2**14)
self.assertFalse(piece.not_all_blocks_requested())
示例4: test_piece_info_hash
# 需要导入模块: from piece import Piece [as 别名]
# 或者: from piece.Piece import not_all_blocks_requested [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())