import os import struct import sys import tempfile from pathlib import Path import pytest sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src")) # modules that read settings at import time (UI) run during collection, before the per-test fixture below os.environ["FRAMEPORT_HOME"] = tempfile.mkdtemp(prefix="frameport-tests-") os.environ.pop("FRAMEPORT_WINDOWS_DATA", None) # a WSL dev shell may share the Windows data folder: never in tests @pytest.fixture(autouse=True) def isolated_home(tmp_path, monkeypatch): """Never touch the real user data dir (tools, keystores, library) from tests.""" from frameport.core import library, paths monkeypatch.setenv("FRAMEPORT_HOME", str(tmp_path / "home")) monkeypatch.setattr(library, "REFRESH_ON_UPDATE", False) # hand-made test libraries have no version marker yield paths._removed.clear() # an uninstall test marks the data folder as removed for the rest of the process # ---------------------------------------------------------------------------------------------- AXML builder def build_axml(elements, strings_extra=()): """elements: list of ("start", name, [(attr, kind, value)]) / ("end", name). kind: "str" | "bool" | "int" | "ref". Produces a UTF-16 string-pool binary XML like aapt does (enough for our editor).""" ns = "http://schemas.android.com/apk/res/android" pool = [] def idx(s): if s not in pool: pool.append(s) return pool.index(s) idx(ns) for e in elements: idx(e[1]) if e[0] == "start": for a, kind, v in e[2]: idx(a) if kind == "str": idx(v) for s in strings_extra: idx(s) data = b"" offsets = [] for s in pool: offsets.append(len(data)) data += struct.pack("