okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
ffb3d9b31
main
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 7platform; 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 23def __init__ (self ,real ,platform_name ): 24object .__setattr__ (self ,"_real" ,real ) 25object .__setattr__ (self ,"platform" ,platform_name ) 26 27def __getattr__ (self ,name ): 28return getattr (object .__getattribute__ (self ,"_real" ),name ) 29 30def __setattr__ (self ,name ,value ): 31if name == "platform" : 32object .__setattr__ (self ,name ,value ) 33else : 34setattr (object .__getattribute__ (self ,"_real" ),name ,value ) 35 36def __delattr__ (self ,name ): 37if name == "platform" : 38object .__setattr__ (self ,name ,"linux" ) 39else : 40delattr (object .__getattribute__ (self ,"_real" ),name ) 41 42 43@ pytest . fixture ( autouse = True ) 44def _a_linux_x86_pc_on_macos (): 45if sys .platform != "darwin" : 46yield 47return 48from strata_control import sysinfo 49with ExitStack ()as stack : 50stack .enter_context (mock .patch .object (platform ,"machine" ,lambda :"x86_64" )) 51stack .enter_context (mock .patch .object (sysinfo ,"machine" ,lambda :"x86_64" )) 52for name in LINUX_VIEW : 53mod = sys .modules .get (name ) 54if mod is not None and getattr (mod ,"sys" ,None )is sys : 55stack .enter_context (mock .patch .object (mod ,"sys" ,_SysView (sys ,"linux" ))) 56yield