fix(app): Recorder-Stop vor Ersatz + create_monitor in Tests mocken
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+12
-6
@@ -8,10 +8,11 @@ from whisper_local.__main__ import App
|
||||
|
||||
class TestApp:
|
||||
@patch("whisper_local.__main__.create_tray")
|
||||
@patch("whisper_local.__main__.create_monitor")
|
||||
@patch("whisper_local.__main__.Transcriber")
|
||||
@patch("whisper_local.__main__.create_listener")
|
||||
@patch("whisper_local.__main__.create_inserter")
|
||||
def test_app_init(self, mock_inserter_factory, mock_listener_factory, mock_transcriber_class, mock_tray_factory):
|
||||
def test_app_init(self, mock_inserter_factory, mock_listener_factory, mock_transcriber_class, mock_monitor_factory, mock_tray_factory):
|
||||
app = App()
|
||||
assert app.recorder is not None
|
||||
mock_transcriber_class.assert_called_once()
|
||||
@@ -19,10 +20,11 @@ class TestApp:
|
||||
mock_inserter_factory.assert_called_once()
|
||||
|
||||
@patch("whisper_local.__main__.create_tray")
|
||||
@patch("whisper_local.__main__.create_monitor")
|
||||
@patch("whisper_local.__main__.Transcriber")
|
||||
@patch("whisper_local.__main__.create_listener")
|
||||
@patch("whisper_local.__main__.create_inserter")
|
||||
def test_on_press_starts_recording(self, mock_inserter_factory, mock_listener_factory, mock_transcriber_class, mock_tray_factory):
|
||||
def test_on_press_starts_recording(self, mock_inserter_factory, mock_listener_factory, mock_transcriber_class, mock_monitor_factory, mock_tray_factory):
|
||||
app = App()
|
||||
app.recorder = MagicMock()
|
||||
|
||||
@@ -32,10 +34,11 @@ class TestApp:
|
||||
app.recorder.start.assert_called_once()
|
||||
|
||||
@patch("whisper_local.__main__.create_tray")
|
||||
@patch("whisper_local.__main__.create_monitor")
|
||||
@patch("whisper_local.__main__.Transcriber")
|
||||
@patch("whisper_local.__main__.create_listener")
|
||||
@patch("whisper_local.__main__.create_inserter")
|
||||
def test_on_release_stops_and_transcribes(self, mock_inserter_factory, mock_listener_factory, mock_transcriber_class, mock_tray_factory):
|
||||
def test_on_release_stops_and_transcribes(self, mock_inserter_factory, mock_listener_factory, mock_transcriber_class, mock_monitor_factory, mock_tray_factory):
|
||||
mock_transcriber = MagicMock()
|
||||
mock_transcriber.transcribe.return_value = "Hallo"
|
||||
mock_transcriber_class.return_value = mock_transcriber
|
||||
@@ -55,10 +58,11 @@ class TestApp:
|
||||
app.inserter.insert.assert_awaited_once_with("Hallo")
|
||||
|
||||
@patch("whisper_local.__main__.create_tray")
|
||||
@patch("whisper_local.__main__.create_monitor")
|
||||
@patch("whisper_local.__main__.Transcriber")
|
||||
@patch("whisper_local.__main__.create_listener")
|
||||
@patch("whisper_local.__main__.create_inserter")
|
||||
def test_on_release_no_audio_skips(self, mock_inserter_factory, mock_listener_factory, mock_transcriber_class, mock_tray_factory):
|
||||
def test_on_release_no_audio_skips(self, mock_inserter_factory, mock_listener_factory, mock_transcriber_class, mock_monitor_factory, mock_tray_factory):
|
||||
mock_transcriber = MagicMock()
|
||||
mock_transcriber_class.return_value = mock_transcriber
|
||||
|
||||
@@ -75,12 +79,13 @@ class TestApp:
|
||||
app.inserter.insert.assert_not_awaited()
|
||||
|
||||
@patch("whisper_local.__main__.create_tray")
|
||||
@patch("whisper_local.__main__.create_monitor")
|
||||
@patch("whisper_local.__main__.Transcriber")
|
||||
@patch("whisper_local.__main__.create_listener")
|
||||
@patch("whisper_local.__main__.create_inserter")
|
||||
def test_on_press_sets_recording_state(
|
||||
self, mock_inserter_factory, mock_listener_factory,
|
||||
mock_transcriber_class, mock_tray_factory
|
||||
mock_transcriber_class, mock_monitor_factory, mock_tray_factory
|
||||
):
|
||||
from whisper_local.tray import AppState
|
||||
mock_tray = MagicMock()
|
||||
@@ -95,12 +100,13 @@ class TestApp:
|
||||
mock_tray.set_state.assert_called_with(AppState.RECORDING)
|
||||
|
||||
@patch("whisper_local.__main__.create_tray")
|
||||
@patch("whisper_local.__main__.create_monitor")
|
||||
@patch("whisper_local.__main__.Transcriber")
|
||||
@patch("whisper_local.__main__.create_listener")
|
||||
@patch("whisper_local.__main__.create_inserter")
|
||||
def test_on_release_sets_waiting_state_after_transcription(
|
||||
self, mock_inserter_factory, mock_listener_factory,
|
||||
mock_transcriber_class, mock_tray_factory
|
||||
mock_transcriber_class, mock_monitor_factory, mock_tray_factory
|
||||
):
|
||||
from whisper_local.tray import AppState
|
||||
mock_tray = MagicMock()
|
||||
|
||||
@@ -103,6 +103,8 @@ class App:
|
||||
from whisper_local.tray._notification import notify
|
||||
device_name = self._config.microphone or "Mikrofon"
|
||||
logger.warning("Konfiguriertes Mikrofon '%s' nicht gefunden, nutze Standard", device_name)
|
||||
if self.recorder.is_recording:
|
||||
self.recorder.stop()
|
||||
self.recorder = Recorder(
|
||||
sample_rate=self._config.sample_rate,
|
||||
channels=self._config.channels,
|
||||
|
||||
Reference in New Issue
Block a user