Files
WoW-Hybrid-gateway/tests/native_profession_icons_test.py
praxisandClaude Fable 5.2 7f2139d8d0 Offline test fixtures
883 files, from working commit b1a079a.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-19 01:32:48 +02:00

44 lines
3.3 KiB
Python

"""Native atlas relationship derivation and exact original-widget posthooks."""
from pathlib import Path
import subprocess, sys
ROOT=Path(__file__).resolve().parents[1]
sys.path.insert(0,str(ROOT/'ops'))
from native_profession_border_profile import profile, lua
name='auctionhouse-itemicon-border-white'
elements=[dict(ID=11419,Name=name)]
members=[dict(ID=1,UiTextureAtlasID=1,Width=136,Height=136,CommittedLeft=139,CommittedRight=275,CommittedTop=715,CommittedBottom=851,UiTextureAtlasElementID=11419,UiCanvasID=0),
dict(ID=2,UiTextureAtlasID=2,Width=64,Height=64,CommittedLeft=25,CommittedRight=89,CommittedTop=1,CommittedBottom=65,UiTextureAtlasElementID=11419,UiCanvasID=0)]
atlases=[dict(ID=1,FileDataID=3046538,AtlasWidth=1024,AtlasHeight=1024,UiCanvasID=1,UiTextureAtlasSetID=0),
dict(ID=2,FileDataID=8164391,AtlasWidth=512,AtlasHeight=128,UiCanvasID=1,UiTextureAtlasSetID=1)]
data=profile(elements,members,atlases)
assert data['atlases'][name]['base']['rect']==[139/1024,275/1024,715/1024,851/1024]
assert lua(data)==lua(profile(elements,members,atlases))
for bad in [members+[members[0]], [dict(members[0],CommittedRight=1025),members[1]], [members[1]]]:
try:profile(elements,bad,atlases)
except ValueError:pass
else:raise AssertionError('Invalid/ambiguous native sprite accepted')
script=r'''
unpack=table.unpack;local callback,secret=nil,{}
function issecretvalue(v)return v==secret end
function CreateFrame()return {RegisterEvent=function()end,SetScript=function()end,UnregisterEvent=function()end}end
Professions={SetupOutputIconCommon=function()return 'original' end}
local original=Professions.SetupOutputIconCommon
function hooksecurefunc(owner,key,fn)assert(owner[key]==original and not callback);callback=fn end
local good={file=8164391,leftTexCoord=25/512,rightTexCoord=89/512,topTexCoord=1/128,bottomTexCoord=65/128}
local current=good;C_Texture={GetAtlasInfo=function()return current end}
local function texture(name)return {GetAtlas=function()return name end,SetTexture=function(self,v)self.file=v end,SetTexCoord=function(self,...)self.rect={...}end}end
local border,normal,green=texture('auctionhouse-itemicon-border-white'),texture('auctionhouse-itemicon-border-white'),texture('auctionhouse-itemicon-border-green')
local button={CircleMask={},GetRegions=function()return border,normal,green end}
dofile(arg[1]);dofile(arg[2]);assert(callback and Professions.SetupOutputIconCommon==original)
callback(button)
assert(border.file==3046538 and normal.file==3046538 and not green.file)
assert(border.rect[1]==139/1024 and border.rect[4]==851/1024)
border.file=nil;current={file=123};callback(button);assert(not border.file)
current={file=secret};callback(button);assert(not border.file)
current=secret;callback(button);assert(not border.file)
current=good;button.CircleMask=nil;callback(button);assert(not border.file)
dofile(arg[2]);assert(Professions.SetupOutputIconCommon==original and original()=='original')
'''
subprocess.run(['lua','-',str(ROOT/'client_addons/WoWHybridUI/NativeProfessionBorderData.lua'),str(ROOT/'client_addons/WoWHybridUI/NativeProfessionIcons.lua')],input=script.encode(),check=True)
print('Deterministic native sprite relations, exact override matching, both border layers, unknown/secret guards, unrelated quality preservation and original function ownership PASS.')