"""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", "radioscanner", *g) assert "CHR_RadioScanner_2" 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", "CHR_RadioScanner_2", wav, *g) assert "replaced CHR_RadioScanner_2" in out assert "CHR_RadioScanner_2" in run(capsys, "status", *g) assert "modified" in run(capsys, "info", "CHR_RadioScanner_2", *g) orig = str(tmp_path / "orig.wem") run(capsys, "extract", "CHR_RadioScanner_2", 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", "CHR_RadioScanner_2", *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)