okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge main (87dfca0e7) into f-own-int: the 0.2.14 app branch, fixtures and CI fixes, the Qwen4-readiness tools, the shape-engine build scriptsffb3d9b31

main
2.4 KiB56 linesraw
1"""pytest, tools/: the tests here describe Linux and Windows PCs on x86 (NVIDIA, AMD and Intel cards; the Spark and the Mac tests say
2so themselves by patching the platform or the CPU). On a Mac every one of them ran the Mac or ARM branch instead: setup.main() goes to
3the Metal installer (`sys.platform == "darwin"`), strata_mcp takes the unified-memory path, and an Apple CPU reads as ARM64.
4
5On macOS only, for each test:
6* setup.py and tools/strata_mcp.py see sys.platform "linux" (their module-level `sys` is a view of the real one with another
7  platform; the rest of the process, and the tests' own skip decisions, still see darwin);
8* the CPU reads as x86_64 (platform.machine and strata_control.sysinfo.machine), as on GitHub's Linux runner.
9Linux and Windows are not touched. A test that wants darwin or arm64 patches it on top, as before (setup.sys.platform, is_arm64)."""
10import platform
11import sys
12from contextlib import ExitStack
13from unittest import mock
14
15import pytest
16
17LINUX_VIEW = ("setup", "strata_mcp")
18
19
20class _SysView:
21    """The real sys module with its own `platform`; every other read and write goes to sys itself."""
22
23    def __init__(self, real, platform_name):
24        object.__setattr__(self, "_real", real)
25        object.__setattr__(self, "platform", platform_name)
26
27    def __getattr__(self, name):
28        return getattr(object.__getattribute__(self, "_real"), name)
29
30    def __setattr__(self, name, value):
31        if name == "platform":
32            object.__setattr__(self, name, value)
33        else:
34            setattr(object.__getattribute__(self, "_real"), name, value)
35
36    def __delattr__(self, name):
37        if name == "platform":
38            object.__setattr__(self, name, "linux")
39        else:
40            delattr(object.__getattribute__(self, "_real"), name)
41
42
43@pytest.fixture(autouse=True)
44def _a_linux_x86_pc_on_macos():
45    if sys.platform != "darwin":
46        yield
47        return
48    from strata_control import sysinfo
49    with ExitStack() as stack:
50        stack.enter_context(mock.patch.object(platform, "machine", lambda: "x86_64"))
51        stack.enter_context(mock.patch.object(sysinfo, "machine", lambda: "x86_64"))
52        for name in LINUX_VIEW:
53            mod = sys.modules.get(name)
54            if mod is not None and getattr(mod, "sys", None) is sys:
55                stack.enter_context(mock.patch.object(mod, "sys", _SysView(sys, "linux")))
56        yield