fix: EvdevHotkeyListener.stop() cancelt Tasks und schließt Devices

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-11 21:21:57 +02:00
parent 107508eeb9
commit d780960381
2 changed files with 49 additions and 6 deletions
+33
View File
@@ -127,3 +127,36 @@ class TestPynputHotkeyListenerStop:
await asyncio.sleep(0) # Loop einen Schritt weiter
listener.stop()
await asyncio.wait_for(listen_task, timeout=1.0)
@pytest.mark.skipif(sys.platform != "linux", reason="evdev nur auf Linux")
class TestEvdevListenerStop:
@pytest.mark.asyncio
async def test_stop_cancels_tasks_and_closes_devices(self):
from whisper_local.hotkey._evdev import EvdevHotkeyListener
listener = EvdevHotkeyListener("KEY_F12")
async def never_ending(device):
while True:
await asyncio.sleep(1)
fake_device = MagicMock()
fake_device.close = MagicMock()
with patch(
"whisper_local.hotkey._evdev.find_keyboard_devices",
return_value=[fake_device],
):
listener._read_device = never_ending
listen_task = asyncio.create_task(listener.listen())
await asyncio.sleep(0.05) # Loop-Schritt, damit listen() startet
assert len(listener._tasks) == 1
listener.stop()
await asyncio.sleep(0.05)
assert listener._tasks == []
fake_device.close.assert_called_once()
await asyncio.wait_for(listen_task, timeout=1.0)