1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
"""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
|