1
1
import logging
2
2
import os .path
3
3
import pathlib
4
- import platform
5
4
from unittest .mock import Mock , patch
6
5
7
6
import pytest
12
11
from pytestqt .qtbot import QtBot
13
12
14
13
from buzz .cache import TasksCache
15
- from buzz .gui import (AboutDialog , AdvancedSettingsDialog , Application ,
16
- AudioDevicesComboBox , DownloadModelProgressDialog ,
14
+ from buzz .gui import (AboutDialog , AdvancedSettingsDialog , AudioDevicesComboBox , DownloadModelProgressDialog ,
17
15
FileTranscriberWidget , LanguagesComboBox , MainWindow ,
18
16
RecordingTranscriberWidget ,
19
17
TemperatureValidator , TextDisplayBox ,
25
23
from tests .mock_sounddevice import MockInputStream
26
24
27
25
28
- class TestApplication :
29
- # FIXME: this seems to break the tests if not run??
30
- app = Application ()
31
-
32
- def test_should_open_application (self ):
33
- assert self .app is not None
34
-
35
-
36
26
class TestLanguagesComboBox :
37
- languagesComboxBox = LanguagesComboBox ('en' )
38
-
39
- def test_should_show_sorted_whisper_languages (self ):
40
- assert self .languagesComboxBox .itemText (0 ) == 'Detect Language'
41
- assert self .languagesComboxBox .itemText (10 ) == 'Belarusian'
42
- assert self .languagesComboxBox .itemText (20 ) == 'Dutch'
43
- assert self .languagesComboxBox .itemText (30 ) == 'Gujarati'
44
- assert self .languagesComboxBox .itemText (40 ) == 'Japanese'
45
- assert self .languagesComboxBox .itemText (50 ) == 'Lithuanian'
46
27
47
- def test_should_select_en_as_default_language (self ):
48
- assert self .languagesComboxBox .currentText () == 'English'
49
-
50
- def test_should_select_detect_language_as_default (self ):
28
+ def test_should_show_sorted_whisper_languages (self , qtbot ):
29
+ languages_combox_box = LanguagesComboBox ('en' )
30
+ qtbot .add_widget (languages_combox_box )
31
+ assert languages_combox_box .itemText (0 ) == 'Detect Language'
32
+ assert languages_combox_box .itemText (10 ) == 'Belarusian'
33
+ assert languages_combox_box .itemText (20 ) == 'Dutch'
34
+ assert languages_combox_box .itemText (30 ) == 'Gujarati'
35
+ assert languages_combox_box .itemText (40 ) == 'Japanese'
36
+ assert languages_combox_box .itemText (50 ) == 'Lithuanian'
37
+
38
+ def test_should_select_en_as_default_language (self , qtbot ):
39
+ languages_combox_box = LanguagesComboBox ('en' )
40
+ qtbot .add_widget (languages_combox_box )
41
+ assert languages_combox_box .currentText () == 'English'
42
+
43
+ def test_should_select_detect_language_as_default (self , qtbot ):
51
44
languages_combo_box = LanguagesComboBox (None )
45
+ qtbot .add_widget (languages_combo_box )
52
46
assert languages_combo_box .currentText () == 'Detect Language'
53
47
54
48
@@ -185,17 +179,16 @@ def check_task_completed():
185
179
186
180
187
181
class TestFileTranscriberWidget :
188
- widget = FileTranscriberWidget (
189
- file_paths = ['testdata/whisper-french.mp3' ], parent = None )
190
-
191
182
def test_should_set_window_title (self , qtbot : QtBot ):
192
- qtbot .addWidget (self .widget )
193
- assert self .widget .windowTitle () == 'whisper-french.mp3'
183
+ widget = FileTranscriberWidget (
184
+ file_paths = ['testdata/whisper-french.mp3' ], parent = None )
185
+ qtbot .add_widget (widget )
186
+ assert widget .windowTitle () == 'whisper-french.mp3'
194
187
195
188
def test_should_emit_triggered_event (self , qtbot : QtBot ):
196
189
widget = FileTranscriberWidget (
197
190
file_paths = ['testdata/whisper-french.mp3' ], parent = None )
198
- qtbot .addWidget (widget )
191
+ qtbot .add_widget (widget )
199
192
200
193
mock_triggered = Mock ()
201
194
widget .triggered .connect (mock_triggered )
@@ -254,31 +247,41 @@ def test_should_validate_temperature(self, text: str, state: QValidator.State):
254
247
255
248
256
249
class TestTranscriptionViewerWidget :
257
- widget = TranscriptionViewerWidget (
258
- transcription_task = FileTranscriptionTask (
259
- id = 0 ,
260
- file_path = 'testdata/whisper-french.mp3' ,
261
- file_transcription_options = FileTranscriptionOptions (
262
- file_paths = ['testdata/whisper-french.mp3' ]),
263
- transcription_options = TranscriptionOptions (),
264
- segments = [Segment (40 , 299 , 'Bien' ),
265
- Segment (299 , 329 , 'venue dans' )],
266
- model_path = '' ))
267
250
268
251
def test_should_display_segments (self , qtbot : QtBot ):
269
- qtbot .add_widget (self .widget )
252
+ widget = TranscriptionViewerWidget (
253
+ transcription_task = FileTranscriptionTask (
254
+ id = 0 ,
255
+ file_path = 'testdata/whisper-french.mp3' ,
256
+ file_transcription_options = FileTranscriptionOptions (
257
+ file_paths = ['testdata/whisper-french.mp3' ]),
258
+ transcription_options = TranscriptionOptions (),
259
+ segments = [Segment (40 , 299 , 'Bien' ),
260
+ Segment (299 , 329 , 'venue dans' )],
261
+ model_path = '' ))
262
+ qtbot .add_widget (widget )
270
263
271
- assert self . widget .windowTitle () == 'whisper-french.mp3'
264
+ assert widget .windowTitle () == 'whisper-french.mp3'
272
265
273
- text_display_box = self . widget .findChild (TextDisplayBox )
266
+ text_display_box = widget .findChild (TextDisplayBox )
274
267
assert isinstance (text_display_box , TextDisplayBox )
275
268
assert text_display_box .toPlainText (
276
269
) == '00:00:00.040 --> 00:00:00.299\n Bien\n \n 00:00:00.299 --> 00:00:00.329\n venue dans'
277
270
278
271
def test_should_export_segments (self , tmp_path : pathlib .Path , qtbot : QtBot ):
279
- qtbot .add_widget (self .widget )
272
+ widget = TranscriptionViewerWidget (
273
+ transcription_task = FileTranscriptionTask (
274
+ id = 0 ,
275
+ file_path = 'testdata/whisper-french.mp3' ,
276
+ file_transcription_options = FileTranscriptionOptions (
277
+ file_paths = ['testdata/whisper-french.mp3' ]),
278
+ transcription_options = TranscriptionOptions (),
279
+ segments = [Segment (40 , 299 , 'Bien' ),
280
+ Segment (299 , 329 , 'venue dans' )],
281
+ model_path = '' ))
282
+ qtbot .add_widget (widget )
280
283
281
- export_button = self . widget .findChild (QPushButton )
284
+ export_button = widget .findChild (QPushButton )
282
285
assert isinstance (export_button , QPushButton )
283
286
284
287
output_file_path = tmp_path / 'whisper.txt'
@@ -291,39 +294,39 @@ def test_should_export_segments(self, tmp_path: pathlib.Path, qtbot: QtBot):
291
294
292
295
293
296
class TestTranscriptionTasksTableWidget :
294
- widget = TranscriptionTasksTableWidget ()
295
297
296
298
def test_upsert_task (self , qtbot : QtBot ):
297
- qtbot .add_widget (self .widget )
299
+ widget = TranscriptionTasksTableWidget ()
300
+ qtbot .add_widget (widget )
298
301
299
302
task = FileTranscriptionTask (id = 0 , file_path = 'testdata/whisper-french.mp3' ,
300
303
transcription_options = TranscriptionOptions (),
301
304
file_transcription_options = FileTranscriptionOptions (
302
305
file_paths = ['testdata/whisper-french.mp3' ]), model_path = '' ,
303
306
status = FileTranscriptionTask .Status .QUEUED )
304
307
305
- self . widget .upsert_task (task )
308
+ widget .upsert_task (task )
306
309
307
- assert self . widget .rowCount () == 1
308
- assert self . widget .item (0 , 1 ).text () == 'whisper-french.mp3'
309
- assert self . widget .item (0 , 2 ).text () == 'Queued'
310
+ assert widget .rowCount () == 1
311
+ assert widget .item (0 , 1 ).text () == 'whisper-french.mp3'
312
+ assert widget .item (0 , 2 ).text () == 'Queued'
310
313
311
314
task .status = FileTranscriptionTask .Status .IN_PROGRESS
312
315
task .fraction_completed = 0.3524
313
- self . widget .upsert_task (task )
316
+ widget .upsert_task (task )
314
317
315
- assert self . widget .rowCount () == 1
316
- assert self . widget .item (0 , 1 ).text () == 'whisper-french.mp3'
317
- assert self . widget .item (0 , 2 ).text () == 'In Progress (35%)'
318
+ assert widget .rowCount () == 1
319
+ assert widget .item (0 , 1 ).text () == 'whisper-french.mp3'
320
+ assert widget .item (0 , 2 ).text () == 'In Progress (35%)'
318
321
319
322
320
- @pytest .mark .skip ()
321
323
class TestRecordingTranscriberWidget :
322
324
def test_should_set_window_title (self , qtbot : QtBot ):
323
325
widget = RecordingTranscriberWidget ()
324
326
qtbot .add_widget (widget )
325
327
assert widget .windowTitle () == 'Live Recording'
326
328
329
+ @pytest .mark .skip ()
327
330
def test_should_transcribe (self , qtbot ):
328
331
widget = RecordingTranscriberWidget ()
329
332
qtbot .add_widget (widget )
0 commit comments