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

48 lines
2.3 KiB
Python

"""Affected-spell identity comparison, including collateral native bit matches."""
import copy
import sys
import unittest
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'ops'))
from spell_affect_compat import derive
class SpellAffectTest(unittest.TestCase):
def fixture(self):
source = [dict(id=10, family=4, mask=1 << 35),
dict(id=20, family=4, mask=2), dict(id=30, family=0, mask=0)]
target = [dict(SpellID=10, SpellClassSet=4, SpellClassMask=[-2147483648, 4, 0, 0]),
dict(SpellID=20, SpellClassSet=4, SpellClassMask=[-2147483648, 0, 0, 0]),
dict(SpellID=30, SpellClassSet=4, SpellClassMask=[-2147483648, 0, 0, 0]),
dict(SpellID=40, SpellClassSet=4, SpellClassMask=[0, 4, 0, 0])]
return source, target
def test_maps_identities_without_copying_bits_or_inputs(self):
source, target = self.fixture(); before = copy.deepcopy((source, target))
out = derive(source, target, 4, 1 << 35)
self.assertEqual((source, target), before)
self.assertEqual(out['target_mask'], [0, 4, 0, 0])
self.assertEqual(out['affected_source_spell_ids'], [10])
self.assertEqual(out['target_only_matches'], [40])
self.assertEqual(out['excluded_bits'], [dict(bit=31, unintended_source_spell_ids=[20, 30])])
def test_rejects_collateral_only_representation(self):
source, target = self.fixture(); target[0]['SpellClassMask'][1] = 0
with self.assertRaisesRegex(ValueError, 'exactly'): derive(source, target, 4, 1 << 35)
def test_rejects_missing_or_ambiguous_identities(self):
source, target = self.fixture()
for a, b in ((source, target[1:]), (source + source[:1], target), (source, target + target[:1])):
with self.assertRaises(ValueError): derive(a, b, 4, 1 << 35)
def test_rejects_unknown_family_and_secret_or_malformed_words(self):
source, target = self.fixture()
for value in (True, 'secret', 0x100000000):
bad = copy.deepcopy(target); bad[0]['SpellClassMask'][0] = value
with self.assertRaises(ValueError): derive(source, bad, 4, 1 << 35)
target[0]['SpellClassSet'] = 5
with self.assertRaises(ValueError): derive(source, target, 4, 1 << 35)
if __name__ == '__main__': unittest.main()