Files
UnheardCity/tests/test_cli.py

82 lines
3.3 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_replace_with_voice_effects(synth_game, tmp_path, capsys):
import json
root, _ = synth_game
g = ["--game", root, "--lang", "INT", "--store", str(tmp_path / "store")]
tpl = str(tmp_path / "fx.json")
assert "wrote" in run(capsys, "fx-template", tpl)
s = json.load(open(tpl))
s["eq"]["on"] = True
json.dump(s, open(tpl, "w"))
wav = str(tmp_path / "line.wav")
audio.save_wav(wav, *synth.tone(1.0, 44100, 660))
assert "replaced Speech_Synth_Radio_02" in run(capsys, "replace", "Speech_Synth_Radio_02", wav, "--fx", tpl, *g)
run(capsys, "revert", "--all", *g)
assert "game files are original" in run(capsys, "status", *g)
def test_cli_text_language_without_voices(synth_game, capsys):
"""--lang works for the languages that have only texts (INT voices are loaded for them, like the editor)."""
root, _ = synth_game
out = run(capsys, "text", "find", "--kind", "subs", "--game", root, "--lang", "RUS", "Строка")
assert "SUB:RUS:%s:0" % synth.SPEECH_EVENT in out and "1 match" in out
def test_cli_restore_backup(synth_game, tmp_path, capsys):
root, _ = synth_game
g = ["--game", root, "--lang", "INT", "--store", str(tmp_path / "store")]
wav = str(tmp_path / "line.wav")
audio.save_wav(wav, *synth.tone(1.0, 44100, 660))
run(capsys, "replace", "Speech_Synth_Radio_02", wav, *g)
out = run(capsys, "restore-backup", *g)
assert "would copy back" in out and "--yes" in out # lists only
assert "Speech_Synth_Radio_02" in run(capsys, "status", *g)
assert "restored" in run(capsys, "restore-backup", "--yes", *g)
assert "game files are original" in run(capsys, "status", *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)