初始化奇妙小屏幕控制器项目

This commit is contained in:
2026-09-08 22:56:52 +08:00
commit 8d368de3b5
491 changed files with 67678 additions and 0 deletions
@@ -0,0 +1,50 @@
from __future__ import annotations
import os
import tempfile
from pathlib import Path
_temporary_root: tempfile.TemporaryDirectory | None = None
configured_root = os.environ.get("MATRIX_TEST_ROOT")
legacy_worker_environment = (
not configured_root
and os.environ.get("MATRIX_SOURCE_ONLY_UPDATE_TESTS") == "1"
and bool(os.environ.get("MATRIX_DATA_DIR"))
and bool(os.environ.get("MATRIX_RUNTIME_DIR"))
)
if legacy_worker_environment:
configured_root = str(Path(os.environ["MATRIX_DATA_DIR"]).parent / "test-root")
if configured_root:
test_root = Path(configured_root)
else:
_temporary_root = tempfile.TemporaryDirectory(
prefix="matrix-screen-controller-pytest-",
)
test_root = Path(_temporary_root.name)
test_root.mkdir(parents=True, exist_ok=True)
if legacy_worker_environment:
temporary_path = test_root / "tmp"
temporary_path.mkdir(parents=True, exist_ok=True)
os.environ["MATRIX_TEST_ROOT"] = str(test_root)
os.environ["TMPDIR"] = str(temporary_path)
os.environ["TEMP"] = str(temporary_path)
os.environ["TMP"] = str(temporary_path)
tempfile.tempdir = str(temporary_path)
os.environ["MATRIX_DRIVER"] = "mock"
os.environ["MATRIX_DATA_DIR"] = str(test_root / "data")
os.environ["MATRIX_RUNTIME_DIR"] = str(test_root / "runtime")
os.environ.pop("STATE_DIRECTORY", None)
os.environ.pop("RUNTIME_DIRECTORY", None)
def pytest_configure(config) -> None:
if legacy_worker_environment and config.option.basetemp is None:
config.option.basetemp = str(test_root / "pytest")
def pytest_sessionfinish(session, exitstatus) -> None:
del session, exitstatus
if _temporary_root is not None:
_temporary_root.cleanup()