GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 262694...f858ef )
by Mandeep
01:05
created

test_playback_previous()   A

Complexity

Conditions 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 1
1
import os
2
3
from PyQt5.QtCore import Qt
4
from PyQt5.QtWidgets import QApplication, QDialog, QFileDialog
5
import pytest
6
7
from mosaic import configuration, information, player
8
9
10
@pytest.fixture
11
def window(qtbot):
12
    """Initializes the music player window for each test.
13
14
    Showing the window has the indirect effect of testing items assigned
15
    to the main window such as the menu bar and the toolbar. Because the window
16
    would crash if these items did not exist or did not show, they are covered
17
    by this setup method."""
18
    music_player = player.MusicPlayer()
19
    qtbot.add_widget(music_player)
20
    music_player.show()
21
    yield music_player
22
    music_player.player.stop()
23
24
25
@pytest.fixture
26
def config(qtbot):
27
    """Provide the preferences dialog as a fixture to the tests."""
28
    preferences = configuration.PreferencesDialog()
29
    qtbot.add_widget(preferences)
30
    return preferences
31
32
33
@pytest.fixture
34
def flac_file():
35
    """Pass a FLAC file resource as an argument to the unit tests."""
36
    file = os.path.join(os.path.dirname(__file__), '02_Ghosts_I.flac')
37
    return file
38
39
40
@pytest.fixture
41
def mp3_file():
42
    """Pass an MP3 file resource as an argument to the unit tests."""
43
    file = os.path.join(os.path.dirname(__file__), '01_Ghosts_I_320kb.mp3')
44
    return file
45
46
47
@pytest.fixture
48
def blank_flac_file():
49
    """Pass a blank FLAC file resource as an argument to the unit tests.
50
51
    The metadata from this file has been removed to test cases where a file
52
    has no metadata."""
53
    file = os.path.join(os.path.dirname(__file__), '03_Ghosts_I.flac')
54
    return file
55
56
57
@pytest.fixture
58
def blank_mp3_file():
59
    """Pass an MP3 file resource as an argument to the unit tests.
60
61
    The metadata from this file has been removed to test cases where a file
62
    has no metadata."""
63
    file = os.path.join(os.path.dirname(__file__), '04_Ghosts_I_320kb.mp3')
64
    return file
65
66
67
def test_window(window):
68
    """Test the window title and window icon."""
69
    assert window.windowTitle() == 'Mosaic'
70
    assert window.windowIcon().isNull() is False
71
72
73
def test_open_flac_file(qtbot, mock, window, flac_file):
74
    """Test the opening of a FLAC media file.
75
76
    Qtbot clicks on the file menu then Qt.Key_Down highlights
77
    the open file item. The mock plugin creates a mock of the
78
    QFileDialog window while Key_Enter executes it."""
79
    qtbot.mouseClick(window.file, Qt.LeftButton)
80
    qtbot.keyClick(window.file, Qt.Key_Down)
81
    mock.patch.object(QFileDialog, 'getOpenFileName', return_value=(flac_file, '*.flac'))
82
    qtbot.keyClick(window.file, Qt.Key_Enter)
83
    qtbot.mouseClick(window.art, Qt.LeftButton)
84
    window.player.play()
85
    qtbot.mouseClick(window.art, Qt.LeftButton)
86
87
88
def test_open_blank_flac_file(qtbot, mock, window, blank_flac_file):
89
    """Test the opening of a blank FLAC media file.
90
91
    Qtbot clicks on the file menu then Qt.Key_Down highlights the open file item.
92
    The mock plugin creates a mock of the QFileDialog window while Qt.Key_Enter executes it.
93
    This test opens a blank flac file to test cases where metadata is not embedded in the file."""
94
    qtbot.mouseClick(window.file, Qt.LeftButton)
95
    qtbot.keyClick(window.file, Qt.Key_Down)
96
    mock.patch.object(QFileDialog, 'getOpenFileName', return_value=(blank_flac_file, '*.flac'))
97
    qtbot.keyClick(window.file, Qt.Key_Enter)
98
99
100
def test_open_blank_mp3_file(qtbot, mock, window, blank_mp3_file):
101
    """Test the opening of a blank MP3 file.
102
103
    Qtbot clicks on the file menu then Qt.Key_Down highlights the open file item.
104
    The mock plugin creates a mock of the QFileDialog window while Qt.Key_Enter executes it.
105
    This test opens a blank flac file to test cases where metadata is not embedded in the file."""
106
    qtbot.mouseClick(window.file, Qt.LeftButton)
107
    qtbot.keyClick(window.file, Qt.Key_Down)
108
    mock.patch.object(QFileDialog, 'getOpenFileName', return_value=(blank_mp3_file, '*.mp3'))
109
    qtbot.keyClick(window.file, Qt.Key_Enter)
110
111
112
def test_open_mp3_file(qtbot, mock, window, mp3_file):
113
    """Test the opening of an MP3 file.
114
115
    Qtbot clicks on the file menu then Qt.Key_Down highlights
116
    the open file item. The mock plugin creates a mock of the
117
    QFileDialog window while Key_Enter executes it."""
118
    qtbot.mouseClick(window.file, Qt.LeftButton)
119
    qtbot.keyClick(window.file, Qt.Key_Down)
120
    mock.patch.object(QFileDialog, 'getOpenFileName', return_value=(mp3_file, '*.mp3'))
121
    qtbot.keyClick(window.file, Qt.Key_Enter)
122
123
124
def test_open_files(qtbot, mock, window, flac_file, mp3_file):
125
    """Test the opening of multiple media files.
126
127
    Qtbot clicks on the file menu then Qt.Key_Down highlights
128
    the open files item. The mock plugin creates a mock of the
129
    QFileDialog window while Key_Enter executes it."""
130
    qtbot.mouseClick(window.file, Qt.LeftButton)
131
    qtbot.keyClick(window.file, Qt.Key_Down)
132
    qtbot.keyClick(window.file, Qt.Key_Down)
133
    mock.patch.object(QFileDialog, 'getOpenFileNames', return_value=(
134
                      [flac_file, mp3_file], '*.flac *.mp3'))
135
    qtbot.keyClick(window.file, Qt.Key_Enter)
136
137
138
def test_open_playlist(qtbot, mock, window):
139
    """Test the opening of a playlist file.
140
141
    Qtbot clicks on the file menu then Qt.Key_Down highlights
142
    the open playlist item. The mock plugin creates a mock of the
143
    QFileDialog window while Key_Enter executes it."""
144
    qtbot.mouseClick(window.file, Qt.LeftButton)
145
    qtbot.keyClick(window.file, Qt.Key_Down)
146
    qtbot.keyClick(window.file, Qt.Key_Down)
147
    qtbot.keyClick(window.file, Qt.Key_Down)
148
    mock.patch.object(QFileDialog, 'getOpenFileName', return_value=('test.m3u', '*.m3u'))
149
    qtbot.keyClick(window.file, Qt.Key_Enter)
150
151
152
def test_open_directory(qtbot, mock, window):
153
    """Test the opening of a media directory.
154
155
    Qtbot clicks on the file menu then Qt.Key_Down highlights
156
    the open directory item. The mock plugin creates a mock of the
157
    QFileDialog window while Key_Enter executes it."""
158
    file = os.path.join(os.path.dirname(__file__), '')
159
    qtbot.mouseClick(window.file, Qt.LeftButton)
160
    qtbot.keyClick(window.file, Qt.Key_Down)
161
    qtbot.keyClick(window.file, Qt.Key_Down)
162
    qtbot.keyClick(window.file, Qt.Key_Down)
163
    qtbot.keyClick(window.file, Qt.Key_Down)
164
    mock.patch.object(QFileDialog, 'getExistingDirectory', return_value=file)
165
    qtbot.keyClick(window.file, Qt.Key_Enter)
166
167
168
def test_quit_application(qtbot, monkeypatch, window):
169
    """Test that the application exits properly.
170
171
    Qtbot clicks on the file menu and Qt.Key_Down highlights the quit application
172
    item. Monkeypatch is set to intercept the exit call and will append 1 to exit_calls
173
    when it does."""
174
    exit_calls = []
175
    monkeypatch.setattr(QApplication, 'quit', lambda: exit_calls.append(1))
176
    qtbot.keyClick(window.file, Qt.Key_Down)
177
    qtbot.keyClick(window.file, Qt.Key_Down)
178
    qtbot.keyClick(window.file, Qt.Key_Down)
179
    qtbot.keyClick(window.file, Qt.Key_Down)
180
    qtbot.keyClick(window.file, Qt.Key_Down)
181
    qtbot.keyClick(window.file, Qt.Key_Enter)
182
    assert exit_calls == [1]
183
184
185
def test_preferences(qtbot, mock, window):
186
    """Test the preferences dialog.
187
188
    Qtbot clicks on the edit menu then Qt.Key_Down highlights
189
    the preferences item. The mock plugin creates a mock of the
190
    QDialog window while Key_Enter executes it."""
191
    qtbot.mouseClick(window.edit, Qt.LeftButton)
192
    qtbot.keyClick(window.edit, Qt.Key_Down)
193
    mock.patch.object(QDialog, 'exec_', return_value='accept')
194
    qtbot.keyClick(window.edit, Qt.Key_Enter)
195
196
197
def test_media_library_path(qtbot, mock, tmpdir, window, config):
198
    """Test the media library path setting in the preferences dialog.
199
200
    Qtbot tests the media library path selection by opening the preferences
201
    dialog, clicking on the set path button, and using the tmpdir fixture to provide
202
    a temporary directory."""
203
    qtbot.mouseClick(window.edit, Qt.LeftButton)
204
    qtbot.keyClick(window.edit, Qt.Key_Down)
205
    mock.patch.object(QDialog, 'exec_', return_value='')
206
    qtbot.keyClick(window.edit, Qt.Key_Enter)
207
    mock.patch.object(QFileDialog, 'getExistingDirectory', return_value=str(tmpdir))
208
    qtbot.mouseClick(config.dialog_media_library.media_library_button, Qt.LeftButton)
209
210
211
def test_playback_options(qtbot, mock, window, config):
212
    """Test the playback settings in the preferences dialog.
213
214
    Qtbot tests the functionality of the items in the Playback page of
215
    the preferences dialog. All of the checkboxes are selected and de-selected in
216
    order to test for segmentation faults."""
217
    qtbot.mouseClick(window.edit, Qt.LeftButton)
218
    qtbot.keyClick(window.edit, Qt.Key_Down)
219
    mock.patch.object(QDialog, 'exec_', return_value='')
220
    qtbot.keyClick(window.edit, Qt.Key_Enter)
221
    config.contents.setCurrentRow(1)
222
    qtbot.mouseClick(config.dialog_playback.cover_art_playback, Qt.LeftButton)
223
    qtbot.mouseClick(config.dialog_playback.cover_art_playback, Qt.LeftButton)
224
225
226
def test_view_options(qtbot, mock, window, config):
227
    """Test the view options in the preferences dialog.
228
229
    Qtbot tests the functionality of the items in the View Options page of
230
    the preferences dialog. All of the checkboxes and radio buttons are selected,
231
    and the window size dropdown box is set to the 400x400 window size."""
232
    qtbot.mouseClick(window.edit, Qt.LeftButton)
233
    qtbot.keyClick(window.edit, Qt.Key_Down)
234
    mock.patch.object(QDialog, 'exec_', return_value='')
235
    qtbot.keyClick(window.edit, Qt.Key_Enter)
236
    config.contents.setCurrentRow(2)
237
    qtbot.mouseClick(config.dialog_view_options.media_library_view_button, Qt.LeftButton)
238
    qtbot.mouseClick(config.dialog_view_options.media_library_view_button, Qt.LeftButton)
239
    qtbot.mouseClick(config.dialog_view_options.playlist_view_button, Qt.LeftButton)
240
    qtbot.mouseClick(config.dialog_view_options.playlist_view_button, Qt.LeftButton)
241
    qtbot.mouseClick(config.dialog_view_options.dock_left_side, Qt.LeftButton)
242
    qtbot.mouseClick(config.dialog_view_options.dock_right_side, Qt.LeftButton)
243
    config.dialog_view_options.dropdown_box.setCurrentIndex(5)
244
    config.dialog_view_options.dropdown_box.setCurrentIndex(0)
245
246
247
def test_about_dialog(qtbot, mock, window):
248
    """Test that the about dialog opens correctly.
249
250
    Qtbot clicks on the help menu then Qt.Key_Down highlights
251
    the about item. The mock plugin creates a mock of the
252
    QMessageBox window while Key_Enter executes it."""
253
    qtbot.mouseClick(window.help_, Qt.LeftButton)
254
    qtbot.keyClick(window.help_, Qt.Key_Down)
255
    mock.patch.object(QDialog, 'exec_', return_value='finished')
256
    qtbot.keyClick(window.help_, Qt.Key_Enter)
257
258
259
def test_playlist_view(qtbot, mock, window):
260
    """Test that the playlist dock widget opens correctly.
261
262
    Qtbot selects the view menu then keys down to the view playlist
263
    item. Once highlighted, qtbot simulates the enter key on the item."""
264
    qtbot.mouseClick(window.view, Qt.LeftButton)
265
    qtbot.keyClick(window.view, Qt.Key_Down)
266
    qtbot.keyClick(window.view, Qt.Key_Enter)
267
268
269
def test_minimalist_view(qtbot, window):
270
    """Test the minimalist view setting.
271
272
    Qtbot clicks on the view menu then Qt.Key_Down highlights the
273
    minimalist view item and selects it."""
274
    qtbot.mouseClick(window.view, Qt.LeftButton)
275
    qtbot.keyClick(window.view, Qt.Key_Down)
276
    qtbot.keyClick(window.view, Qt.Key_Down)
277
    qtbot.keyClick(window.view, Qt.Key_Down)
278
    qtbot.keyClick(window.view, Qt.Key_Enter)
279
280
281
def test_media_information(qtbot, mock, window):
282
    """Test that the media information dialog opens correctly..
283
284
    Qtbot clicks on the view menu then Qt.Key_Down highlights
285
    the media information item. The mock plugin creates a mock of the
286
    QDialog window while Key_Enter executes it."""
287
    qtbot.mouseClick(window.view, Qt.LeftButton)
288
    qtbot.keyClick(window.view, Qt.Key_Down)
289
    qtbot.keyClick(window.view, Qt.Key_Down)
290
    qtbot.keyClick(window.view, Qt.Key_Down)
291
    qtbot.keyClick(window.view, Qt.Key_Down)
292
    mock.patch.object(QDialog, 'exec_', return_value='finished')
293
    qtbot.keyClick(window.view, Qt.Key_Enter)
294
295
296
def test_media_library(qtbot, window):
297
    """Test that the media library dock widget opens correctly.
298
299
    Qtbot clicks on the view menu then navigates to the View Media Library
300
    item and uses Qt.Key_Enter to select it."""
301
    qtbot.mouseClick(window.view, Qt.LeftButton)
302
    qtbot.keyClick(window.view, Qt.Key_Down)
303
    qtbot.keyClick(window.view, Qt.Key_Down)
304
    qtbot.keyClick(window.view, Qt.Key_Enter)
305
306
307
def test_media_information_directly(qtbot, flac_file, mp3_file):
308
    """Test that the media information dialog shows information correctly.
309
310
    Creates an instance of the GenralInformation and FullInformation classes to see
311
    if there are any errors."""
312
    information.GeneralInformation(flac_file)
313
    information.FullInformation(flac_file)
314
    information.GeneralInformation(mp3_file)
315
    information.FullInformation(mp3_file)
316
317
318
def test_playback_play(qtbot, window):
319
    """Test the play item in the playback menu."""
320
    qtbot.mouseClick(window.playback, Qt.LeftButton)
321
    qtbot.keyClick(window.playback, Qt.Key_Down)
322
    qtbot.keyClick(window.playback, Qt.Key_Enter)
323
324
325
def test_playback_stop(qtbot, window):
326
    """Test the stop item in the playback menu."""
327
    qtbot.mouseClick(window.playback, Qt.LeftButton)
328
    qtbot.keyClick(window.playback, Qt.Key_Down)
329
    qtbot.keyClick(window.playback, Qt.Key_Down)
330
    qtbot.keyClick(window.playback, Qt.Key_Enter)
331
332
333
def test_playback_previous(qtbot, window):
334
    """Test the previous item in the playback menu."""
335
    qtbot.mouseClick(window.playback, Qt.LeftButton)
336
    qtbot.keyClick(window.playback, Qt.Key_Down)
337
    qtbot.keyClick(window.playback, Qt.Key_Down)
338
    qtbot.keyClick(window.playback, Qt.Key_Down)
339
    qtbot.keyClick(window.playback, Qt.Key_Enter)
340
341
342
def test_playback_next(qtbot, window):
343
    """Test the next item in the playback menu."""
344
    qtbot.mouseClick(window.playback, Qt.LeftButton)
345
    qtbot.keyClick(window.playback, Qt.Key_Down)
346
    qtbot.keyClick(window.playback, Qt.Key_Down)
347
    qtbot.keyClick(window.playback, Qt.Key_Down)
348
    qtbot.keyClick(window.playback, Qt.Key_Down)
349
    qtbot.keyClick(window.playback, Qt.Key_Enter)
350