Files
libretro/tests/__init__.py
T
Abdessamad Derraz 2535d99cc6 fix: keep the host's XDG folders out of the tests
install.py reads RetroArch's base folder from XDG_CONFIG_HOME, and the
GitHub runner sets it: six tests that give the installer a home of
their own read the runner's ~/.config, failed in CI and passed here.
2026-11-07 02:10:53 +01:00

48 lines
2.1 KiB
Python

"""No test downloads a release asset unless it says so.
The CI job sets RETROBIOS_OFFLINE, but a local run of the documented command
did not, and e2e fixtures queried the large-files release and wrote its
answers into the shared .cache/large. A test that serves its own assets
clears the variable for itself.
Scratch files go under the repository's tmp/, which git does not track: a
fresh clone has none, and a module run alone raised FileNotFoundError on a
temporary directory instead of naming the missing parent.
"""
from __future__ import annotations
import os
import tempfile
from pathlib import Path
os.environ.setdefault("RETROBIOS_OFFLINE", "1")
# The installer reads RetroArch's base folder from XDG_CONFIG_HOME as
# RetroArch does. The GitHub runner sets it, and the tests that give the
# installer a home of their own found the runner's ~/.config instead: six
# failed in CI and passed here. A test that needs the variable sets it.
for _xdg in ("XDG_CONFIG_HOME", "XDG_DATA_HOME"):
os.environ.pop(_xdg, None)
# A test never waits on, nor blocks, the measurements running on the host.
os.environ.setdefault(
"RETROBIOS_PROBE_LOCK",
str(Path(__file__).resolve().parent.parent / "tmp" / "tests" / "probe.lock"),
)
_SCRATCH = Path(__file__).resolve().parent.parent / "tmp" / "tests"
_SCRATCH.mkdir(parents=True, exist_ok=True)
# A TemporaryDirectory() without dir= landed in /tmp, a 4 GB tmpfs here: once
# another run filled it, modules unrelated to any change failed with ENOSPC.
# The default is the repository's tmp/, for this process and its children.
os.environ["TMPDIR"] = str(_SCRATCH)
tempfile.tempdir = str(_SCRATCH)
# A scratch directory is not part of this checkout: git run inside one must
# not walk up to the repository, as it could not from /tmp.
os.environ["GIT_CEILING_DIRECTORIES"] = str(_SCRATCH)
# The installer's cache (the games index, what reading a card found) is the
# suite's own: a run never reads nor fills the one of the person running it.
os.environ.setdefault(
"RETROBIOS_CACHE",
str(Path(__file__).resolve().parent.parent / "tmp" / "tests" / "cache"),
)