Files

65 lines
3.0 KiB
Python

"""Run an extracted parent or composed creator through its real choice and Finish callbacks."""
import argparse
import subprocess
from pathlib import Path
import sys
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
from character_creation import NativeCreate
from source_appearance_groups import profile
HERE = Path(__file__).resolve().parent
def function_body(text, name):
start = text.index('function CharacterCreateMixin:' + name + '(')
return text[start:text.index('\nend\n', start) + 5]
def check(asset):
text = asset.read_text()
prefix = text[:text.index('-- Native create result codes')]
# The retained overlay helper returns immediately for normal Undead.
start = text.index('local GW_SOURCE_HIGH_ELF_NO_OVERLAY')
overlay = text[start:text.index('function CharacterCreateMixin:', start)]
methods = '\n'.join(function_body(text, name) for name in ('UpdateCharCustomizationFrame', 'SetCustomizationChoice'))
template = (HERE/'check.lua').read_text()
harness = template.replace('-- ORIGINAL_CREATOR', '\n'.join([prefix, overlay, methods]))
schema, _ = profile()
def click(race, sex, option, choice, mode='new'):
run = subprocess.run(['lua5.1', '-', str(race), str(sex), str(option), str(choice), mode],
input=harness, text=True, capture_output=True, check=True)
if mode == 'stale':
assert run.stdout.strip() == 'stale preview held'
return {}
rows = [tuple(map(int, line.split())) for line in run.stdout.splitlines()]
if any(preview != finish for _, preview, finish in rows):
raise AssertionError('Preview and Finish differ')
return {opt: finish for opt, _, finish in rows}
cases = [(1,67,1042,5),(1,559,6276,2),(1,535,6305,2),
(1,67,1038,1),(0,62,977,10),(0,563,6288,2),(0,62,978,11)]
for sex, option, choice, source in cases:
selected = click(5, sex, option, choice)
request = NativeCreate('Fixture', '', 5, 5, sex, tuple(selected.items()), None, False, False, False, 0, -1, 0, 0)
try:
actual = schema.resolve(request, new_character=True)
except ValueError as error:
raise AssertionError(f'Invalid preview for click {option}={choice}: {selected}') from error
if actual != (0,0,0,0,source) or selected[option] != choice:
raise AssertionError(f'{option}={choice}: wanted feature {source}, got {actual} with {selected}')
print(f'sex={sex} click={option}:{choice} original={source}')
# The same choice activity in another race or service must use its existing behavior.
for race, mode in [(1,'new'), (5,'service')]:
other = click(race, 1, 67, 1042, mode)
assert (other[67], other[535], other[559]) == (1042,5337,6275)
click(5, 1, 67, 1042, 'stale')
print('Seven round trips, two scope controls and one stale-preview check passed.')
if __name__ == '__main__':
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('asset', type=Path)
check(parser.parse_args().asset)