refactor: share the loopback server of the tests

Each installer test module rebuilt the same loopback fixture: a silent SimpleHTTPRequestHandler, a ThreadingHTTPServer on a daemon thread with its two cleanups, closed_port(), noise() and the CRC-32 text. tests/loopback.py holds them once; handlers with their own behaviour (Slow, Range, Held) pass in as handler=. The test_install servers that set log_message on a functools.partial, which never reached the handler, now use the quiet one. The journeys comment says why their root stays in tmp/.
This commit is contained in:
Abdessamad Derraz committed 2026-11-21 06:04:40 +01:00
1 parent 13db912e52
commit 98775b7e4d
15 files changed
+144 -285

No files matched your search

+3 -14
View File
@@ -12,10 +12,9 @@ directory the frontend's config names.
from __future__ import annotations
import tests
from tests import loopback
import functools
import hashlib
import http.server
import importlib.util
import json
import os
@@ -23,7 +22,6 @@ import shutil
import subprocess
import sys
import tempfile
import threading
import unittest
import zipfile
from pathlib import Path
@@ -698,15 +696,11 @@ class _Repository:
"base_destination": "system", "files": entries,
"save_directory": {"folder": "saves", "by_core": True}}
(self.root / "install" / "retroarch.json").write_text(json.dumps(manifest))
handler = functools.partial(_Quiet, directory=str(self.root))
self.httpd = http.server.ThreadingHTTPServer(("127.0.0.1", 0), handler)
threading.Thread(target=self.httpd.serve_forever, daemon=True).start()
test.addCleanup(self.httpd.server_close)
test.addCleanup(self.httpd.shutdown)
self.base = loopback.serve(test, self.root)
def run(self, *options: str) -> subprocess.CompletedProcess:
env = dict(os.environ)
env["RETROBIOS_BASE_URL"] = f"http://127.0.0.1:{self.httpd.server_address[1]}"
env["RETROBIOS_BASE_URL"] = self.base
return subprocess.run(
[sys.executable, str(REPO_ROOT / "install.py"), "--platform", "retroarch",
"--yes", *options],
@@ -715,11 +709,6 @@ class _Repository:
)
class _Quiet(http.server.SimpleHTTPRequestHandler):
def log_message(self, *args) -> None:
pass
class TheInstallerWritesThem(unittest.TestCase):
FILES = {
"sys.bin": (b"system file", {}),