Files

90 lines
2.3 KiB
Python

import logging
from contextlib import ExitStack
from unittest.mock import AsyncMock, MagicMock, patch
import pytest
from galaxy.api.consts import Platform
from galaxy.api.plugin import Plugin
from galaxy.unittest.mock import async_return_value
@pytest.fixture()
def reader():
stream = MagicMock(name="stream_reader")
stream.read = AsyncMock()
yield stream
@pytest.fixture()
def writer():
stream = MagicMock(name="stream_writer")
stream.drain.side_effect = lambda: async_return_value(None)
yield stream
@pytest.fixture()
def read(reader):
yield reader.read
@pytest.fixture()
def write(writer):
yield writer.write
@pytest.fixture()
def plugin(reader, writer):
"""Return plugin instance with all feature methods mocked"""
methods = (
"handshake_complete",
"authenticate",
"get_owned_games",
"prepare_achievements_context",
"get_unlocked_achievements",
"achievements_import_complete",
"get_local_games",
"launch_game",
"launch_platform_client",
"install_game",
"uninstall_game",
"get_friends",
"get_game_time",
"prepare_game_times_context",
"game_times_import_complete",
"shutdown_platform_client",
"shutdown",
"tick",
"get_game_library_settings",
"prepare_game_library_settings_context",
"game_library_settings_import_complete",
"get_os_compatibility",
"prepare_os_compatibility_context",
"os_compatibility_import_complete",
"get_user_presence",
"prepare_user_presence_context",
"user_presence_import_complete",
"get_local_size",
"prepare_local_size_context",
"local_size_import_complete",
"get_subscriptions",
"get_subscription_games",
"prepare_subscription_games_context",
"subscription_games_import_complete"
)
# Patch the class methods BEFORE creating the instance
with ExitStack() as stack:
for method in methods:
stack.enter_context(patch.object(Plugin, method))
# Now create the plugin instance
plugin = Plugin(Platform.Generic, "0.1", reader, writer, "token")
plugin.shutdown.return_value = None
yield plugin
@pytest.fixture(autouse=True)
def my_caplog(caplog):
caplog.set_level(logging.DEBUG)