feat: add stop() method to HotkeyListener protocol and PynputHotkeyListener
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user