38 lines
2.5 KiB
Python
38 lines
2.5 KiB
Python
#!/usr/bin/env python3
|
|
import importlib.util
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
import subprocess
|
|
import sys
|
|
ROOT=Path(__file__).resolve().parents[1]
|
|
if len(sys.argv)>1 and sys.argv[1]=='--build':
|
|
out=Path(sys.argv[2]).resolve();out.mkdir(parents=True,exist_ok=True)
|
|
subprocess.run([sys.executable,str(ROOT/'tests/hotfix_baked_audit_test.py'),'--build',str(out/'db2-reader')],check=True)
|
|
casc=Path(os.environ.get('GW_CASC_TOOL_ROOT','/mnt/Games/@project/tools/casc-tool'))
|
|
subprocess.run(['c++','-std=c++17','-O2','-Wall','-Wextra','-Werror','-I',str(casc/'vendor/CascLib/src'),str(ROOT/'ops/addon_db2_audit/CascIdentity.cpp'),str(casc/'build/vendor/CascLib/libcasc.a'),'-lz','-pthread','-o',str(out/'casc-identity')],check=True)
|
|
raise SystemExit(0)
|
|
sys.path.insert(0,str(ROOT/'ops'));import addon_db2_audit as audit
|
|
icons,armor,deps=audit.parse_data(ROOT/'client_addons')
|
|
assert len(icons)==26321 and len(armor)==9333
|
|
assert {k:len(v) for k,v in deps.items()}=={'itemSets':2200,'sets':358,'setSpells':358,'itemSpells':9956}
|
|
assert audit.compare([1,2],[1,2])=='identical'
|
|
assert audit.compare([1,2],[1,3])=='different'
|
|
assert audit.compare([1,2],None)=='missing'
|
|
# Independent arithmetic fixture: 2*100*.5=100 base, +10 flat armor; +5 block.
|
|
tables={'ItemArmorQuality':{20:{'ID':20,'Qualitymod':[1,1,2,3,4,5,6]}},'ItemArmorTotal':{20:{'ID':20,'ItemLevel':20,'Cloth':100}},'ArmorLocation':{5:{'ID':5,'Clothmodifier':.5}},'ItemArmorShield':{20:{'ID':20,'ItemLevel':20,'Quality':[10,20,30,40,50,60,70]}},'RandPropPoints':{20:{'ID':20,'GoodF':[100]*5}}}
|
|
item={'ID':1,'ClassID':4,'SubclassID':1}
|
|
sparse={'InventoryType':5,'ItemLevel':20,'OverallQualityID':2,'StatModifier_bonusStat':[50,48],'StatPercentEditor':[1000,500],'StatPercentageOfSocket':[0,0]}
|
|
assert audit.armor_value(item,sparse,tables)=={'armor':110,'block':5,'subclass':1}
|
|
item['SubclassID']=6;sparse['InventoryType']=14
|
|
assert audit.armor_value(item,sparse,tables)=={'armor':40,'block':5,'subclass':6}
|
|
sparse['StatPercentageOfSocket'][0]=1
|
|
try:audit.armor_value(item,sparse,tables)
|
|
except ValueError as e:assert 'Socket' in str(e)
|
|
else:raise AssertionError('unknown socket adjustment guessed')
|
|
config=os.environ.get('GW_ADDON_DB2_AUDIT_CONFIG')
|
|
if config:
|
|
options=json.loads(Path(config).read_text());args=[part for key,value in options.items() for part in ('--'+key,value)]
|
|
subprocess.run([sys.executable,str(ROOT/'ops/addon_db2_audit.py'),*args],check=True)
|
|
print('PASS strict addon data parsing, dependency equality and native armor/block arithmetic')
|