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

131 lines
7.1 KiB
Python

#!/usr/bin/env python3
import copy
import sys
import unittest
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'ops'))
import source_mount_compat as mounts
import source_catalogue_compat as catalogue
def source_spell(ident=36651):
# Actual public Source Black Drake prototype's three effect tuples.
row = {'entry': ident, 'attributes': 0x10118110}
for i, (effect, aura, base, misc) in enumerate(
[(6, 78, 0, 23051), (6, 32, 59, 0), (0, 0, 0, 0)], 1):
row.update({name+str(i): value for name, value in
[('effect', effect), ('effectApplyAuraName', aura),
('effectBasePoints', base), ('effectMiscValue', misc),
('effectTriggerSpell', 0)]})
return row
class SourceMountTest(unittest.TestCase):
def plan(self, collections=None, spells=None, **changes):
return mounts.source_mount_environment(
[{'itemId': 36551, 'spellId': 36651}] if collections is None else collections,
[source_spell()] if spells is None else spells,
native_type_records=changes.get('types', [mounts.NATIVE_TYPE]),
native_capability_records=changes.get('caps', [mounts.NATIVE_CAPABILITY]))
def test_actual_item_spell_namespaces_and_only_environment_changes(self):
items = [{'itemId': 36551, 'spellId': 36651}, {'itemId': 99999, 'spellId': 36651}]
spells = [source_spell()]
before = copy.deepcopy((items, spells))
plan = self.plan(items, spells)
self.assertEqual((plan['collection_items'], plan['qualified_spells']), (2, 1))
self.assertNotIn(36551, plan['profiles']) # Spell36551 is Death Roll.
row = {'ID': 3210, 'SourceSpellID': 36651, 'MountTypeID': 469,
'Name_lang': 'Black Drake', 'Flags': 0, 'PlayerConditionID': 0}
result = mounts.apply_source_mount_environment(row, plan['profiles'][36651])
self.assertEqual({k for k in row if row[k] != result[k]}, {'MountTypeID'})
self.assertEqual(result['MountTypeID'], 283)
self.assertEqual((items, spells), before)
self.assertEqual(plan['profiles'][36651]['native_capability']['ModSpellAuraID'], 0)
def test_foreign_horse_gate_or_speed_aura_and_extra_children_rejected(self):
for field, value in [('ReqSpellKnownID', 824), ('ReqRidingSkill', 75),
('ModSpellAuraID', 86457), ('ReqAreaID', 1)]:
with self.subTest(field=field), self.assertRaisesRegex(ValueError, 'contract'):
self.plan(caps=[dict(mounts.NATIVE_CAPABILITY, **{field: value})])
with self.assertRaisesRegex(ValueError, 'contract'):
self.plan(types=[mounts.NATIVE_TYPE, dict(mounts.NATIVE_TYPE, ID=2000)])
def test_scripted_aq_missing_or_unqualified_prototypes_remain_held(self):
missing = source_spell(2); del missing['effectMiscValue3']
scripted = source_spell(26656)
for i in (1, 2, 3):
scripted['effect'+str(i)] = scripted['effectApplyAuraName'+str(i)] = 0
exotic = source_spell(3); exotic.update(effect3=6, effectApplyAuraName3=12)
plan = self.plan([{'itemId': i, 'spellId': s} for i, s in
[(1, 36651), (2, 2), (3, 3), (4, 26656), (5, 7)]],
[source_spell(), missing, scripted, exotic])
self.assertEqual(set(plan['profiles']), {36651})
self.assertEqual({r['source_spell_id'] for r in plan['held']}, {2, 3, 7, 26656})
def test_generator_requires_proof_and_never_inherits_horse_template(self):
template = {'ID': 6, 'Name_lang': 'Brown Horse', 'MountTypeID': 469,
'SourceSpellID': 458, 'Flags': 0}
args = dict(icons={}, predecessors={}, spell_icons={})
spec = {'ID': 3210, 'Name': 'Black Drake', 'SourceSpellID': 36651,
'template_native_id': 6}
with self.assertRaisesRegex(ValueError, 'Qualified'):
catalogue.source_record('Mount', spec, [], {'Mount': {6: template}}, **args)
profile = self.plan()['profiles'][36651]
row = catalogue.source_record('Mount', spec, [], {'Mount': {6: template}},
mount_environment=profile, **args)
self.assertEqual(row['MountTypeID'], 283)
self.assertEqual(template['MountTypeID'], 469)
with self.assertRaisesRegex(ValueError, 'Qualified'):
mounts.apply_source_mount_environment(dict(row, SourceSpellID=36551), profile)
def test_shared_item_associations_do_not_choose_acquisition_spell(self):
plan = self.plan([{'itemId': 50402, 'spellId': 10799},
{'itemId': 50402, 'spellId': 46501}],
[source_spell(10799), source_spell(46501)])
self.assertEqual(plan['collection_rows'], 2)
self.assertEqual(plan['collection_items'], 1)
self.assertEqual(set(plan['profiles']), {10799, 46501})
self.assertEqual(plan['ambiguous_acquisition_items'], {50402: [10799, 46501]})
def test_direct_item_definition_requires_real_onuse_and_never_claims_learning(self):
item = {'entry': 2415, 'required_level': 40, 'required_skill': 762,
'required_skill_rank': 75}
for i in range(1, 6):
item.update({'spellid_'+str(i): 468 if i == 1 else 0,
'spelltrigger_'+str(i): 0})
before = copy.deepcopy(item)
args = dict(native_type_records=[mounts.NATIVE_TYPE],
native_capability_records=[mounts.NATIVE_CAPABILITY])
plan = mounts.source_item_mount_environment([item], [source_spell(468)], **args)
self.assertFalse(plan['profiles'][468]['learned_collection_ownership_claimed'])
self.assertEqual(item, before)
item['spelltrigger_1'] = 1
self.assertEqual(mounts.source_item_mount_environment(
[item], [source_spell(468)], **args)['profiles'], {})
def test_existing_native_join_only_replaces_qualified_source_type(self):
qualified = {'ID': 6, 'SourceSpellID': 36651, 'Name_lang': 'Native name',
'MountTypeID': 469, 'Flags': 64, 'PlayerConditionID': 99,
'Description_lang': 'Preserve', 'UiModelSceneID': 4}
unrelated = dict(qualified, ID=7, SourceSpellID=458)
scripted = dict(qualified, ID=8, SourceSpellID=26656)
native = [qualified, unrelated, scripted]
before = copy.deepcopy(native)
environment = self.plan()
environment['held'].append(dict(source_spell_id=26656, source_item_ids=[21176],
reason='scripted-Source-prototype'))
result = mounts.qualify_existing_source_mounts(native, environment)
self.assertEqual(result['records'], [dict(qualified, MountTypeID=283)])
self.assertEqual(result['unchanged'], [unrelated, scripted])
self.assertEqual(result['unrelated_native_rows'], 1)
self.assertEqual(result['held'][0]['id'], 8)
self.assertEqual(native, before)
with self.assertRaisesRegex(ValueError, 'Unique native'):
mounts.qualify_existing_source_mounts([qualified, qualified], environment)
if __name__ == '__main__':
unittest.main()