Files
cthulhu/tests/test_speech_monitor_callbacks.py

54 lines
1.3 KiB
Python

"""Regression tests for speech monitor callback registration."""
from __future__ import annotations
import pytest
from cthulhu import speech
@pytest.mark.unit
def test_set_monitor_callbacks_accepts_snake_case_keywords() -> None:
captured: list[str] = []
speech.set_monitor_callbacks(
write_text=captured.append,
write_key=lambda _key: None,
begin_group=lambda: None,
end_group=lambda: None,
)
try:
speech._write_to_monitor("hello")
finally:
speech.set_monitor_callbacks()
assert captured == ["hello"]
@pytest.mark.unit
def test_set_monitor_callbacks_preserves_legacy_write_text_argument() -> None:
captured: list[str] = []
speech.set_monitor_callbacks(writeText=captured.append)
try:
speech._write_to_monitor("legacy")
finally:
speech.set_monitor_callbacks()
assert captured == ["legacy"]
@pytest.mark.unit
def test_speech_server_snake_case_accessors_delegate_to_legacy_api(monkeypatch) -> None:
monkeypatch.setattr(speech, "_refreshEchoSpeechServer", lambda: None)
original_server = speech.getSpeechServer()
server = object()
try:
speech.set_server(server)
assert speech.get_speech_server() is server
assert speech.getSpeechServer() is server
finally:
speech.setSpeechServer(original_server)