883 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
262 lines
23 KiB
Python
262 lines
23 KiB
Python
import copy,hashlib,json,struct,sys,tempfile,unittest
|
|
from types import SimpleNamespace
|
|
from pathlib import Path
|
|
ROOT=Path(__file__).resolve().parents[1];sys.path.insert(0,str(ROOT/'ops'))
|
|
from turtle_data import DBC
|
|
from spell_passive_compat import fields,encode,TABLES,SUPPLEMENTAL_TABLES,NEW_MISC_NEUTRAL,NEW_EFFECT_NEUTRAL
|
|
from spell_item_static_compat import item_text_rows,item_text_namespace
|
|
from item_enchantment_visual_profile import defense_scalar_rows
|
|
from aura_definition_profile import SCALAR_POLICY,SCALAR_HEADER_PINS
|
|
from turtle_data import spell_layout
|
|
from item_source_corrections import generate
|
|
from item_sparse_compat import package_payloads
|
|
DIR=ROOT/'tests/fixtures';DBD=ROOT.parent/'tools/WoWDBDefs/definitions'
|
|
F=json.loads((DIR/'item-text-native.json').read_text());D=DBC(DIR/'item-text-source.dbc',173);E=DBC(DIR/'defense-enchant-source.dbc',24)
|
|
PROOF=dict(policy=SCALAR_POLICY,header_sha256=SCALAR_HEADER_PINS)
|
|
class Tests(unittest.TestCase):
|
|
def test_generic_text_pass_preserves_reviewed_constant_item_literals(self):
|
|
fixture=self.periodic_fixture();source,items,effect,proof=fixture
|
|
schema=fields(DBD/'Spell.dbd','Spell');record=dict(next(r for r in F['text']if r['ID']==22725),Description_lang='Reviewed constant 20.',AuraDescription_lang='')
|
|
raw=encode(record,schema)
|
|
for marker in ({'constant_description_policy':'new-item-school-damage-literal-definition-candidate-v2'},{'allocation_policy':'new-item-static-definition-parent'}):
|
|
row=dict(table_name='Spell',table_hash=hex(TABLES['Spell'][0]),id=22725,record=record,wire_hex=raw.hex(),sha256=hashlib.sha256(raw).hexdigest(),**marker)
|
|
result=item_text_rows(source,items,F['text'],[effect],[row],schema,proof)
|
|
self.assertFalse(result['rows']);self.assertEqual(result['blocked'],[dict(spell=22725,reason='published constant item text requires its static policy revalidation')])
|
|
def division_fixture(self,text='Generates $/10;s1 rage.'):
|
|
fixture=self.periodic_fixture(text,'');source,items,effect,proof=fixture;layout=spell_layout()
|
|
for field,value in [('Effect',30),('EffectAura',0),('EffectBasePoints',149),('EffectAuraPeriod',0),('EffectMiscValue',1)]:source.by_id[22725][layout[field]]=value
|
|
effect.update(Effect=30,EffectAura=0,EffectBasePointsF=150,EffectAuraPeriod=0,EffectMiscValue=[1,0])
|
|
return fixture
|
|
def test_constant_division_keeps_units_and_native_effect_binding(self):
|
|
fixture=self.division_fixture('Raw $s1; generates $/10;s1 rage.');before=copy.deepcopy(fixture[2]);r=self.periodic_batch(fixture)
|
|
self.assertFalse(r['blocked']);self.assertEqual(fixture[2],before);row=r['rows'][0]
|
|
self.assertEqual(row['record']['Description_lang'],'Raw $s2; generates $/10;s2 rage.')
|
|
self.assertEqual(row['constant_division_reviews']['22725:0'],dict(divisor=10,source_operand=150,source_quotient=15))
|
|
fixture=self.division_fixture('Generates $/10;15494s1 rage.');fixture[0].by_id[15494]=list(fixture[0].by_id[22725]);fixture[0].by_id[15494][0]=15494;fixture[2]['SpellID']=15494
|
|
row=self.periodic_batch(fixture)['rows'][0];self.assertEqual(row['record']['Description_lang'],'Generates $/10;15494s2 rage.')
|
|
def test_division_rejects_rounding_other_operators_and_mismatched_native_values(self):
|
|
for mode in ('fractional','variable','level','native','divisor','operator','long-token'):
|
|
fixture=self.division_fixture('Raw $s1; generates $/10;s1 rage.');source,items,effect,proof=fixture;l=spell_layout()
|
|
if mode=='fractional':source.by_id[22725][l['EffectBasePoints']]=150;effect['EffectBasePointsF']=151
|
|
elif mode=='variable':source.by_id[22725][l['EffectDieSides']]=21;effect.update(EffectBasePointsF=160,Variance=.125)
|
|
elif mode=='level':source.by_id[22725][l['EffectRealPointsPerLevel']]=struct.unpack('<I',struct.pack('<f',1))[0];effect['EffectRealPointsPerLevel']=1
|
|
elif mode=='native':effect['EffectBasePointsF']=151
|
|
else:fixture=self.division_fixture({'divisor':'Generates $/100;s1.','operator':'Generates $*10;s1.','long-token':'Generates $/10;s12.'}[mode])
|
|
self.assertFalse(self.periodic_batch(fixture)['rows'],mode)
|
|
def periodic_fixture(self,description='Tick every $t1 sec.',aura='Deals $s1 every $t1 sec.'):
|
|
changed=copy.deepcopy(D);layout=spell_layout();row=list(changed.by_id[22725]);original=changed.string
|
|
texts={987650:description,987651:aura,987652:''}
|
|
for field,offset in [('Description_lang',987650),('AuraDescription_lang',987651),('NameSubtext_lang',987652)]:row[layout[field]]=offset
|
|
changed.string=lambda offset:texts[offset]if offset in texts else original(offset)
|
|
for field,value in [('Effect',6),('EffectAura',3),('EffectBasePoints',19),('EffectDieSides',1),('EffectMiscValue',0),('EffectTriggerSpell',0),('EffectAuraPeriod',3000),('EffectRealPointsPerLevel',0),('EffectDicePerLevel',0)]:row[layout[field]]=value
|
|
changed.by_id[22725]=row
|
|
effect=dict(NEW_EFFECT_NEUTRAL,ID=991,SpellID=22725,EffectIndex=1,Effect=6,EffectAura=3,EffectBasePointsF=20,EffectAuraPeriod=3000,EffectMiscValue=[0,0])
|
|
source=Path('/home/praxis/Servers/tortoise-wow/src/game');target=ROOT.parent/'servers/trinity-forever/src/server/game'
|
|
proof=item_text_namespace(dict(source_defines=source/'Spells/SpellDefines.h',source_auras=source/'Spells/SpellAuraDefines.h',target_defines=target/'Miscellaneous/SharedDefines.h',target_auras=target/'Spells/Auras/SpellAuraDefines.h'))
|
|
items=[dict(entry=1,**{'spellid_'+str(k):22725 if k==1 else 0 for k in range(1,6)})]
|
|
return changed,items,effect,proof
|
|
def periodic_batch(self,fixture,*,effects=None):
|
|
source,items,effect,proof=fixture
|
|
return item_text_rows(source,items,F['text'],[effect]if effects is None else effects,[],fields(DBD/'Spell.dbd','Spell'),proof)
|
|
def test_period_and_amount_share_the_same_verified_effect_in_any_field_order(self):
|
|
for description,aura in [('Tick every $t1 sec.','Deals $s1 every $t1 sec.'),('Deals $s1 every $t1 sec.','Tick every $t1 sec.')]:
|
|
fixture=self.periodic_fixture(description,aura);before=copy.deepcopy(fixture[2]);result=self.periodic_batch(fixture)
|
|
self.assertFalse(result['blocked']);self.assertEqual(fixture[2],before);row=result['rows'][0]
|
|
self.assertEqual(row['record']['Description_lang'],description.replace('$s1','$s2').replace('$t1','$t2'))
|
|
self.assertEqual(row['periodic_interval_reviews']['22725:0'],dict(source_period_ms=3000,native_period_ms=3000,native_effect_id=991,source_effect_index=0,native_effect_index=1))
|
|
fixture[2]['EffectBasePointsF']=21
|
|
self.assertFalse(self.periodic_batch(fixture)['rows'])
|
|
def test_period_mismatch_ambiguity_fractional_seconds_and_unknown_totals_reject(self):
|
|
for mode in ('period','attributes','aura','duplicate','fraction','zero','total','long-token'):
|
|
fixture=self.periodic_fixture();source,items,effect,proof=fixture;effects=[effect]
|
|
if mode=='period':effect['EffectAuraPeriod']=2000
|
|
elif mode=='attributes':effect['EffectAttributes']=1
|
|
elif mode=='aura':effect['EffectAura']=8
|
|
elif mode=='duplicate':effects.append(dict(effect,ID=992))
|
|
elif mode in ('fraction','zero'):source.by_id[22725][spell_layout()['EffectAuraPeriod']]=1500 if mode=='fraction'else 0
|
|
elif mode=='total':fixture=self.periodic_fixture('Total $o1 every $t1 sec.');effects=[fixture[2]]
|
|
else:fixture=self.periodic_fixture('Tick $t12.');effects=[fixture[2]]
|
|
result=self.periodic_batch(fixture,effects=effects);self.assertFalse(result['rows'],mode);self.assertTrue(result['blocked'],mode)
|
|
def test_cross_spell_period_keeps_source_identity_and_uses_native_index(self):
|
|
fixture=self.periodic_fixture('Tick every $15494t1 sec.','')
|
|
fixture[0].by_id[15494]=list(fixture[0].by_id[22725]);fixture[0].by_id[15494][0]=15494
|
|
fixture[2]['SpellID']=15494;row=self.periodic_batch(fixture)['rows'][0]
|
|
self.assertEqual(row['record']['Description_lang'],'Tick every $15494t2 sec.')
|
|
self.assertEqual(row['referenced_source_to_native_effect_indices'],{'15494:0':1})
|
|
self.assertEqual(row['source_to_native_effect_indices'],{})
|
|
self.assertIn('15494:0',row['periodic_interval_reviews'])
|
|
def test_variable_family_text_requires_exact_existing_range_without_effect_changes(self):
|
|
source=Path('/home/praxis/Servers/tortoise-wow/src/game');target=ROOT.parent/'servers/trinity-forever/src/server/game'
|
|
proof=item_text_namespace(dict(source_defines=source/'Spells/SpellDefines.h',source_auras=source/'Spells/SpellAuraDefines.h',target_defines=target/'Miscellaneous/SharedDefines.h',target_auras=target/'Spells/Auras/SpellAuraDefines.h'))
|
|
for kind in (2,6,10,30):
|
|
aura=99 if kind==6 else 0
|
|
changed=copy.deepcopy(D);layout=spell_layout();row=list(changed.by_id[22725]);index=0
|
|
for name,value in [('Effect',kind),('EffectAura',aura),('EffectBasePoints',79),('EffectDieSides',41),('EffectMiscValue',0),('EffectTriggerSpell',0),('EffectRealPointsPerLevel',0),('EffectDicePerLevel',0)]:row[layout[name]+index]=value
|
|
changed.by_id[22725]=row;original=changed.string;at=row[layout['Description_lang']];changed.string=lambda offset:'Restores $s1.'if offset==at else original(offset)
|
|
effect=dict(NEW_EFFECT_NEUTRAL,ID=991,SpellID=22725,EffectIndex=0,Effect=kind,EffectAura=aura,EffectBasePointsF=100,Variance=.4,EffectMiscValue=[0,0]);before=copy.deepcopy(effect)
|
|
items=[dict(entry=1,**{'spellid_'+str(k):22725 if k==1 else 0 for k in range(1,6)})]
|
|
def run(value):return item_text_rows(changed,items,F['text'],[value],[],fields(DBD/'Spell.dbd','Spell'),proof)
|
|
result=run(effect);self.assertFalse(result['blocked']);self.assertEqual(effect,before);self.assertEqual(result['rows'][0]['record']['Description_lang'],'Restores $s1.')
|
|
self.assertEqual(result['rows'][0]['existing_variable_range_reviews']['22725:0'],dict(source_min=80,source_max=120,native_mean=100,native_variance=.4,native_effect_id=991))
|
|
for patch in (dict(Variance=.3),dict(EffectBasePointsF=101),dict(EffectBonusCoefficient=.5)):
|
|
self.assertFalse(run(dict(effect,**patch))['rows'])
|
|
def test_source_names_sync_even_when_descriptions_already_match(self):
|
|
items=[dict(entry=i,**{'spellid_'+str(k):i if k==1 else 0 for k in range(1,6)})for i in(15494,22725)]
|
|
text=[r['record']for r in self.batch()['rows']];layout=spell_layout()
|
|
names=[dict(ID=i,Name_lang=D.string(D.by_id[i][layout['Name_lang']]))for i in(15494,22725)]
|
|
names[0]['Name_lang']='Destination-only label';before=copy.deepcopy(names)
|
|
context=dict(native=names,schema=fields(DBD/'SpellName.dbd','SpellName'))
|
|
def run(published=None):return item_text_rows(D,items,text,F['effects'],[]if published is None else published,fields(DBD/'Spell.dbd','Spell'),PROOF,name_context=context)
|
|
result=run();self.assertEqual(names,before);self.assertEqual(len(result['rows']),1);row=result['rows'][0]
|
|
self.assertEqual(row['table_name'],'SpellName');self.assertEqual(row['id'],15494)
|
|
self.assertEqual(row['record']['Name_lang'],D.string(D.by_id[15494][layout['Name_lang']]))
|
|
self.assertEqual(run([row])['rows'],[])
|
|
forged=copy.deepcopy(row);forged['wire_hex']='00'
|
|
with self.assertRaisesRegex(ValueError,'bytes'):run([forged])
|
|
context['native']=[];self.assertEqual(len(run()['name_blocked']),2);self.assertFalse(run()['rows'])
|
|
context['native']=[before[0],before[0]]
|
|
with self.assertRaisesRegex(ValueError,'Duplicate'):run()
|
|
def duration_fixture(self,*,cross=False):
|
|
changed=copy.deepcopy(D);original=changed.string;layout=spell_layout();offset=changed.by_id[22725][layout['Description_lang']]
|
|
changed.string=lambda at:('Lasts $15494d.'if cross else'Lasts $d.')if at==offset else original(at)
|
|
ident=15494 if cross else 22725;row=list(changed.by_id[ident]);row[layout['DurationIndex']]=7;changed.by_id[ident]=row
|
|
misc=dict(NEW_MISC_NEUTRAL,ID=991,SpellID=ident,DurationIndex=7,SpellIconFileDataID=1)
|
|
duration=dict(ID=7,Duration=5000,MaxDuration=5000,DurationPerResource=0)
|
|
source=SimpleNamespace(fields=4,by_id={7:[7,5000,0,5000]},digest=lambda:'f'*64)
|
|
context=dict(source=source,native=[duration],misc=[misc],misc_schema=fields(DBD/'SpellMisc.dbd','SpellMisc'))
|
|
item=dict(entry=1,**{'spellid_'+str(k):22725 if k==1 else 0 for k in range(1,6)})
|
|
return changed,[item],context
|
|
def duration_batch(self,fixture,published=None):
|
|
changed,items,context=fixture
|
|
return item_text_rows(changed,items,F['text'],F['effects'],[]if published is None else published,fields(DBD/'Spell.dbd','Spell'),PROOF,duration_context=context)
|
|
def test_duration_tokens_preserve_original_syntax_and_pin_equal_timing(self):
|
|
for cross in (False,True):
|
|
x=self.duration_batch(self.duration_fixture(cross=cross));self.assertFalse(x['blocked']);row=x['rows'][0]
|
|
self.assertEqual(row['record']['Description_lang'],'Lasts $15494d.'if cross else'Lasts $d.')
|
|
review=row['duration_reference_reviews'][str(15494 if cross else 22725)]
|
|
self.assertEqual(review['duration_ms'],5000);self.assertEqual(review['source_duration_id'],review['target_duration_id']);self.assertEqual(row['source_duration_dbc_sha256'],'f'*64)
|
|
def test_duration_mismatch_scaling_missing_and_ambiguous_bindings_reject(self):
|
|
for mode in ('duration','maximum','resource','source-level','binding','pvp','minimum','missing','duplicate'):
|
|
fixture=self.duration_fixture();context=fixture[2]
|
|
if mode in ('duration','maximum','resource'):context['native'][0][{'duration':'Duration','maximum':'MaxDuration','resource':'DurationPerResource'}[mode]]=1
|
|
elif mode=='source-level':context['source'].by_id[7][2]=1
|
|
elif mode=='binding':context['misc'][0]['DurationIndex']=8
|
|
elif mode=='pvp':context['misc'][0]['PvPDurationIndex']=8
|
|
elif mode=='minimum':context['misc'][0]['MinDuration']=1
|
|
elif mode=='missing':context['misc']=[]
|
|
else:context['misc'].append(dict(context['misc'][0],ID=992))
|
|
x=self.duration_batch(fixture);self.assertFalse(x['rows'],mode);self.assertTrue(x['blocked'],mode)
|
|
def test_published_timing_override_is_validated_and_used(self):
|
|
fixture=self.duration_fixture();override=dict(fixture[2]['misc'][0],DurationIndex=8)
|
|
self.assertFalse(self.duration_batch(fixture,[self.published('SpellMisc',override)])['rows'])
|
|
row=self.published('SpellMisc',override);row['sha256']='0'*64
|
|
with self.assertRaisesRegex(ValueError,'bytes'):self.duration_batch(fixture,[row])
|
|
def test_distinct_duration_ids_require_identical_actual_timing_semantics(self):
|
|
fixture=self.duration_fixture();context=fixture[2];context['native'][0]['ID']=8;context['misc'][0]['DurationIndex']=8
|
|
result=self.duration_batch(fixture);self.assertFalse(result['blocked'])
|
|
proof=result['rows'][0]['duration_reference_reviews']['22725'];self.assertEqual((proof['source_duration_id'],proof['target_duration_id']),(7,8))
|
|
context['native'][0]['Duration']=6000
|
|
self.assertFalse(self.duration_batch(fixture)['rows'])
|
|
def cross_reference_batch(self,text,*,effects=None,native_text=None):
|
|
changed=copy.deepcopy(D);original=changed.string;offset=changed.by_id[22725][spell_layout()['Description_lang']]
|
|
changed.string=lambda at:text if at==offset else original(at)
|
|
item=dict(entry=1,**{'spellid_'+str(k):22725 if k==1 else 0 for k in range(1,6)})
|
|
return item_text_rows(changed,[item],F['text']if native_text is None else native_text,F['effects']if effects is None else effects,[],fields(DBD/'Spell.dbd','Spell'),PROOF)
|
|
def test_cross_spell_amount_uses_referenced_effect_and_preserves_real_spell_id(self):
|
|
x=self.cross_reference_batch('Grants $15494s2 extra attacks; also $15494s2.')
|
|
self.assertFalse(x['blocked']);self.assertEqual(len(x['rows']),1);row=x['rows'][0]
|
|
self.assertEqual(row['id'],22725)
|
|
self.assertEqual(row['record']['Description_lang'],'Grants $15494s1 extra attacks; also $15494s1.')
|
|
self.assertEqual(row['source_to_native_effect_indices'],{})
|
|
self.assertEqual(row['referenced_source_to_native_effect_indices'],{'15494:1':0})
|
|
self.assertEqual(set(row['referenced_source_record_sha256']),{'15494'})
|
|
def test_cross_spell_missing_wrong_ambiguous_and_long_tokens_do_not_authorize_text(self):
|
|
bad=copy.deepcopy(F['effects']);next(r for r in bad if r['SpellID']==15494 and r['EffectIndex']==0)['EffectBasePointsF']=999
|
|
duplicate=copy.deepcopy(F['effects']);row=copy.deepcopy(next(r for r in duplicate if r['SpellID']==15494 and r['EffectIndex']==0));row.update(ID=row['ID']+99999,EffectIndex=2);duplicate.append(row)
|
|
cases=[('Grants $15494s2.',dict(effects=bad)),('Grants $15494s2.',dict(effects=duplicate)),('Grants $15494s2.',dict(native_text=[r for r in F['text']if r['ID']!=15494])),('Grants $999999s1.',{}),('Grants $15494s20.',{}),('Grants $2147483648s1.',{}),('Grants $15494s2 for $d.',{})]
|
|
for text,kwargs in cases:
|
|
result=self.cross_reference_batch(text,**kwargs);self.assertFalse(result['rows'],text);self.assertTrue(result['blocked'],text)
|
|
def published(self,table,record):
|
|
raw=encode(record,fields(DBD/(table+'.dbd'),table))
|
|
return dict(table_name=table,table_hash=hex((TABLES|SUPPLEMENTAL_TABLES)[table][0]),id=record['ID'],record=copy.deepcopy(record),wire_hex=raw.hex(),sha256=hashlib.sha256(raw).hexdigest())
|
|
def test_newly_published_spells_and_effects_participate_without_native_extract_rows(self):
|
|
items=[dict(entry=i,**{'spellid_'+str(k):i if k==1 else 0 for k in range(1,6)})for i in(15494,22725)]
|
|
published=[self.published(t,r)for t,rows in [('Spell',F['text']),('SpellEffect',F['effects'])]for r in rows];before=copy.deepcopy(published)
|
|
args=(D,items,[],[],published,fields(DBD/'Spell.dbd','Spell'),PROOF)
|
|
x=item_text_rows(*args,effect_schema=fields(DBD/'SpellEffect.dbd','SpellEffect'))
|
|
self.assertEqual(x['rows'],self.batch()['rows']);self.assertEqual(published,before)
|
|
self.assertFalse(x['engine_accepted']);self.assertFalse(x['gameplay_verified'])
|
|
# An installed definition with different amounts cannot authorize source text.
|
|
other=copy.deepcopy(F['effects']);next(r for r in other if r['SpellID']==15494 and r['EffectIndex']==0)['EffectBasePointsF']=999
|
|
bad=[self.published(t,r)for t,rows in [('Spell',F['text']),('SpellEffect',other)]for r in rows]
|
|
y=item_text_rows(D,items,[],[],bad,args[5],PROOF,effect_schema=fields(DBD/'SpellEffect.dbd','SpellEffect'))
|
|
self.assertNotIn(15494,{r['id']for r in y['rows']})
|
|
def test_published_additions_require_schema_identity_and_exact_payload(self):
|
|
for table,record in [('Spell',F['text'][0]),('SpellEffect',F['effects'][0])]:
|
|
for mode in ('wire','hash','identity','table','removed'):
|
|
row=self.published(table,record)
|
|
if mode=='wire':row['wire_hex']='00'
|
|
elif mode=='hash':row['sha256']='0'*64
|
|
elif mode=='identity':row['id']+=1
|
|
elif mode=='table':row['table_hash']='0x1'
|
|
else:row['record_status']='removed'
|
|
with self.assertRaises(ValueError,msg=(table,mode)):
|
|
item_text_rows(D,[],[],[],[row],fields(DBD/'Spell.dbd','Spell'),PROOF,effect_schema=fields(DBD/'SpellEffect.dbd','SpellEffect'))
|
|
with self.assertRaisesRegex(ValueError,'schema'):
|
|
item_text_rows(D,[],[],[],[self.published('SpellEffect',F['effects'][0])],fields(DBD/'Spell.dbd','Spell'),PROOF)
|
|
def test_text_only_command_preserves_other_rows_and_is_idempotent(self):
|
|
with tempfile.TemporaryDirectory()as directory:
|
|
root=Path(directory);paths={};source=Path('/home/praxis/Servers/tortoise-wow/src/game');target=ROOT.parent/'servers/trinity-forever/src/server/game'
|
|
def pin(key,path):paths[key]=dict(path=str(path),sha256=hashlib.sha256(path.read_bytes()).hexdigest())
|
|
for key,path in dict(source_spells=DIR/'item-text-source.dbc',source_defines=source/'Spells/SpellDefines.h',source_auras=source/'Spells/SpellAuraDefines.h',target_defines=target/'Miscellaneous/SharedDefines.h',target_auras=target/'Spells/Auras/SpellAuraDefines.h').items():pin(key,path)
|
|
rows=[self.published(t,r)for t,values in [('Spell',F['text']),('SpellEffect',F['effects']),('SpellName',[dict(ID=9911,Name_lang='Unrelated spell')])]for r in values]
|
|
package=dict(build='1.60.1.70334',schema='wowstatic_camelot_1_60_1',id_remapping=False,rows=rows,push_id=package_payloads(rows)[0])
|
|
items=[dict(entry=i,**{'spellid_'+str(k):i if k==1 else 0 for k in range(1,6)})for i in(15494,22725)]
|
|
for key,value in dict(package=package,items=items,native_text=[],native_effects=[]).items():
|
|
path=root/(key+'.json');path.write_text(json.dumps(value));pin(key,path)
|
|
config=dict(item_text_only=True,inputs=paths,all_ready_metadata=True)
|
|
result,report=generate(config)
|
|
self.assertEqual(len(report['changed']),2);self.assertEqual(len(result['rows']),len(rows))
|
|
self.assertEqual([r for r in result['rows']if r['table_name']!='Spell'],[r for r in rows if r['table_name']!='Spell'])
|
|
p=root/'package.json';p.write_text(json.dumps(result));pin('package',p)
|
|
again,second=generate(config);self.assertEqual(again,result);self.assertEqual(second['changed'],[])
|
|
self.assertFalse(second['installed']);self.assertFalse(second['engine_accepted'])
|
|
def batch(self,effects=None,proof=PROOF):
|
|
items=[dict(entry=i,**{'spellid_'+str(k):i if k==1 else 0 for k in range(1,6)})for i in(15494,22725)]
|
|
return item_text_rows(D,items,F['text'],F['effects']if effects is None else effects,[],fields(DBD/'Spell.dbd','Spell'),proof)
|
|
def test_source_descriptions_and_swapped_indices(self):
|
|
x=self.batch();rows={r['id']:r for r in x['rows']}
|
|
self.assertEqual(rows[15494]['record']['Description_lang'],'Grants $s1 extra attacks on your next swing.')
|
|
self.assertEqual(rows[15494]['source_to_native_effect_indices'],{'1':0})
|
|
self.assertNotIn('Orc',str(rows[15494]['record']));self.assertIn('by 5.',rows[22725]['record']['Description_lang'])
|
|
self.assertFalse(x['installed']);self.assertEqual(x,self.batch())
|
|
def test_wrong_or_ambiguous_amount_is_not_substituted(self):
|
|
e=copy.deepcopy(F['effects']);next(r for r in e if r['SpellID']==15494 and r['EffectIndex']==0)['EffectBasePointsF']=999
|
|
self.assertNotIn(15494,{r['id']for r in self.batch(e)['rows']})
|
|
e=copy.deepcopy(F['effects']);other=copy.deepcopy(next(r for r in e if r['SpellID']==15494 and r['EffectIndex']==0));other['ID']+=100000;other['EffectIndex']=2;e.append(other)
|
|
self.assertNotIn(15494,{r['id']for r in self.batch(e)['rows']})
|
|
def test_namespace_proof_required(self):
|
|
with self.assertRaises(ValueError):self.batch(proof={})
|
|
def test_broader_namespace_is_derived_from_matching_symbolic_names(self):
|
|
source=Path('/home/praxis/Servers/tortoise-wow/src/game');target=ROOT.parent/'servers/trinity-forever/src/server/game'
|
|
proof=item_text_namespace(dict(source_defines=source/'Spells/SpellDefines.h',source_auras=source/'Spells/SpellAuraDefines.h',target_defines=target/'Miscellaneous/SharedDefines.h',target_auras=target/'Spells/Auras/SpellAuraDefines.h'))
|
|
self.assertIn('SPELL_AURA_MOD_SKILL',proof['auras']['30']);self.assertIn('SPELL_EFFECT_ADD_EXTRA_ATTACKS',proof['effects']['19'])
|
|
x=self.batch(proof=proof);self.assertEqual({r['id']for r in x['rows']},{15494,22725})
|
|
bad=copy.deepcopy(proof);bad['header_sha256']['source_auras']='0'*64
|
|
with self.assertRaises(ValueError):self.batch(proof=bad)
|
|
def test_long_effect_index_token_is_never_partially_rewritten(self):
|
|
changed=copy.deepcopy(D);original=changed.string;changed.string=lambda offset:original(offset).replace('$s2','$s20')
|
|
items=[dict(entry=1,**{'spellid_'+str(k):15494 if k==1 else 0 for k in range(1,6)})]
|
|
x=item_text_rows(changed,items,F['text'],F['effects'],[],fields(DBD/'Spell.dbd','Spell'),PROOF)
|
|
self.assertFalse(x['rows']);self.assertIn('complex',x['blocked'][0]['reason'])
|
|
def test_defense_enchant(self):
|
|
schema=fields(DBD/'SpellItemEnchantment.dbd','SpellItemEnchantment')
|
|
x=defense_scalar_rows(E,D,F['enchantments'],schema);r=x['rows'][0]['record'];old=F['enchantments'][0]
|
|
self.assertEqual(r['Name_lang'],'Defense +5');self.assertEqual(r['EffectPointsMin'],[5,0,0])
|
|
self.assertEqual({k for k in old if old[k]!=r[k]},{'Name_lang','EffectPointsMin'})
|
|
wrong=copy.deepcopy(F['enchantments']);wrong[0]['EffectArg']=[3,0,0]
|
|
self.assertFalse(defense_scalar_rows(E,D,wrong,schema)['rows'])
|
|
wrong=copy.deepcopy(F['enchantments']);wrong[0]['ScalingClass']=1
|
|
self.assertFalse(defense_scalar_rows(E,D,wrong,schema)['rows'])
|
|
if __name__=='__main__':unittest.main()
|