"""Shared fixtures for the fungus-launcher test suite.""" import os from unittest.mock import patch import pytest @pytest.fixture() def tmp_data_dir(tmp_path): """Provide a temporary XDG_DATA_HOME directory.""" with patch.dict(os.environ, {"XDG_DATA_HOME": str(tmp_path / "data")}): yield tmp_path / "data" @pytest.fixture() def tmp_config_dir(tmp_path): """Provide a temporary XDG_CONFIG_HOME directory.""" with patch.dict(os.environ, {"XDG_CONFIG_HOME": str(tmp_path / "config")}): yield tmp_path / "config" @pytest.fixture() def games_file(tmp_path): """Provide a path to a temporary games.json file and clean it up.""" path = tmp_path / "games.json" yield path if path.exists(): path.unlink() @pytest.fixture() def sample_games(): """Provide a list of sample Game objects.""" from fungus.game_model import Game return [ Game( gameid="umu-1234", title="Test Game Alpha", path="/home/user/Games/alpha/game.sh", prefix="/home/user/prefixes/umu-1234", launch_arguments="", game_arguments="--verbose", protonfix="umu-1234", runner="GE-Proton9-11", playtime=3600, hidden=False, favorite=True, ), Game( gameid="umu-5678", title="Test Game Beta", path="/home/user/Games/beta/beta.exe", prefix="/home/user/prefixes/umu-5678", launch_arguments="--options", game_arguments="", protonfix="umu-5678", runner="Proton-EM-1.0", playtime=7200, hidden=True, favorite=False, ), ] @pytest.fixture() def populated_games_file(games_file, sample_games): """Write sample games to a JSON file and return the path.""" import json with open(games_file, "w", encoding="utf-8") as f: json.dump([g.to_dict() for g in sample_games], f, ensure_ascii=False, indent=4) return games_file @pytest.fixture() def sample_games_dir(tmp_path, sample_games): """Provide a temporary games directory with sample .ini files. Returns the path to the games directory. """ from fungus.game_model import GameLibrary games_dir = tmp_path / "games" library = GameLibrary(str(games_dir)) for game in sample_games: library.save(game) return games_dir