Skip to content

Commit

Permalink
Remove event_loop fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
drew2a committed Jul 5, 2023
1 parent 0dcd0da commit 2a257f1
Show file tree
Hide file tree
Showing 16 changed files with 31 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def knowledge_endpoint(knowledge_db):


@pytest.fixture
async def rest_api(event_loop, aiohttp_client, knowledge_endpoint): # pylint: disable=unused-argument
async def rest_api(aiohttp_client, knowledge_endpoint):
app = Application()
app.add_subapp('/knowledge', knowledge_endpoint.app)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@


@pytest.fixture
async def rest_api(event_loop, aiohttp_client, mock_dlmgr, metadata_store): # pylint: disable=unused-argument
async def rest_api(aiohttp_client, mock_dlmgr, metadata_store):
endpoint = DownloadsEndpoint(mock_dlmgr, metadata_store=metadata_store)
app = Application(middlewares=[error_middleware])
app.add_subapp('/downloads', endpoint.app)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


@pytest.fixture
async def rest_api(event_loop, aiohttp_client, mock_dlmgr, mock_lt_session): # pylint: disable=unused-argument
async def rest_api(aiohttp_client, mock_dlmgr, mock_lt_session):
endpoint = LibTorrentEndpoint(mock_dlmgr)
app = Application(middlewares=[error_middleware])
app.add_subapp('/libtorrent', endpoint.app)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def download_manager(state_dir):


@pytest.fixture
async def rest_api(event_loop, aiohttp_client, download_manager: DownloadManager): # pylint: disable=unused-argument
async def rest_api(aiohttp_client, download_manager: DownloadManager):
endpoint = TorrentInfoEndpoint(download_manager)
app = Application(middlewares=[error_middleware])
app.add_subapp('/torrentinfo', endpoint.app)
Expand Down Expand Up @@ -114,7 +114,7 @@ async def mock_http_query(*_):
tdef = TorrentDef.load_from_memory(torrent_data)
metainfo_dict = tdef_to_metadata_dict(TorrentDef.load_from_memory(torrent_data))

async def get_metainfo(infohash, timeout=20, hops=None, url=None):
async def get_metainfo(infohash, timeout=20, hops=None, url=None): # pylint: disable=unused-argument
if hops is not None:
hops_list.append(hops)
assert url
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@


@pytest.fixture
async def rest_api(event_loop, aiohttp_client, mock_dlmgr, metadata_store,
knowledge_db): # pylint: disable=unused-argument
async def rest_api(aiohttp_client, mock_dlmgr, metadata_store, knowledge_db):
mock_gigachannel_manager = Mock()
mock_gigachannel_community = Mock()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ async def torrent_checker(mock_dlmgr, metadata_store):


@pytest.fixture
async def rest_api(event_loop, aiohttp_client, torrent_checker, metadata_store):
async def rest_api(aiohttp_client, torrent_checker, metadata_store):
endpoint = MetadataEndpoint(torrent_checker, metadata_store)

app = Application(middlewares=[error_middleware])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def mock_gigachannel_community():


@pytest.fixture
async def rest_api(event_loop, aiohttp_client, metadata_store, mock_gigachannel_community):
async def rest_api(aiohttp_client, metadata_store, mock_gigachannel_community):
endpoint = RemoteQueryEndpoint(mock_gigachannel_community, metadata_store)
app = Application(middlewares=[error_middleware])
app.add_subapp('/remote_query', endpoint.app)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def needle_in_haystack_mds(metadata_store):


@pytest.fixture
async def rest_api(event_loop, needle_in_haystack_mds, aiohttp_client, knowledge_db):
async def rest_api(needle_in_haystack_mds, aiohttp_client, knowledge_db):
channels_endpoint = SearchEndpoint(needle_in_haystack_mds, knowledge_db=knowledge_db)
app = Application()
app.add_subapp('/search', channels_endpoint.app)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@
CHANNEL_METADATA_UPDATED = CHANNEL_DIR / 'channel_upd.mdblob'


# pylint: disable=redefined-outer-name

@pytest.fixture
def channel_tdef():
return TorrentDef.load(TESTS_DATA_DIR / 'sample_channel' / 'channel_upd.torrent')


@pytest.fixture
async def channel_seeder(channel_tdef, tmp_path_factory): # pylint: disable=unused-argument, redefined-outer-name
async def channel_seeder(channel_tdef, tmp_path_factory): # pylint: disable=unused-argument
config = LibtorrentSettings()
config.dht = False
config.upnp = False
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@
from tribler.core.tests.tools.common import TESTS_DATA_DIR


# pylint: disable=redefined-outer-name


@pytest.fixture
async def rest_api(event_loop, aiohttp_client, download_manager): # pylint: disable=unused-argument
async def rest_api(aiohttp_client, download_manager):
endpoint = CreateTorrentEndpoint(download_manager)
app = Application(middlewares=[error_middleware])
app.add_subapp('/createtorrent', endpoint.app)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ async def core_resource_monitor(tmp_path):


@pytest.fixture
async def rest_api(event_loop, aiohttp_client, mock_tunnel_community, tmp_path, core_resource_monitor):
async def rest_api(aiohttp_client, mock_tunnel_community, tmp_path, core_resource_monitor):
endpoint = DebugEndpoint(tmp_path, tmp_path / 'logs',
tunnel_community=mock_tunnel_community,
resource_monitor=core_resource_monitor)
Expand All @@ -41,6 +41,7 @@ async def rest_api(event_loop, aiohttp_client, mock_tunnel_community, tmp_path,

app = Application(middlewares=[error_middleware])
app.add_subapp('/debug', endpoint.app)

yield await aiohttp_client(app)

await endpoint.shutdown()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ def tribler_config(tmp_path):
return config



@pytest.fixture
async def rest_api(event_loop, aiohttp_client, tribler_config):
async def rest_api(aiohttp_client, tribler_config):
endpoint = SettingsEndpoint(tribler_config)
app = Application(middlewares=[error_middleware])
app.add_subapp('/settings', endpoint.app)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
from tribler.core.components.restapi.rest.shutdown_endpoint import ShutdownEndpoint


# pylint: disable=redefined-outer-name


@pytest.fixture
async def endpoint():
endpoint = ShutdownEndpoint(Mock())
Expand All @@ -17,7 +20,7 @@ async def endpoint():


@pytest.fixture
async def rest_api(event_loop, aiohttp_client, endpoint): # pylint: disable=unused-argument
async def rest_api(aiohttp_client, endpoint):
app = Application(middlewares=[error_middleware])
app.add_subapp('/shutdown', endpoint.app)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
from tribler.core.components.restapi.rest.statistics_endpoint import StatisticsEndpoint


# pylint: disable=redefined-outer-name


@pytest.fixture
async def endpoint(metadata_store):
ipv8 = MockIPv8("low", BandwidthAccountingCommunity, database=Mock(),
Expand All @@ -29,7 +32,7 @@ async def endpoint(metadata_store):


@pytest.fixture
async def rest_api(event_loop, aiohttp_client, endpoint): # pylint: disable=unused-argument
async def rest_api(aiohttp_client, endpoint):
app = Application(middlewares=[error_middleware])
app.add_subapp('/statistics', endpoint.app)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@
from tribler.core.utilities.utilities import MEMORY_DB


# pylint: disable=redefined-outer-name

@pytest.fixture
async def endpoint(bandwidth_db): # pylint: disable=W0621
async def endpoint(bandwidth_db):
endpoint = TrustViewEndpoint(bandwidth_db)
yield endpoint
await endpoint.shutdown()


@pytest.fixture
async def rest_api(event_loop, aiohttp_client, endpoint): # pylint: disable=unused-argument
async def rest_api(aiohttp_client, endpoint):
app = Application(middlewares=[error_middleware])
app.add_subapp('/trustview', endpoint.app)

Expand Down
14 changes: 0 additions & 14 deletions src/tribler/core/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import asyncio
import logging
import platform
import sys
from datetime import datetime
from typing import Optional
Expand Down Expand Up @@ -64,15 +62,3 @@ def pytest_runtest_protocol(item: Function, log=True, nextitem=None):
@pytest.fixture
def free_port():
return default_network_utils.get_random_free_port(start=1024, stop=50000)


@pytest.fixture
def event_loop():
if platform.system() == 'Windows':
# to prevent the "Loop is closed" error
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())

policy = asyncio.get_event_loop_policy()
loop = policy.new_event_loop()
yield loop
loop.close()

0 comments on commit 2a257f1

Please sign in to comment.