diff options
Diffstat (limited to 'tests/test_service.py')
| -rw-r--r-- | tests/test_service.py | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/tests/test_service.py b/tests/test_service.py new file mode 100644 index 0000000..2bda2ab --- /dev/null +++ b/tests/test_service.py @@ -0,0 +1,60 @@ +from pathlib import Path + +from mic_clipper.service import install, render_unit, uninstall + + +def test_rendered_service_waits_for_audio_services_and_restarts_only_on_failure(): + unit = render_unit(Path("/runtime/python"), Path("/project")) + + assert "After=pipewire.service wireplumber.service pipewire-pulse.service" in unit + assert "Restart=on-failure" in unit + assert "RestartMaxDelaySec=60s" in unit + assert "ExecStart=/runtime/python -m mic_clipper run" in unit + assert "UMask=0077" in unit + + +def test_install_and_uninstall_only_manage_the_tool_unit(tmp_path): + unit_path = tmp_path / "systemd" / "mic-clipper.service" + clips = tmp_path / "Mic Clips" / "2026-09-29" / "keep.opus" + clips.parent.mkdir(parents=True) + clips.write_bytes(b"recording") + commands: list[list[str]] = [] + + install( + unit_path=unit_path, + python=Path("/runtime/python"), + project_root=Path("/project"), + run_command=commands.append, + ) + install( + unit_path=unit_path, + python=Path("/runtime/python"), + project_root=Path("/project"), + run_command=commands.append, + ) + uninstall(unit_path=unit_path, run_command=commands.append) + + assert not unit_path.exists() + assert clips.read_bytes() == b"recording" + assert commands == [ + ["systemctl", "--user", "daemon-reload"], + ["systemctl", "--user", "enable", "--now", "mic-clipper.service"], + ["systemctl", "--user", "daemon-reload"], + ["systemctl", "--user", "enable", "--now", "mic-clipper.service"], + ["systemctl", "--user", "disable", "--now", "mic-clipper.service"], + ["systemctl", "--user", "daemon-reload"], + ] + + +def test_dry_run_does_not_write_a_unit(tmp_path): + unit_path = tmp_path / "mic-clipper.service" + + commands = install( + unit_path=unit_path, + python=Path("/runtime/python"), + project_root=Path("/project"), + dry_run=True, + ) + + assert not unit_path.exists() + assert commands[-1] == ["systemctl", "--user", "enable", "--now", "mic-clipper.service"] |
