Files
WoW-Hybrid-gateway/tests/turtle_tooltip_level_data_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

77 lines
5.8 KiB
Python

"""Focused tooltip producer fields/SQL authority; in-memory fixtures only."""
import copy
from pathlib import Path
import struct
import sys
import unittest
ROOT=Path(__file__).resolve().parents[1]
sys.path.insert(0,str(ROOT/'ops'));sys.path.insert(0,str(ROOT/'tests'))
import turtle_data as m
from native_tooltip_closure_test import SQL_SHAPE
def bits(v):return struct.unpack('<I',struct.pack('<f',v))[0]
def word(v):return v&0xffffffff
class Store:
def __init__(self,fields,by_id):self.fields=fields;self.by_id=by_id
class Source(Store):
def __init__(self):
self.offsets=m.spell_layout();rows={};self.text={0:'',1:'Root',2:'Rank 1',3:'Uses $20s1',4:'Dependency'}
for ident in [10,20]:
row=[0]*173;row[0]=ident;row[self.offsets['Name_lang']]=1 if ident==10 else 4;row[self.offsets['NameSubtext_lang']]=2
row[self.offsets['Description_lang']]=3 if ident==10 else 0
for name,value in [('MaxLevel',80),('BaseLevel',10),('SpellLevel',20),('DurationIndex',19)]:row[self.offsets[name]]=value
row[self.offsets['Effect']]=6;row[self.offsets['EffectBasePoints']]=word(-3);row[self.offsets['EffectBaseDice']]=1;row[self.offsets['EffectDieSides']]=6
row[self.offsets['EffectDicePerLevel']]=bits(.5);row[self.offsets['EffectRealPointsPerLevel']]=bits(-5);row[self.offsets['EffectPointsPerCombo']]=bits(.25)
rows[ident]=row
super().__init__(173,rows);self.rows=list(rows.values())
def string(self,ident):return self.text[ident]
def server(ident=10):
row=copy.deepcopy(SQL_SHAPE);row.update(entry=ident,maxLevel=65,baseLevel=25,spellLevel=30,durationIndex=19)
row.update(effectBasePoints1=0xffffffff,effectBaseDice1=2,effectDieSides1=6,effectDicePerLevel1=.25,effectRealPointsPerLevel1=-.5,effectPointsPerComboPoint1=20)
# Numeric SQL authority must not replace Source text/graph identities.
row.update(name='SQL text not selected by this presentation producer',effectTriggerSpell1=0,effectRadiusIndex1=0,effectRadiusIndex2=0,effectRadiusIndex3=0)
return row
class TurtleTooltipLevelDataTest(unittest.TestCase):
def setUp(self):self.source=Source();self.duration=Store(4,{19:(19,30000,500,40000)})
def graph(self,**kwargs):return m.spell_tooltip_graph(self.source,[10],duration_candidates=(self.duration,),**kwargs)
def test_dbc_fallback_keeps_signed_and_floating_effect_fields(self):
value=self.graph()['records'][10];effect=value['effects'][0]
self.assertEqual((value['maxLevel'],value['baseLevel'],value['spellLevel']),(80,10,20))
self.assertEqual((effect['basePoints'],effect['baseDice'],effect['dicePerLevel'],effect['pointsPerLevel'],effect['pointsPerComboPoint']),(-3,1,.5,-5,.25))
def test_current_sql_numeric_authority_and_dependency_closure(self):
graph=self.graph(server_templates={10:server(),20:server(20)});value=graph['records'][10];effect=value['effects'][0]
self.assertEqual(set(graph['records']),{10,20});self.assertEqual(value['name'],'Root')
self.assertEqual((value['maxLevel'],value['baseLevel'],value['spellLevel']),(65,25,30))
self.assertEqual((effect['basePoints'],effect['baseDice'],effect['dicePerLevel'],effect['pointsPerLevel'],effect['pointsPerComboPoint']),(-1,2,.25,-.5,20))
def test_missing_sql_row_retains_explicit_dbc_fallback(self):
self.assertEqual(self.graph(),self.graph(server_templates={}))
def test_wrong_sql_identity_and_nonfinite_coefficients_reject(self):
with self.assertRaisesRegex(ValueError,'identity'):self.graph(server_templates={10:server(11)})
bad=server();bad['effectDicePerLevel1']=float('nan')
with self.assertRaisesRegex(ValueError,'Nonfinite'):self.graph(server_templates={10:bad})
def test_duration19_is_nominal_base_not_level_scaled(self):
value=self.graph()['records'][10]
self.assertEqual(value['durationMs'],30000);self.assertEqual(value['sourceDurationFields'],[30000,500,40000])
def test_negative_duration_absolute_and_permanent_or_zero_hold(self):
self.duration.by_id[19]=(19,word(-30000),500,word(-40000));value=self.graph()['records'][10]
self.assertEqual(value['durationMs'],30000);self.assertEqual(value['sourceDurationFields'],[-30000,500,-40000])
for base in [-1,0,-0x80000000]:
with self.subTest(base=base):
self.duration.by_id[19]=(19,word(base),500,40000);graph=self.graph()
self.assertNotIn('durationMs',graph['records'][10]);self.assertTrue(any(x['kind']=='zero-or-permanent-duration'for x in graph['issues']))
def test_ambiguous_duration_candidates_remain_held(self):
other=Store(4,{19:(19,31000,500,40000)})
graph=m.spell_tooltip_graph(self.source,[10],duration_candidates=(self.duration,other))
self.assertNotIn('durationMs',graph['records'][10]);self.assertTrue(any(x['kind']=='conflicting-duration'for x in graph['issues']))
def test_refresh_forwards_sql_without_changing_trees_or_known_state(self):
data={'tabs':[{'id':7,'name':'Source'}],'talents':[{'id':9,'tab':7,'ranks':[{'id':10,'name':'old','icon':'kept'}]}],'rankSuccessors':{'10':[20]},'known':{10:True}}
original=copy.deepcopy(data)
result,report=m.refresh_talent_data(data,self.source,duration_candidates=(self.duration,),server_templates={10:server(),20:server(20)})
self.assertEqual(data,original);self.assertEqual(result['tabs'],data['tabs']);self.assertEqual(result['known'],data['known'])
self.assertEqual([x['id']for x in result['talents'][0]['ranks']],[10]);self.assertEqual(result['talents'][0]['ranks'][0]['baseLevel'],25)
self.assertEqual(set(result['tooltipSpells']),{20});self.assertEqual(report['current_SQL_definition_records'],2)
self.assertFalse(report['relationships_or_server_state_changed'])
if __name__=='__main__':unittest.main()