feat: add hotkey module with evdev push-to-talk listener

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-06 20:23:48 +02:00
parent 8224fdcc3f
commit ef6ff5b35b
2 changed files with 95 additions and 0 deletions
+38
View File
@@ -0,0 +1,38 @@
import asyncio
from unittest.mock import AsyncMock, MagicMock, patch
import pytest
from whisper_local.hotkey import HotkeyListener
@pytest.fixture
def listener():
return HotkeyListener(key_name="KEY_F12")
class TestHotkeyListener:
def test_init_stores_key_name(self, listener):
assert listener.key_name == "KEY_F12"
@pytest.mark.asyncio
async def test_key_down_calls_callback(self, listener):
on_press = AsyncMock()
listener.on_press = on_press
await listener._handle_key_event(key_down=True)
on_press.assert_awaited_once()
@pytest.mark.asyncio
async def test_key_up_calls_callback(self, listener):
on_release = AsyncMock()
listener.on_release = on_release
await listener._handle_key_event(key_down=False)
on_release.assert_awaited_once()
@pytest.mark.asyncio
async def test_no_callback_no_error(self, listener):
# Kein Callback gesetzt — soll nicht crashen
await listener._handle_key_event(key_down=True)
await listener._handle_key_event(key_down=False)