Files
hms-mediaengine/tests/unit/test_portable_paths.py
T

55 lines
2.1 KiB
Python
Raw Normal View History

"""Unit-Tests portable Pfade (PLAN.md §9, §9.1)."""
from __future__ import annotations
from pathlib import Path
from hms_launcher import AppPaths
def test_paths_are_relative_to_root(tmp_path: Path) -> None:
paths = AppPaths(root=tmp_path)
assert paths.app == tmp_path / "app"
assert paths.runtime == tmp_path / "runtime"
assert paths.gstreamer_bin == tmp_path / "runtime" / "gstreamer" / "bin"
assert paths.gstreamer_plugins == tmp_path / "runtime" / "gstreamer" / "lib" / "gstreamer-1.0"
assert paths.database == tmp_path / "userdata" / "database"
assert paths.cache == tmp_path / "userdata" / "cache"
assert paths.identity == tmp_path / "userdata" / "identity" / "node_id"
# Keine Laufwerksbuchstaben, keine absoluten Fremdpfade
assert not str(paths.app).startswith("C:")
def test_ensure_writable(tmp_path: Path) -> None:
assert AppPaths(root=tmp_path).ensure_writable() is True
assert not (tmp_path / ".write_probe").exists() # Probe wird aufgeräumt
def test_ensure_writable_false_on_write_error(tmp_path: Path, monkeypatch) -> None:
"""Schreibfehler (z. B. schreibgeschütztes Medium) → False.
Der Fehler wird simuliert, weil root in Containern Verzeichnisrechte
umgeht und ein chmod-Test dort falsch grün/rot wäre.
"""
from pathlib import Path as _Path
def _raise_write(self, *args, **kwargs):
raise OSError("read-only file system")
monkeypatch.setattr(_Path, "write_text", _raise_write)
assert AppPaths(root=tmp_path).ensure_writable() is False
def test_portable_environment_sets_gstreamer_vars(tmp_path: Path) -> None:
paths = AppPaths(root=tmp_path)
env = paths.portable_environment()
assert env["GST_PLUGIN_PATH_1_0"].endswith("gstreamer-1.0")
assert env["GST_PLUGIN_SYSTEM_PATH_1_0"] == "" # System-Plugins unterdrückt
def test_portable_environment_prepends_bundled_bin(tmp_path: Path) -> None:
gs_bin = tmp_path / "runtime" / "gstreamer" / "bin"
gs_bin.mkdir(parents=True)
env = AppPaths(root=tmp_path).portable_environment()
assert env["PATH"].startswith(str(gs_bin))