25 lines
1.2 KiB
Python
25 lines
1.2 KiB
Python
import json, sys, tempfile
|
|
from pathlib import Path
|
|
sys.path.insert(0, str(Path(__file__).resolve().parent.parent / 'ops'))
|
|
import editor_spawns as E
|
|
|
|
rows = [{'kind': 'npc', 'entry': 1423, 'map': 0, 'x': -9449.06, 'y': 64.83, 'z': 56.1234},
|
|
{'kind': 'go', 'entry': 32349, 'map': 0, 'x': -9460.5, 'y': 70.25, 'z': 56.5}]
|
|
with tempfile.TemporaryDirectory() as d:
|
|
p = Path(d) / 'list.json'; p.write_text(json.dumps(rows))
|
|
assert E.commands(E.load(p)) == ['.go xyz -9449.060 64.830 56.123 0', '.npc add 1423',
|
|
'.go xyz -9460.500 70.250 56.500 0', '.gobject add 32349']
|
|
for bad in ([{'kind': 'npc', 'entry': 1, 'map': 0, 'x': 1, 'y': 2}],
|
|
[{'kind': 'creature', 'entry': 1, 'map': 0, 'x': 1, 'y': 2, 'z': 3}],
|
|
[{'kind': 'go', 'entry': 0, 'map': 0, 'x': 1, 'y': 2, 'z': 3}], {}):
|
|
p.write_text(json.dumps(bad))
|
|
try:
|
|
E.load(p); raise AssertionError(f'accepted {bad}')
|
|
except ValueError:
|
|
pass
|
|
try:
|
|
E.main(['apply', str(p.with_name('x.json'))]); raise AssertionError('apply ran without list')
|
|
except (FileNotFoundError, SystemExit):
|
|
pass
|
|
print('OK')
|