Skip to content

Commit

Permalink
feat: update transcription tasks columns
Browse files Browse the repository at this point in the history
  • Loading branch information
chidiwilliams committed Dec 21, 2023
1 parent 730bade commit 7a2295e
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 23 deletions.
4 changes: 4 additions & 0 deletions buzz/settings/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -56,3 +57,6 @@ def begin_group(self, group: Key):

def end_group(self):
self.settings.endGroup()

def sync(self):
self.settings.sync()
37 changes: 22 additions & 15 deletions tests/widgets/main_window_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
)

Expand All @@ -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)
Expand All @@ -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()
Expand Down Expand Up @@ -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):
Expand All @@ -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()
44 changes: 36 additions & 8 deletions tests/widgets/transcription_tasks_table_widget_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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

0 comments on commit 7a2295e

Please sign in to comment.