feat: add stop() method to HotkeyListener protocol and PynputHotkeyListener

This commit is contained in:
2026-04-10 21:05:20 +02:00
parent 1d19a197c7
commit 8b64d66326
4 changed files with 28 additions and 2 deletions
+15
View File
@@ -112,3 +112,18 @@ class TestPynputHotkeyListener:
# Erneutes Release ohne Press — wird ignoriert
listener._on_release(Key.f12)
assert listener._loop.call_soon_threadsafe.call_count == 2
class TestPynputHotkeyListenerStop:
@pytest.mark.asyncio
async def test_stop_ends_listen(self):
from whisper_local.hotkey._pynput import PynputHotkeyListener
from unittest.mock import patch, MagicMock
listener = PynputHotkeyListener("KEY_F12")
with patch("whisper_local.hotkey._pynput.Listener") as mock_listener_cls:
mock_listener_cls.return_value = MagicMock()
listen_task = asyncio.create_task(listener.listen())
await asyncio.sleep(0) # Loop einen Schritt weiter
listener.stop()
await asyncio.wait_for(listen_task, timeout=1.0)