883 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
63 lines
5.0 KiB
Python
63 lines
5.0 KiB
Python
"""Named category ingestion/serialization; no proc or timed-buff gameplay claims."""
|
|
import copy,json,sys,unittest
|
|
from pathlib import Path
|
|
from types import SimpleNamespace
|
|
ROOT=Path(__file__).resolve().parents[1];sys.path[:0]=[str(ROOT/'ops'),str(ROOT/'tests')]
|
|
import spell_definition_common as m,spell_passive_compat as codec
|
|
from spell_item_proc_compat import presentation_namespace
|
|
from turtle_data import spell_layout
|
|
import spell_restore_compat_test as restore
|
|
|
|
class SpellCategoryContextTest(unittest.TestCase):
|
|
def paths(self):
|
|
return Path.home()/'Servers/tortoise-wow/src/game/Spells/SpellDefines.h',ROOT.parent/'servers/trinity-forever/src/server/game/Miscellaneous/SharedDefines.h'
|
|
def fixture(self):
|
|
f=json.loads((ROOT/'tests/fixtures/source-spell-category-capture.json').read_text())
|
|
dbc=SimpleNamespace(by_id={int(k):v for k,v in f['disk_rows'].items()},string={int(k):v for k,v in f['strings'].items()}.__getitem__)
|
|
return f,dbc
|
|
def source(self,ident=52838,**patch):
|
|
f,dbc=self.fixture();raw=next(r for r in f['server_rows']if r['entry']==ident);opts=dict(family_namespace=f['family_namespace'],category_context=m.spell_category_namespace(*self.paths()))
|
|
if ident==52837:
|
|
source,target=self.paths();opts.update(proc_namespace_proof=m.proc_namespace(source,target.parent.parent/'Spells/SpellMgr.h',incoming_harmful=True),incoming_harmful_proc=True,passive_proc_presentation=presentation_namespace(source,target))
|
|
opts.update(patch)
|
|
return m.checked_constant_source(dbc,raw,spell_layout(),**opts)
|
|
def test_captured_magic_proc_parent_and_child_keep_distinct_categories(self):
|
|
for ident in (52837,52838):
|
|
src=self.source(ident);self.assertEqual((src['defense_type'],src['prevention_type']),(1,0))
|
|
self.assertEqual(src['entry'],ident)
|
|
with self.assertRaises(ValueError):self.source(ident,category_context=None)
|
|
self.assertEqual(self.source(52837)['proc_context']['target_proc_type_mask'],[139944,0])
|
|
with self.assertRaises(ValueError):self.source(52837,incoming_harmful_proc=False)
|
|
def test_category_mismatch_forgery_and_other_capture_dependencies_stay_blocked(self):
|
|
for mode in ('source','capture','boolean','proof','radius'):
|
|
f,dbc=self.fixture();raw=next(r for r in f['server_rows']if r['entry']==52838);proof=m.spell_category_namespace(*self.paths())
|
|
if mode=='source':raw['dmgClass']=2
|
|
elif mode=='capture':dbc.by_id[52838][spell_layout()['PreventionType']]=1
|
|
elif mode=='boolean':raw['dmgClass']=True
|
|
elif mode=='proof':proof['mappings'][1]['target_value']=2
|
|
else:raw['effectRadiusIndex1']=123;dbc.by_id[52838][spell_layout()['EffectRadiusIndex']]=123
|
|
with self.assertRaises(ValueError):m.checked_constant_source(dbc,raw,spell_layout(),family_namespace=f['family_namespace'],category_context=proof)
|
|
def builder(self):
|
|
src,native,schemas,maxima,registry,_=restore.RestorationCompatibilityTest().new_fixture();src=src[0]
|
|
src.update(spell_category_context=m.spell_category_namespace(*self.paths()),defense_type=1,prevention_type=0)
|
|
schemas['SpellCategories']=codec.fields(ROOT.parent/'tools/WoWDBDefs/definitions/SpellCategories.dbd','SpellCategories');maxima['SpellCategories']=1500000
|
|
occupied={t:{r['ID']for r in native.get(t,[])}for t in (*m.NEW_DEFINITION_CHILD_TABLES,'SpellCategories')}
|
|
effects={i:dict(codec.NEW_EFFECT_NEUTRAL,Effect=e[0],EffectAura=e[1],EffectBasePointsF=e[2]+1,EffectMiscValue=[e[7],0])for i,e in enumerate(src['effects'])if e[0]}
|
|
return src,effects,136235,schemas,maxima,registry,occupied
|
|
def test_shared_builder_serializes_required_category_with_stable_child_identity(self):
|
|
args=self.builder();rows=m.new_definition_records(*args,allocation_prefix='category-test');r=next(x for x in rows if x['table_name']=='SpellCategories')
|
|
self.assertEqual((r['record']['DefenseType'],r['record']['PreventionType']),(1,0));self.assertEqual(r['record']['SpellID'],args[0]['entry'])
|
|
self.assertEqual(codec.encode(r['record'],args[3]['SpellCategories']).hex(),r['wire_hex'])
|
|
self.assertEqual(m.new_definition_records(*args,allocation_prefix='category-test'),rows)
|
|
self.assertEqual(len({(r['table_name'],r['id'])for r in rows}),len(rows))
|
|
def test_category_cannot_be_silently_dropped_or_written_under_wrong_schema(self):
|
|
for index in (3,4,6):
|
|
args=list(self.builder());del args[index]['SpellCategories']
|
|
with self.assertRaisesRegex(ValueError,'category'):m.new_definition_records(*args,allocation_prefix='category-test')
|
|
args=list(self.builder());args[3]['SpellCategories']=args[3]['SpellLevels']
|
|
with self.assertRaisesRegex(ValueError,'category schema'):m.new_definition_records(*args,allocation_prefix='category-test')
|
|
args=list(self.builder());args[0]['prevention_type']=4
|
|
with self.assertRaises(ValueError):m.new_definition_records(*args,allocation_prefix='category-test')
|
|
|
|
if __name__=='__main__':unittest.main()
|