mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-12-02 06:18:51 -06:00
RETROBIOS_OFFLINE was read by six callers and never by the network gateway: a caller that did not pass offline=True sent the request, untokened. core.offline holds the rule, open_retrying refuses with OfflineError and the cached reads answer as an offline run. The callers read the same predicate, and the tests that fake the network clear the variable for themselves (tests.ONLINE).
71 lines
3.4 KiB
Python
71 lines
3.4 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,
|
|
or fakes the network core.upstream reaches, clears the variable for itself
|
|
(ONLINE).
|
|
|
|
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 shutil
|
|
import sys
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
from unittest import mock
|
|
|
|
os.environ.setdefault("RETROBIOS_OFFLINE", "1")
|
|
# A test or a test class that fakes the network runs as a run that fetches:
|
|
# under RETROBIOS_OFFLINE, core.upstream refuses every request before it goes out.
|
|
ONLINE = mock.patch.dict(os.environ, {"RETROBIOS_OFFLINE": ""})
|
|
# The modules under test import each other by bare name (common, verify), as
|
|
# the scripts do when run from scripts/, and install.py sits at the root.
|
|
_REPOSITORY = Path(__file__).resolve().parent.parent
|
|
for _path in (str(_REPOSITORY), str(_REPOSITORY / "scripts")):
|
|
if _path not in sys.path:
|
|
sys.path.insert(0, _path)
|
|
# The installer reads the XDG base directories as RetroArch and the
|
|
# emulators do. The CI runner sets XDG_CONFIG_HOME to its own home, so tests
|
|
# that fake HOME found the runner's folders instead of theirs. A test that
|
|
# exercises one of them sets it for itself.
|
|
for _name in ("XDG_CONFIG_HOME", "XDG_DATA_HOME", "XDG_CACHE_HOME"):
|
|
os.environ.pop(_name, None)
|
|
# A test never waits on, nor blocks, the measurements running on the host.
|
|
# scripts/run_tests.py runs each module in a process of its own, beside
|
|
# others: each one gets its own scratch folder, so two never share the
|
|
# installer cache, the probe lock or a fixed name below it.
|
|
_SCRATCH = Path(os.environ.get("RETROBIOS_TEST_SCRATCH")
|
|
or Path(__file__).resolve().parent.parent / "tmp" / "tests")
|
|
_SCRATCH.mkdir(parents=True, exist_ok=True)
|
|
os.environ.setdefault("RETROBIOS_PROBE_LOCK", str(_SCRATCH / "probe.lock"))
|
|
# The repository's own hold (database.json, install/, README.md) too: a
|
|
# pipeline run by one module no longer refuses another module's, nor the
|
|
# maintainer's real run beside the suite.
|
|
os.environ.setdefault("RETROBIOS_REPOSITORY_LOCK_DIR", str(_SCRATCH / "repository-lock"))
|
|
# 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(_SCRATCH / "cache"))
|
|
|
|
|
|
def scratch_dir(test: unittest.TestCase) -> Path:
|
|
"""A fresh directory under this module's scratch folder, removed after
|
|
the test."""
|
|
path = Path(tempfile.mkdtemp())
|
|
test.addCleanup(shutil.rmtree, path, True)
|
|
return path
|