Files
UnheardCity/tests/test_cli.py

46 lines
1.6 KiB
Python

"""The `ackit` command line on a synthetic game."""
import os
import pytest
from ackit import audio, cli
import synth
def run(capsys, *args):
cli.main(list(args))
return capsys.readouterr().out
def test_cli_workflow(synth_game, tmp_path, capsys):
root, originals = synth_game
g = ["--game", root, "--lang", "INT"]
out = run(capsys, "find", "synth radio", *g)
assert "Speech_Synth_Radio_02" in out
wav = str(tmp_path / "line.wav")
x, sr = synth.tone(1.0, 44100, 660)
audio.save_wav(wav, x, sr)
out = run(capsys, "replace", "Speech_Synth_Radio_02", wav, *g)
assert "replaced Speech_Synth_Radio_02" in out
assert "Speech_Synth_Radio_02" in run(capsys, "status", *g)
assert "modified" in run(capsys, "info", "Speech_Synth_Radio_02", *g)
orig = str(tmp_path / "orig.wem")
run(capsys, "extract", "Speech_Synth_Radio_02", orig, *g)
assert open(orig, "rb").read() == originals["%08X:1" % synth.SPEECH_ENTRY]
mod = str(tmp_path / "m.acmod")
assert "1 sounds" in run(capsys, "export-mod", mod, *g)
assert "reverted 1" in run(capsys, "revert", "--all", *g)
assert "original" in run(capsys, "status", *g)
assert "exact" in run(capsys, "import-mod", mod, *g)
run(capsys, "revert", "Speech_Synth_Radio_02", *g)
def test_cli_errors_are_friendly(synth_game, capsys):
root, _ = synth_game
with pytest.raises(SystemExit) as e:
cli.main(["info", "Nope_Nothing", "--game", root, "--lang", "INT"])
assert "no sound named" in str(e.value)
with pytest.raises(SystemExit) as e:
cli.main(["info", "x", "--game", os.path.dirname(root)])
assert "not a Batman" in str(e.value)