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

63 lines
3.0 KiB
Python

#!/usr/bin/env python3
"""Preserve the Source primary school through native weapon magnitude retention."""
from copy import deepcopy
import json
from pathlib import Path
import sys
import unittest
ROOT=Path(__file__).resolve().parents[1]
sys.path.insert(0,str(ROOT/'ops'))
import item_sparse_compat as sparse
class WeaponPrimarySchool(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.fixture=json.loads((ROOT/'tests/fixtures/item-weapon-primary-school.json').read_text())
cls.schema=sparse.fields(ROOT.parent/'tools/WoWDBDefs/definitions/ItemSparse.dbd')
def convert(self,source=None,native=None):
f=self.fixture
return sparse.convert(source or f['source'],f['basic'],f['points'],self.schema,native or f['native'])
def test_actual_same_id_nature_wand_and_existing_magnitude_parameters(self):
before=deepcopy(self.fixture);row=self.convert();source=before['source'];native=before['native']
self.assertEqual((source['entry'],source['dmg_type1'],native['DamageType']),(16997,3,3))
self.assertEqual(row['DamageType'],3)
self.assertEqual(row['DmgVariance'],native['DmgVariance'])
self.assertEqual(row['QualityModifier'],native['QualityModifier'])
for field,key in [('ItemLevel','item_level'),('OverallQualityID','quality'),('ItemDelay','delay')]:
self.assertEqual(row[field],source[key])
sparse.encode(row,self.schema)
self.assertEqual(self.fixture,before)
def test_all_source_schools_win_over_unrelated_native_school(self):
source=self.fixture['source'];native=self.fixture['native']
physical=self.convert(dict(source,dmg_type1=0),dict(native,DamageType=6))
wire=sparse.encode(physical,self.schema)
for school in range(7):
row=self.convert(dict(source,dmg_type1=school),dict(native,DamageType=(school+1)%7))
self.assertEqual(row['DamageType'],school)
self.assertEqual({k:v for k,v in row.items()if k!='DamageType'},
{k:v for k,v in physical.items()if k!='DamageType'})
actual=sparse.encode(row,self.schema)
self.assertEqual(len(actual),len(wire))
changed=[i for i,(a,b)in enumerate(zip(wire,actual))if a!=b]
self.assertEqual(len(changed),int(school!=0))
if school:self.assertEqual((wire[changed[0]],actual[changed[0]]),(0,school))
def test_unknown_missing_or_coerced_school_never_becomes_physical(self):
for school in [-1,7,True,3.0,'3',None]:
with self.assertRaisesRegex(ValueError,'primary weapon school'):
self.convert(dict(self.fixture['source'],dmg_type1=school))
source=dict(self.fixture['source']);source.pop('dmg_type1')
with self.assertRaisesRegex(ValueError,'primary weapon school'):self.convert(source)
def test_unrelated_native_identity_still_rejects(self):
with self.assertRaisesRegex(ValueError,'identity differs'):
self.convert(native=dict(self.fixture['native'],ID=16998))
if __name__=='__main__':unittest.main()