Files
WoW-Hybrid-gateway/tests/tradeskill_trainer_step_catalog_test.py

81 lines
4.3 KiB
Python

#!/usr/bin/env python3
"""Check the rank catalog join against recorded trainer and native spell row shapes."""
import json
from pathlib import Path
import struct
import subprocess
import sys
import tempfile
root = Path(__file__).resolve().parents[1]
generator = root / 'ops/tradeskill_trainer_steps.py'
with tempfile.TemporaryDirectory() as directory:
work = Path(directory)
catalog = work / 'catalog.sql'
effects = work / 'effects.jsonl'
abilities = work / 'abilities.tsv'
output = work / 'profile.hpp'
venues = work / 'venues.sql'
source = work / 'spell_template.sql'
skills = work / 'skills.tsv'
# 353 is the observed Alchemy trainer. The second service lacks its native
# step effect, and the second trainer has only an unverified catalog row.
catalog.write_text(
"INSERT IGNORE INTO `trainer` VALUES\n(353,2,'An alchemist\\'s trade; training, too.',70124),"
"(376,2,'Blacksmithing',70124),(999,2,'Alchemy',0); "
"INSERT IGNORE INTO `trainer_spell` VALUES\n"
"(353,2275,10,0,0,0,0,0,1,70124),(353,2331,100,171,25,0,0,0,0,70124),"
"(353,9001,10,0,0,0,0,0,1,70124),(999,2275,10,0,0,0,0,0,1,70124),"
"(999,2331,100,171,25,0,0,0,0,70124),(376,2021,500,164,50,0,0,0,10,70124);\n")
abilities.write_text('1374\tSkillLine=171\tSpell=2259\tTradeSkillCategoryID=0\n'
'smith\tSkillLine=164\tSpell=3100\tTradeSkillCategoryID=0\n')
skills.write_text('alchemy\tID=171\tCategoryID=11\tParentSkillLineID=0\n'
'smith\tID=164\tCategoryID=11\tParentSkillLineID=0\n')
source.write_text('CREATE TABLE `spell_template` (`entry` int, `effect1` int, `effectTriggerSpell1` int);\n'
'INSERT INTO `spell_template` VALUES\n(2275,36,2259),\n(2021,36,3100),\n(9001,36,2259);\n')
venues.write_text("INSERT INTO `trainer` VALUES (1001215,2,'Alchemy',0),(1001383,2,'Blacksmithing',0),"
"(1000999,0,'Class',0); "
'INSERT INTO `trainer_spell` VALUES (1000999,2259,10,0,0,0,0,0,1,0),'
'(1001215,2259,10,0,0,0,0,0,1,0),'
'(1001383,3100,500,164,50,0,0,0,10,0);\n')
rows = [(2275,36,2259,0,0), (2275,44,0,1,171), (2259,118,0,1,171), (9001,36,2259,0,0)]
journeyman = [(2021,36,3100,0,0), (2021,44,0,2,164), (3100,118,0,2,164)]
def write_effects(rows):
records = []
for spell, kind, taught, step, skill in rows:
records.append(json.dumps({'fields': {'DifficultyID': 0, 'SpellID': spell, 'Effect': kind,
'EffectTriggerSpell': taught, 'EffectMiscValue': [skill, 0],
'EffectBasePointsF': {'f32_bits': struct.unpack('<I', struct.pack('<f', step))[0]}}}))
effects.write_text('\n'.join(records) + '\n')
def generate():
return subprocess.run([sys.executable, generator, catalog, effects, abilities, output,
'--venue-catalog', venues, '--source-spells', source, '--native-skills', skills],
capture_output=True, text=True)
write_effects(rows + journeyman)
for statement in ('INSERT IGNORE', 'INSERT', 'REPLACE'):
sql = catalog.read_text()
catalog.write_text(sql.replace('INSERT IGNORE', statement))
generate().check_returncode()
assert [row.strip() for row in output.read_text().splitlines() if row.strip().startswith('{')] == [
'{2021,3100,164,2,0,376},', '{2275,2259,171,1,1,353},',
'{1001215,2275},', '{1001383,2021},']
catalog.write_text(sql)
for divergent in (rows[:2], rows[:2] + [(2259,118,0,1,164)], rows + [(2275,36,9999,0,0)]):
write_effects(divergent)
result = generate()
assert result.returncode and 'No verified 70124 trainer steps' in result.stderr
# A venue may expose the rank only when its learned spell has the right
# skill requirement and the Source teacher agrees with the native teacher.
write_effects(rows + journeyman)
venues.write_text(venues.read_text().replace('3100,500,164', '3100,500,171'))
generate().check_returncode()
assert '2021,3100' not in output.read_text() and '{1001383,2021}' not in output.read_text()
source.write_text(source.read_text().replace('(2275,36,2259)', '(2275,36,2331)'))
assert generate().returncode != 0