Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle corupted pieces in a handle status #7982

Merged
merged 2 commits into from
Apr 22, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Enhance test readability with helper function
Introduced a helper function to improve the readability of tests in the libtorrent component. This function converts bitarray representations into base64, making it easier to understand and verify the expected results. The changes are applied in tests that check if correct pieces bitmask is returned when requested.
  • Loading branch information
drew2a committed Apr 22, 2024
commit 9eac127193c2b26afca21875b0f319c8e450bce1
11 changes: 9 additions & 2 deletions src/tribler/core/components/libtorrent/tests/test_download.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from asyncio import Future, sleep
from base64 import b64encode
from pathlib import Path
from typing import Generator
from unittest.mock import MagicMock, Mock, PropertyMock, patch

import libtorrent as lt
import pytest
from _pytest.logging import LogCaptureFixture
from bitarray import bitarray
from ipv8.util import succeed
from libtorrent import bencode

Expand Down Expand Up @@ -494,11 +496,16 @@ def test_get_pieces_bitmask(mock_handle, test_download):
"""
Testing whether a correct pieces bitmask is returned when requested
"""

def _repr(s):
""" Helper function to return the base64 representation of a bitarray"""
return b64encode(bitarray(s).tobytes())

test_download.handle.status().pieces = [True, False, True, False, False]
assert test_download.get_pieces_base64() == b"oA=="
assert test_download.get_pieces_base64() == _repr('10100')

test_download.handle.status().pieces = [True] * 16
assert test_download.get_pieces_base64() == b"//8="
assert test_download.get_pieces_base64() == _repr('1111111111111111')


async def test_resume_data_failed(test_download):
Expand Down