diff --git a/buzz/settings/settings.py b/buzz/settings/settings.py index 90fc83b16..f5e74a620 100644 --- a/buzz/settings/settings.py +++ b/buzz/settings/settings.py @@ -9,6 +9,7 @@ class Settings: def __init__(self): self.settings = QSettings(APP_NAME) + self.settings.sync() class Key(enum.Enum): RECORDING_TRANSCRIBER_TASK = "recording-transcriber/task" @@ -56,3 +57,6 @@ def begin_group(self, group: Key): def end_group(self): self.settings.endGroup() + + def sync(self): + self.settings.sync() diff --git a/tests/widgets/main_window_test.py b/tests/widgets/main_window_test.py index 6a3fa9666..f9caf117b 100644 --- a/tests/widgets/main_window_test.py +++ b/tests/widgets/main_window_test.py @@ -10,6 +10,7 @@ from pytestqt.qtbot import QtBot from buzz.cache import TasksCache +from buzz.settings.settings import Settings from buzz.transcriber import ( FileTranscriptionTask, TranscriptionOptions, @@ -69,7 +70,7 @@ def test_should_run_transcription_task(self, qtbot: QtBot, tasks_cache): table_widget: QTableWidget = window.findChild(QTableWidget) qtbot.wait_until( - self._assert_task_status(table_widget, 0, "Completed"), + self.get_assert_task_status_callback(table_widget, 0, "Completed"), timeout=2 * 60 * 1000, ) @@ -88,19 +89,18 @@ def test_should_run_and_cancel_transcription_task(self, qtbot, tasks_cache): table_widget: QTableWidget = window.findChild(QTableWidget) - def assert_task_in_progress(): - assert table_widget.rowCount() > 0 - assert table_widget.item(0, 1).text() == "whisper-french.mp3" - assert "In Progress" in table_widget.item(0, 2).text() - - qtbot.wait_until(assert_task_in_progress, timeout=2 * 60 * 1000) + qtbot.wait_until( + self.get_assert_task_status_callback(table_widget, 0, "In Progress"), + timeout=2 * 60 * 1000, + ) # Stop task in progress table_widget.selectRow(0) window.toolbar.stop_transcription_action.trigger() qtbot.wait_until( - self._assert_task_status(table_widget, 0, "Canceled"), timeout=60 * 1000 + self.get_assert_task_status_callback(table_widget, 0, "Canceled"), + timeout=60 * 1000, ) table_widget.selectRow(0) @@ -117,15 +117,15 @@ def test_should_load_tasks_from_cache(self, qtbot, tasks_cache): table_widget: QTableWidget = window.findChild(QTableWidget) assert table_widget.rowCount() == 3 - assert table_widget.item(0, 2).text() == "Completed" + assert table_widget.item(0, 4).text() == "Completed" table_widget.selectRow(0) assert window.toolbar.open_transcript_action.isEnabled() - assert table_widget.item(1, 2).text() == "Canceled" + assert table_widget.item(1, 4).text() == "Canceled" table_widget.selectRow(1) assert window.toolbar.open_transcript_action.isEnabled() is False - assert table_widget.item(2, 2).text() == "Failed (Error)" + assert table_widget.item(2, 4).text() == "Failed (Error)" table_widget.selectRow(2) assert window.toolbar.open_transcript_action.isEnabled() is False window.close() @@ -226,15 +226,15 @@ def _start_new_transcription(window: MainWindow): run_button.click() @staticmethod - def _assert_task_status( + def get_assert_task_status_callback( table_widget: QTableWidget, row_index: int, expected_status: str ): - def assert_task_canceled(): + def assert_task_status(): assert table_widget.rowCount() > 0 assert table_widget.item(row_index, 1).text() == "whisper-french.mp3" - assert expected_status in table_widget.item(row_index, 2).text() + assert expected_status in table_widget.item(row_index, 4).text() - return assert_task_canceled + return assert_task_status @staticmethod def _get_toolbar_action(window: MainWindow, text: str): @@ -250,3 +250,10 @@ def tasks_cache(tmp_path, request: SubRequest): cache.save(tasks) yield cache cache.clear() + + +@pytest.fixture(autouse=True) +def reset_settings(): + settings = Settings() + settings.clear() + settings.sync() diff --git a/tests/widgets/transcription_tasks_table_widget_test.py b/tests/widgets/transcription_tasks_table_widget_test.py index abc449c13..865d02ec7 100644 --- a/tests/widgets/transcription_tasks_table_widget_test.py +++ b/tests/widgets/transcription_tasks_table_widget_test.py @@ -31,24 +31,37 @@ def test_upsert_task(self, qtbot: QtBot): widget.upsert_task(task) assert widget.rowCount() == 1 - assert widget.item(0, 1).text() == "whisper-french.mp3" - assert widget.item(0, 2).text() == "Queued" + self.assert_row_text( + widget, 0, "whisper-french.mp3", "Whisper (Tiny)", "Transcribe", "Queued" + ) task.status = FileTranscriptionTask.Status.IN_PROGRESS task.fraction_completed = 0.3524 widget.upsert_task(task) assert widget.rowCount() == 1 - assert widget.item(0, 1).text() == "whisper-french.mp3" - assert widget.item(0, 2).text() == "In Progress (35%)" + self.assert_row_text( + widget, + 0, + "whisper-french.mp3", + "Whisper (Tiny)", + "Transcribe", + "In Progress (35%)", + ) task.status = FileTranscriptionTask.Status.COMPLETED task.completed_at = datetime.datetime(2023, 4, 12, 0, 0, 10) widget.upsert_task(task) assert widget.rowCount() == 1 - assert widget.item(0, 1).text() == "whisper-french.mp3" - assert widget.item(0, 2).text() == "Completed (5s)" + self.assert_row_text( + widget, + 0, + "whisper-french.mp3", + "Whisper (Tiny)", + "Transcribe", + "Completed (5s)", + ) def test_upsert_task_no_timings(self, qtbot: QtBot): widget = TranscriptionTasksTableWidget() @@ -67,5 +80,20 @@ def test_upsert_task_no_timings(self, qtbot: QtBot): widget.upsert_task(task) assert widget.rowCount() == 1 - assert widget.item(0, 1).text() == "whisper-french.mp3" - assert widget.item(0, 2).text() == "Completed" + self.assert_row_text( + widget, 0, "whisper-french.mp3", "Whisper (Tiny)", "Transcribe", "Completed" + ) + + def assert_row_text( + self, + widget: TranscriptionTasksTableWidget, + row: int, + filename: str, + model: str, + task: str, + status: str, + ): + assert widget.item(row, 1).text() == filename + assert widget.item(row, 2).text() == model + assert widget.item(row, 3).text() == task + assert widget.item(row, 4).text() == status