883 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
75 lines
4.0 KiB
Python
75 lines
4.0 KiB
Python
"""Named all-magic71→global57 percentage mapping; specific schools stay held."""
|
|
from copy import deepcopy
|
|
from pathlib import Path
|
|
import json,unittest
|
|
import spell_item_school_crit_compat as m
|
|
import spell_item_static_compat as static
|
|
import spell_passive_compat as codec
|
|
from octo_client_data import canonical_sha256
|
|
ROOT=Path(__file__).resolve().parents[1]
|
|
|
|
class AllMagicSchoolCrit(unittest.TestCase):
|
|
def fixture(self):
|
|
f=json.loads((ROOT/'tests/fixtures/item-all-magic-school-crit.json').read_text())
|
|
schemas={t:codec.fields(ROOT.parent/'tools/WoWDBDefs/definitions'/(t+'.dbd'),t)for t in ('SpellName','Spell','SpellMisc','SpellEffect','SpellLevels')}
|
|
return f,schemas
|
|
def compose(self,source,native=None):
|
|
f,schemas=self.fixture()
|
|
c=m.component([source],native if native is not None else f['native'],schemas,{t:1500000 for t in schemas},dict(schema_version=1,build=codec.BUILD,SpellEffect={}),semantics=f['semantic_contract'],duration_reference=f['duration_reference'])
|
|
return c,schemas
|
|
def source(self):return self.fixture()[0]['sources'][0]
|
|
|
|
def test_named_all_magic_mapping_does_not_mutate_actual_source(self):
|
|
s=self.source();before=deepcopy(s);n=m.normalized_source(s,m.contract())
|
|
self.assertEqual(s,before);self.assertEqual((n['effects'][0][1],n['effects'][0][7]),(57,0))
|
|
self.assertEqual((s['effects'][0][1],s['effects'][0][7]),(71,126))
|
|
self.assertEqual(n['effects'][0][2],s['effects'][0][2])
|
|
|
|
def test_all_specific_school_masks_are_held(self):
|
|
for mask in (0,1,2,4,8,16,32,64,127):
|
|
with self.subTest(mask=mask):
|
|
s=self.source();s['effects'][0][7]=mask
|
|
with self.assertRaises(ValueError):m.normalized_source(s,m.contract())
|
|
|
|
def test_native_71_collision_is_rejected(self):
|
|
s=self.source();f,_=self.fixture();native=deepcopy(f['native'])
|
|
for e in native['SpellEffect']:
|
|
if e['SpellID']==s['entry']:e['EffectAura']=71
|
|
with self.assertRaises(ValueError):self.compose(s,native)
|
|
|
|
def test_percentage_and_actual_source_pins_are_retained(self):
|
|
s=self.source();s['effects'][0][2]+=3;c,schemas=self.compose(s)
|
|
e=next(r for r in c['records']if r['table_name']=='SpellEffect')
|
|
self.assertEqual(e['record']['EffectAura'],57);self.assertEqual(e['record']['EffectBasePointsF'],s['effects'][0][2]+1)
|
|
self.assertEqual(e['record']['EffectMiscValue'],[0,0])
|
|
self.assertEqual(c['spells'][0]['source_record_sha256'],canonical_sha256(s))
|
|
self.assertEqual(c['spells'][0]['source_definition']['effects'][0][1],71)
|
|
self.assertEqual(bytes.fromhex(e['wire_hex']),codec.encode(e['record'],schemas['SpellEffect']))
|
|
|
|
def test_missing_positive_parent_is_not_synthesized(self):
|
|
s=self.source();s['entry']=900001
|
|
with self.assertRaises(ValueError):self.compose(s)
|
|
|
|
def test_legacy_generic_crit_policy_still_rejects_source71(self):
|
|
with self.assertRaises(ValueError):static.validate_source(self.source(),percent_stat='spell-crit')
|
|
|
|
def test_semantic_contract_tamper_is_held(self):
|
|
proof=m.contract();proof['source_school_mask']=127
|
|
with self.assertRaises(ValueError):m.normalized_source(self.source(),proof)
|
|
|
|
def test_other_effect_or_metadata_shape_is_held(self):
|
|
for mutate in ('aura','extra','condition'):
|
|
with self.subTest(mutate=mutate):
|
|
s=self.source()
|
|
if mutate=='aura':s['effects'][0][1]=57
|
|
elif mutate=='extra':s['effects'][1]=deepcopy(s['effects'][0])
|
|
else:s['conditions']['procFlags']=1
|
|
with self.assertRaises(ValueError):m.normalized_source(s,m.contract())
|
|
|
|
def test_no_spell_or_item_id_allowlist_and_no_numeric_mask_coercion(self):
|
|
s=self.source();s['entry']=900001;m.normalized_source(s,m.contract())
|
|
s['effects'][0][7]=126.0
|
|
with self.assertRaises(ValueError):m.normalized_source(s,m.contract())
|
|
|
|
if __name__=='__main__':unittest.main()
|