Skip to content

Commit

Permalink
Refactor appinfo test fixture
Browse files Browse the repository at this point in the history
Instead of storing pytest fixture specific state, parse the actual
`appinfo.vdf` file for the entries.

This will make it easier to implement additional pytest fixtures that
append data into the same `appinfo.vdf` file.
  • Loading branch information
Matoking committed Dec 5, 2023
1 parent 26952ae commit 53f3794
Showing 1 changed file with 12 additions and 19 deletions.
31 changes: 12 additions & 19 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from protontricks.steam import (APPINFO_STRUCT_HEADER,
APPINFO_V28_STRUCT_SECTION, SteamApp,
get_appid_from_shortcut)
from protontricks.steam import iter_appinfo_sections


@pytest.fixture(scope="function", autouse=True)
Expand Down Expand Up @@ -319,41 +320,33 @@ def steam_config_path(steam_dir):


@pytest.fixture(scope="function", autouse=True)
def appinfo_compat_tool_factory(appinfo_factory):
def appinfo_compat_tool_factory(appinfo_factory, steam_dir):
"""
Factory function to add compat tool entries to the appinfo.vdf binary file
"""
compat_tools = []

def func(proton_app, compat_tool_name, aliases=None):
manifest_appinfo = next(
section["appinfo"] for section
in iter_appinfo_sections(steam_dir / "appcache" / "appinfo.vdf")
if section["appinfo"]["appid"] == 891390
)

if not aliases:
aliases = []

aliases.append(compat_tool_name)

compat_tools.append({
manifest_appinfo["extended"]["compat_tools"][compat_tool_name] = {
"appid": proton_app.appid,
"compat_tool_name": compat_tool_name,
"aliases": [compat_tool_name] + aliases
})

compat_tool_entries = {}

for compat_tool in compat_tools:
compat_tool_entries[compat_tool["compat_tool_name"]] = {
"aliases": ",".join(compat_tool["aliases"]),
"appid": compat_tool["appid"]
}
"aliases": ",".join(aliases)
}

# Update the appinfo.vdf with the compat tools that have been
# added so far.
appinfo_factory(
appid=891390, # Steam Play 2.0 Manifests app ID,
appinfo={
"extended": {
"compat_tools": compat_tool_entries
}
}
appinfo=manifest_appinfo
)

return func
Expand Down

0 comments on commit 53f3794

Please sign in to comment.