883 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
63 lines
4.7 KiB
Python
63 lines
4.7 KiB
Python
import unittest,json,sys
|
|
from pathlib import Path
|
|
from copy import deepcopy
|
|
sys.path.insert(0,str(Path(__file__).resolve().parents[1]/'ops'))
|
|
import spell_set_modifier_compat as m
|
|
from spell_definition_common import checked_constant_source,new_definition_records,NEW_DEFINITION_CHILD_TABLES
|
|
from spell_affect_compat import derive
|
|
from turtle_data import spell_layout
|
|
F=json.loads((Path(__file__).parent/'fixtures/source-set-modifiers.json').read_text())
|
|
class Disk:
|
|
def __init__(self):self.by_id={int(i):r for i,r in F['disk'].items()}
|
|
def string(self,i):return F['strings'][str(i)]
|
|
class ModifierTest(unittest.TestCase):
|
|
def test_source_capture_all_classes_and_both_types(self):
|
|
for raw,source in zip(F['raw'],F['sources']):
|
|
self.assertEqual(m.source_spell(Disk(),raw,spell_layout(),semantics=F['namespace']),source)
|
|
self.assertEqual({e[1]for s in F['sources']for e in s['effects']if e[0]},{107,108})
|
|
def test_legacy_capture_does_not_acquire_class_or_itemtype_policy(self):
|
|
for raw in F['raw']:
|
|
with self.assertRaises(ValueError):checked_constant_source(Disk(),raw,spell_layout())
|
|
def test_capture_rejects_family_flags_and_affect_fallback_drift(self):
|
|
for key in ('spellFamilyName','spellFamilyFlags','effectItemType1'):
|
|
raw=deepcopy(F['raw'][0]);raw[key]+=1
|
|
with self.assertRaises(ValueError):m.source_spell(Disk(),raw,spell_layout(),semantics=F['namespace'])
|
|
def test_no_proc_mixed_scale_visual_or_unknown_operation(self):
|
|
for mutate in (lambda s:s['conditions'].__setitem__('procFlags',1),lambda s:s['effects'][0].__setitem__(1,42),lambda s:s['effects'][0].__setitem__(6,1),lambda s:s['visuals'].__setitem__(0,1),lambda s:s['effects'][0].__setitem__(7,31)):
|
|
s=deepcopy(F['sources'][0]);mutate(s)
|
|
with self.assertRaises(ValueError):m.validate_source(s)
|
|
def test_signed_native_wire_mask_words_preserve_all_bits(self):
|
|
self.assertEqual(m.native_mask_words([0x80000000,0xffffffff,0,1]),[-2147483648,-1,0,1])
|
|
for words in ([1]*3,[1<<32,0,0,0]):
|
|
with self.assertRaises(ValueError):m.native_mask_words(words)
|
|
def test_named_namespace_drift_cannot_copy_numeric_custom_operation(self):
|
|
p=deepcopy(F['namespace']);p['operations'][0]['target_name']='Doses'
|
|
with self.assertRaises(ValueError):m.validate_namespace(p)
|
|
self.assertNotIn(31,{r['source_value']for r in F['namespace']['operations']})
|
|
def snapshot(self,src,rows):
|
|
return dict(kind='local-read-only-exact-set-modifier-affect-snapshot',named_columns=['entry','effectId','SpellFamilyMask'],equal=True,mutated=False,first_sha256='a'*64,second_sha256='a'*64,spell_ids=[src['entry']],rows=rows)
|
|
def test_override_precedes_fallback_and_duplicate_or_missing_scope_rejected(self):
|
|
s=F['sources'][0];snap=self.snapshot(s,[dict(entry=s['entry'],effect_index=0,source_mask=1<<40)])
|
|
self.assertEqual(m.effective_affect_mask(s,0,snap),1<<40)
|
|
self.assertEqual(m.effective_affect_mask(s,1,snap),s['source_effect_affect_fallbacks'][1])
|
|
snap['rows']*=2
|
|
with self.assertRaises(ValueError):m.effective_affect_mask(s,0,snap)
|
|
snap=self.snapshot(s,[]);snap['spell_ids']=[]
|
|
with self.assertRaises(ValueError):m.effective_affect_mask(s,0,snap)
|
|
def test_identity_mask_remap_rejects_extra_or_missing_class_matches(self):
|
|
source=[dict(id=1,family=11,mask=1),dict(id=2,family=11,mask=2)];target=[dict(SpellID=1,SpellClassSet=11,SpellClassMask=[0,32,0,0]),dict(SpellID=2,SpellClassSet=11,SpellClassMask=[64,0,0,0])]
|
|
self.assertEqual(derive(source,target,11,1)['target_mask'],[0,32,0,0])
|
|
target[1]['SpellClassMask']=[0,32,0,0]
|
|
with self.assertRaises(ValueError):derive(source,target,11,1)
|
|
with self.assertRaises(ValueError):derive(source,target[1:],11,1)
|
|
def test_shared_allocator_preserves_all_class_and_rejects_unsupported_parent_mask(self):
|
|
s=deepcopy(F['sources'][0]);schemas=F['schemas'];maxima={t:1000000 for t in schemas};registry=dict(schema_version=1,build=m.BUILD,SpellEffect={});occupied={t:set()for t in NEW_DEFINITION_CHILD_TABLES};indices=m.validate_source(s)
|
|
from spell_passive_compat import NEW_EFFECT_NEUTRAL
|
|
effects={i:dict(deepcopy(NEW_EFFECT_NEUTRAL),EffectAura=s['effects'][i][1],EffectBasePointsF=s['effects'][i][2]+1,EffectMiscValue=[s['effects'][i][7],0],EffectSpellClassMask=[0,32,0,0])for i in indices}
|
|
records=new_definition_records(s,effects,135790,schemas,maxima,registry,occupied,allocation_prefix='test-set-modifier')
|
|
self.assertEqual(next(r['record']['SpellClassSet']for r in records if r['table_name']=='SpellClassOptions'),11)
|
|
self.assertEqual(next(r['record']['EffectSpellClassMask']for r in records if r['table_name']=='SpellEffect'),[0,32,0,0])
|
|
s['class_family']['source_mask'][0]=1
|
|
with self.assertRaises(ValueError):new_definition_records(s,effects,135790,schemas,maxima,registry,occupied,allocation_prefix='test-set-modifier')
|
|
if __name__=='__main__':unittest.main()
|