Skip to content

Commit

Permalink
Adopt asyncio_mode=auto
Browse files Browse the repository at this point in the history
  • Loading branch information
drew2a committed Apr 15, 2022
1 parent 39901e7 commit 2b36129
Show file tree
Hide file tree
Showing 62 changed files with 20 additions and 202 deletions.
2 changes: 2 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
[pytest]
timeout = 60
;https://pypi.org/project/pytest-asyncio/
asyncio_mode = auto
log_level = INFO
log_format = %(asctime)s.%(msecs)03d %(levelname)s %(message)s
log_cli_format = %(asctime)s.%(msecs)03d %(levelname)s %(message)s
Expand Down
20 changes: 10 additions & 10 deletions requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
-r requirements.txt

pytest==6.2.5
pytest-aiohttp==0.3.0
pytest-asyncio==0.16.0
pytest-mock==3.6.1
pytest-randomly==3.10.2
pytest-timeout==2.0.1
pytest-xdist==2.4.0
pytest==7.1.1
pytest-aiohttp==1.0.4
pytest-asyncio==0.18.3
pytest-mock==3.7.0
pytest-randomly==3.11.0
pytest-timeout==2.1.0
pytest-freezegun==0.4.2
freezegun==1.1.0
asynctest==0.13.0
coverage==6.3.2
freezegun==1.2.1
coverage==6.3.2

asynctest==0.13.0 # this library has to be installed to properly work with ipv8 TestBase.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
# pylint: disable=protected-access


@pytest.mark.asyncio
async def test_bandwidth_accounting_component(tribler_config):
components = [KeyComponent(), Ipv8Component(), BandwidthAccountingComponent()]
async with Session(tribler_config, components).start():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from tribler.core.components.restapi.rest.base_api_test import do_request
from tribler.core.utilities.unicode import hexlify

pytestmark = pytest.mark.asyncio

# pylint: disable=redefined-outer-name
@pytest.fixture
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ def test_store_large_transaction(bandwidth_db):
assert latest_tx


@pytest.mark.asyncio
async def test_totals(bandwidth_db):
with db_session:
tx1 = BandwidthTransactionData(1, b"a", b"b", EMPTY_SIGNATURE, EMPTY_SIGNATURE, 3000)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
# pylint: disable=protected-access


@pytest.mark.asyncio
async def test_giga_channel_component(tribler_config):
tribler_config.ipv8.enabled = True
tribler_config.libtorrent.enabled = True
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ async def gigachannel_manager(metadata_store):
await chanman.shutdown()


@pytest.mark.asyncio
async def test_regen_personal_channel_no_torrent(personal_channel, gigachannel_manager):
"""
Test regenerating a non-existing personal channel torrent at startup
Expand All @@ -60,7 +59,6 @@ async def test_regen_personal_channel_no_torrent(personal_channel, gigachannel_m
gigachannel_manager.regenerate_channel_torrent.assert_called_once()


@pytest.mark.asyncio
async def test_regen_personal_channel_damaged_torrent(personal_channel, gigachannel_manager):
"""
Test regenerating a damaged personal channel torrent at startup
Expand All @@ -75,7 +73,6 @@ async def mock_regen(*_, **__):
await complete


@pytest.mark.asyncio
async def test_regenerate_channel_torrent(personal_channel, metadata_store, gigachannel_manager):
with db_session:
chan_pk, chan_id = personal_channel.public_key, personal_channel.id_
Expand Down Expand Up @@ -116,7 +113,6 @@ def test_updated_my_channel(personal_channel, gigachannel_manager, tmpdir):
gigachannel_manager.download_manager.start_download.assert_called_once()


@pytest.mark.asyncio
async def test_check_and_regen_personal_channel_torrent(personal_channel, gigachannel_manager):
with db_session:
chan_pk, chan_id = personal_channel.public_key, personal_channel.id_
Expand Down Expand Up @@ -145,7 +141,6 @@ async def mock_regen(*_):
f.assert_called_once()


@pytest.mark.asyncio
async def test_check_channels_updates(personal_channel, gigachannel_manager, metadata_store):
torrents_added = 0
# We add our personal channel in an inconsistent state to make sure the GigaChannel Manager will
Expand Down Expand Up @@ -231,7 +226,6 @@ def mock_process_channel_dir(c, _):
assert not gigachannel_manager.channels_processing_queue


@pytest.mark.asyncio
async def test_remove_cruft_channels(torrent_template, personal_channel, gigachannel_manager, metadata_store):
remove_list = []
with db_session:
Expand Down Expand Up @@ -324,7 +318,6 @@ def mock_remove(infohash, remove_content=False):
initiated_download = False


@pytest.mark.asyncio
async def test_reject_malformed_channel(
gigachannel_manager, metadata_store
): # pylint: disable=unused-argument, redefined-outer-name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
# pylint: disable=protected-access


@pytest.mark.asyncio
async def test_gigachannel_manager_component(tribler_config):
components = [Ipv8Component(), TagComponent(), SocksServersComponent(), KeyComponent(), MetadataStoreComponent(),
LibtorrentComponent(), GigachannelManagerComponent()]
Expand Down
2 changes: 0 additions & 2 deletions src/tribler/core/components/ipv8/tests/test_eva_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,6 @@ def peer():
return Mock()


@pytest.mark.asyncio
async def test_on_write_request_data_size_le0(eva: EVAProtocol, peer):
# validate that data_size can not be less or equal to 0
with patch.object(EVAProtocol, '_incoming_error') as method_mock:
Expand All @@ -521,7 +520,6 @@ async def test_on_write_request_data_size_le0(eva: EVAProtocol, peer):
assert method_mock.call_count == 2


@pytest.mark.asyncio
async def test_on_acknowledgement_window_size_attr(eva: EVAProtocol, peer):
transfer = create_transfer(block_count=10)
eva.outgoing[peer] = transfer
Expand Down
3 changes: 0 additions & 3 deletions src/tribler/core/components/ipv8/tests/test_ipv8_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@


# pylint: disable=protected-access
@pytest.mark.asyncio
async def test_ipv8_component(tribler_config):
async with Session(tribler_config, [KeyComponent(), Ipv8Component()]).start():
comp = Ipv8Component.instance()
Expand All @@ -18,7 +17,6 @@ async def test_ipv8_component(tribler_config):
assert not comp._peer_discovery_community


@pytest.mark.asyncio
async def test_ipv8_component_dht_disabled(tribler_config):
tribler_config.ipv8.enabled = True
tribler_config.dht.enabled = True
Expand All @@ -27,7 +25,6 @@ async def test_ipv8_component_dht_disabled(tribler_config):
assert comp.dht_discovery_community


@pytest.mark.asyncio
async def test_ipv8_component_discovery_community_enabled(tribler_config):
tribler_config.ipv8.enabled = True
tribler_config.gui_test_mode = False
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ def fixture_ipv8_health_monitor(ipv8):
return IPv8Monitor(ipv8, DEFAULT_WALK_INTERVAL, 3.0, 0.01)


@pytest.mark.asyncio
async def test_start(task_manager, ipv8_health_monitor):
mock_interval = 7.7

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from tribler.core.components.key.key_component import KeyComponent


@pytest.mark.asyncio
async def test_masterkey_component(tribler_config):
async with Session(tribler_config, [KeyComponent()]).start():
comp = KeyComponent.instance()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from asyncio import Future
from binascii import unhexlify

from asynctest import Mock
from unittest.mock import Mock

import pytest

Expand All @@ -16,7 +15,6 @@ async def dht_health_manager():
await manager.shutdown_task_manager()


@pytest.mark.asyncio
async def test_get_health(dht_health_manager):
"""
Test fetching the health of a trackerless torrent.
Expand All @@ -27,14 +25,12 @@ async def test_get_health(dht_health_manager):
assert response['DHT'][0]['infohash'] == hexlify(b'a' * 20)


@pytest.mark.asyncio
async def test_existing_get_health(dht_health_manager):
lookup_future = dht_health_manager.get_health(b'a' * 20, timeout=0.1)
assert dht_health_manager.get_health(b'a' * 20, timeout=0.1) == lookup_future
await lookup_future


@pytest.mark.asyncio
async def test_combine_bloom_filters(dht_health_manager):
"""
Test combining two bloom filters
Expand All @@ -48,7 +44,6 @@ async def test_combine_bloom_filters(dht_health_manager):
assert dht_health_manager.combine_bloomfilters(bf1, bf2) == bf2


@pytest.mark.asyncio
async def test_get_size_from_bloom_filter(dht_health_manager):
"""
Test whether we can successfully estimate the size from a bloom filter
Expand All @@ -69,7 +64,6 @@ async def test_get_size_from_bloom_filter(dht_health_manager):
assert dht_health_manager.get_size_from_bloomfilter(bf) == 6000


@pytest.mark.asyncio
async def test_receive_bloomfilters(dht_health_manager):
"""
Test whether the right operations happen when receiving a bloom filter
Expand Down
8 changes: 0 additions & 8 deletions src/tribler/core/components/libtorrent/tests/test_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,12 @@ def test_download_resume(mock_handle, mock_download_config, test_download):
test_download.handle.resume.assert_called()


@pytest.mark.asyncio
async def test_download_resume_in_upload_mode(mock_handle, mock_download_config, test_download):
await test_download.set_upload_mode(True)
test_download.resume()
test_download.handle.set_upload_mode.assert_called_with(test_download.get_upload_mode())


@pytest.mark.asyncio
async def test_save_resume(mock_handle, test_download, test_tdef):
"""
testing call resume data alert
Expand Down Expand Up @@ -77,7 +75,6 @@ def mock_move(s):
assert len(result) == 1


@pytest.mark.asyncio
async def test_save_checkpoint(test_download, test_tdef):
await test_download.checkpoint()
basename = hexlify(test_tdef.get_infohash()) + '.conf'
Expand Down Expand Up @@ -146,7 +143,6 @@ def test_get_share_mode(test_download):
assert test_download.get_share_mode()


@pytest.mark.asyncio
async def test_set_share_mode(mock_handle, test_download):
"""
Test whether we set the right share mode in Download
Expand Down Expand Up @@ -188,7 +184,6 @@ def get_peer_info(seeders, leechers):
assert num_peers == mock_leechers, "Expected peers differ"


@pytest.mark.asyncio
async def test_set_priority(mock_handle, test_download):
"""
Test whether setting the priority calls the right methods in Download
Expand Down Expand Up @@ -249,7 +244,6 @@ def test_tracker_warning_alert(test_download):
assert test_download.tracker_status[url][1] == 'Warning: test'


@pytest.mark.asyncio
async def test_on_metadata_received_alert(mock_handle, test_download):
"""
Testing whether the right operations happen when we receive metadata
Expand Down Expand Up @@ -362,7 +356,6 @@ def test_get_pieces_bitmask(mock_handle, test_download):
assert test_download.get_pieces_base64() == b"gA=="


@pytest.mark.asyncio
async def test_resume_data_failed(test_download):
"""
Testing whether the correct operations happen when an error is raised during resume data saving
Expand Down Expand Up @@ -394,7 +387,6 @@ def test_on_state_changed(mock_handle, test_download):
test_download.apply_ip_filter.assert_called_with(False)


@pytest.mark.asyncio
async def test_checkpoint_timeout(test_download):
"""
Testing whether making a checkpoint times out when we receive no alert from libtorrent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from tribler.core.utilities.simpledefs import DLSTATUS_DOWNLOADING


@pytest.mark.asyncio
async def test_download_torrent_from_url(tmp_path, file_server, download_manager):
# Setup file server to serve torrent file
shutil.copyfile(TORRENT_UBUNTU_FILE, tmp_path / "ubuntu.torrent")
Expand All @@ -17,14 +16,12 @@ async def test_download_torrent_from_url(tmp_path, file_server, download_manager
await download.wait_for_status(DLSTATUS_DOWNLOADING)


@pytest.mark.asyncio
async def test_download_torrent_from_file(download_manager):
uri = path_to_url(TORRENT_UBUNTU_FILE)
d = await download_manager.start_download_from_uri(uri, config=DownloadConfig())
await d.wait_for_status(DLSTATUS_DOWNLOADING)


@pytest.mark.asyncio
async def test_download_torrent_from_file_with_escaped_characters(download_manager, tmp_path):
destination = tmp_path / 'ubuntu%20%21 15.04.torrent'
shutil.copyfile(TORRENT_UBUNTU_FILE, destination)
Expand Down
Loading

0 comments on commit 2b36129

Please sign in to comment.