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 ( 83dd25...ed70cc )
by Mandeep
37s
created

test_save_playlist()   A

Complexity

Conditions 1

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 16
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_save_playlist(qtbot, mock, window, tmpdir):
153
    """Test the saving of media in the playlist dock.
154
155
    Qtbot clicks on the file menu then Qt.Key_Down highlights
156
    the save playlist item. The mock plugin creates a mock of the
157
    QFileDialog window while Key_Enter executes it."""
158
    tmpdir.chdir()
159
160
    qtbot.mouseClick(window.file, Qt.LeftButton)
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
    qtbot.keyClick(window.file, Qt.Key_Down)
165
    qtbot.keyClick(window.file, Qt.Key_Down)
166
    mock.patch.object(QFileDialog, 'getSaveFileName', return_value=('test', '*.m3u'))
167
    qtbot.keyClick(window.file, Qt.Key_Enter)
168
169
170
def test_open_directory(qtbot, mock, window):
171
    """Test the opening of a media directory.
172
173
    Qtbot clicks on the file menu then Qt.Key_Down highlights
174
    the open directory item. The mock plugin creates a mock of the
175
    QFileDialog window while Key_Enter executes it."""
176
    file = os.path.join(os.path.dirname(__file__), '')
177
    qtbot.mouseClick(window.file, Qt.LeftButton)
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_Down)
182
    mock.patch.object(QFileDialog, 'getExistingDirectory', return_value=file)
183
    qtbot.keyClick(window.file, Qt.Key_Enter)
184
185
186
def test_quit_application(qtbot, monkeypatch, window):
187
    """Test that the application exits properly.
188
189
    Qtbot clicks on the file menu and Qt.Key_Down highlights the quit application
190
    item. Monkeypatch is set to intercept the exit call and will append 1 to exit_calls
191
    when it does."""
192
    exit_calls = []
193
    monkeypatch.setattr(QApplication, 'quit', lambda: exit_calls.append(1))
194
    qtbot.keyClick(window.file, Qt.Key_Down)
195
    qtbot.keyClick(window.file, Qt.Key_Down)
196
    qtbot.keyClick(window.file, Qt.Key_Down)
197
    qtbot.keyClick(window.file, Qt.Key_Down)
198
    qtbot.keyClick(window.file, Qt.Key_Down)
199
    qtbot.keyClick(window.file, Qt.Key_Down)
200
    qtbot.keyClick(window.file, Qt.Key_Enter)
201
    assert exit_calls == [1]
202
203
204
def test_preferences(qtbot, mock, window):
205
    """Test the preferences dialog.
206
207
    Qtbot clicks on the edit menu then Qt.Key_Down highlights
208
    the preferences item. The mock plugin creates a mock of the
209
    QDialog window while Key_Enter executes it."""
210
    qtbot.mouseClick(window.edit, Qt.LeftButton)
211
    qtbot.keyClick(window.edit, Qt.Key_Down)
212
    mock.patch.object(QDialog, 'exec_', return_value='accept')
213
    qtbot.keyClick(window.edit, Qt.Key_Enter)
214
215
216
def test_media_library_path(qtbot, mock, tmpdir, window, config):
217
    """Test the media library path setting in the preferences dialog.
218
219
    Qtbot tests the media library path selection by opening the preferences
220
    dialog, clicking on the set path button, and using the tmpdir fixture to provide
221
    a temporary directory."""
222
    qtbot.mouseClick(window.edit, Qt.LeftButton)
223
    qtbot.keyClick(window.edit, Qt.Key_Down)
224
    mock.patch.object(QDialog, 'exec_', return_value='')
225
    qtbot.keyClick(window.edit, Qt.Key_Enter)
226
    mock.patch.object(QFileDialog, 'getExistingDirectory', return_value=str(tmpdir))
227
    qtbot.mouseClick(config.dialog_media_library.media_library_button, Qt.LeftButton)
228
229
230
def test_playback_options(qtbot, mock, window, config):
231
    """Test the playback settings in the preferences dialog.
232
233
    Qtbot tests the functionality of the items in the Playback page of
234
    the preferences dialog. All of the checkboxes are selected and de-selected in
235
    order to test for segmentation faults."""
236
    qtbot.mouseClick(window.edit, Qt.LeftButton)
237
    qtbot.keyClick(window.edit, Qt.Key_Down)
238
    mock.patch.object(QDialog, 'exec_', return_value='')
239
    qtbot.keyClick(window.edit, Qt.Key_Enter)
240
    config.contents.setCurrentRow(1)
241
    qtbot.mouseClick(config.dialog_playback.cover_art_playback, Qt.LeftButton)
242
    qtbot.mouseClick(config.dialog_playback.cover_art_playback, Qt.LeftButton)
243
244
245
def test_view_options(qtbot, mock, window, config):
246
    """Test the view options in the preferences dialog.
247
248
    Qtbot tests the functionality of the items in the View Options page of
249
    the preferences dialog. All of the checkboxes and radio buttons are selected,
250
    and the window size dropdown box is set to the 400x400 window size."""
251
    qtbot.mouseClick(window.edit, Qt.LeftButton)
252
    qtbot.keyClick(window.edit, Qt.Key_Down)
253
    mock.patch.object(QDialog, 'exec_', return_value='')
254
    qtbot.keyClick(window.edit, Qt.Key_Enter)
255
    config.contents.setCurrentRow(2)
256
    qtbot.mouseClick(config.dialog_view_options.media_library_view_button, Qt.LeftButton)
257
    qtbot.mouseClick(config.dialog_view_options.media_library_view_button, Qt.LeftButton)
258
    qtbot.mouseClick(config.dialog_view_options.playlist_view_button, Qt.LeftButton)
259
    qtbot.mouseClick(config.dialog_view_options.playlist_view_button, Qt.LeftButton)
260
    qtbot.mouseClick(config.dialog_view_options.dock_left_side, Qt.LeftButton)
261
    qtbot.mouseClick(config.dialog_view_options.dock_right_side, Qt.LeftButton)
262
    config.dialog_view_options.dropdown_box.setCurrentIndex(5)
263
    config.dialog_view_options.dropdown_box.setCurrentIndex(0)
264
265
266
def test_about_dialog(qtbot, mock, window):
267
    """Test that the about dialog opens correctly.
268
269
    Qtbot clicks on the help menu then Qt.Key_Down highlights
270
    the about item. The mock plugin creates a mock of the
271
    QMessageBox window while Key_Enter executes it."""
272
    qtbot.mouseClick(window.help_, Qt.LeftButton)
273
    qtbot.keyClick(window.help_, Qt.Key_Down)
274
    mock.patch.object(QDialog, 'exec_', return_value='finished')
275
    qtbot.keyClick(window.help_, Qt.Key_Enter)
276
277
278
def test_playlist_view(qtbot, mock, window):
279
    """Test that the playlist dock widget opens correctly.
280
281
    Qtbot selects the view menu then keys down to the view playlist
282
    item. Once highlighted, qtbot simulates the enter key on the item."""
283
    qtbot.mouseClick(window.view, Qt.LeftButton)
284
    qtbot.keyClick(window.view, Qt.Key_Down)
285
    qtbot.keyClick(window.view, Qt.Key_Enter)
286
287
288
def test_minimalist_view(qtbot, window):
289
    """Test the minimalist view setting.
290
291
    Qtbot clicks on the view menu then Qt.Key_Down highlights the
292
    minimalist view item and selects it."""
293
    qtbot.mouseClick(window.view, Qt.LeftButton)
294
    qtbot.keyClick(window.view, Qt.Key_Down)
295
    qtbot.keyClick(window.view, Qt.Key_Down)
296
    qtbot.keyClick(window.view, Qt.Key_Down)
297
    qtbot.keyClick(window.view, Qt.Key_Enter)
298
299
300
def test_media_information(qtbot, mock, window):
301
    """Test that the media information dialog opens correctly..
302
303
    Qtbot clicks on the view menu then Qt.Key_Down highlights
304
    the media information item. The mock plugin creates a mock of the
305
    QDialog window while Key_Enter executes it."""
306
    qtbot.mouseClick(window.view, Qt.LeftButton)
307
    qtbot.keyClick(window.view, Qt.Key_Down)
308
    qtbot.keyClick(window.view, Qt.Key_Down)
309
    qtbot.keyClick(window.view, Qt.Key_Down)
310
    qtbot.keyClick(window.view, Qt.Key_Down)
311
    mock.patch.object(QDialog, 'exec_', return_value='finished')
312
    qtbot.keyClick(window.view, Qt.Key_Enter)
313
314
315
def test_media_library(qtbot, window):
316
    """Test that the media library dock widget opens correctly.
317
318
    Qtbot clicks on the view menu then navigates to the View Media Library
319
    item and uses Qt.Key_Enter to select it."""
320
    qtbot.mouseClick(window.view, Qt.LeftButton)
321
    qtbot.keyClick(window.view, Qt.Key_Down)
322
    qtbot.keyClick(window.view, Qt.Key_Down)
323
    qtbot.keyClick(window.view, Qt.Key_Enter)
324
325
326
def test_media_information_directly(qtbot, flac_file, mp3_file):
327
    """Test that the media information dialog shows information correctly.
328
329
    Creates an instance of the GenralInformation and FullInformation classes to see
330
    if there are any errors."""
331
    information.GeneralInformation(flac_file)
332
    information.FullInformation(flac_file)
333
    information.GeneralInformation(mp3_file)
334
    information.FullInformation(mp3_file)
335
336
337
def test_playback_play(qtbot, window):
338
    """Test the play item in the playback menu."""
339
    qtbot.mouseClick(window.playback, Qt.LeftButton)
340
    qtbot.keyClick(window.playback, Qt.Key_Down)
341
    qtbot.keyClick(window.playback, Qt.Key_Enter)
342
343
344
def test_playback_stop(qtbot, window):
345
    """Test the stop item in the playback menu."""
346
    qtbot.mouseClick(window.playback, Qt.LeftButton)
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
351
352
def test_playback_previous(qtbot, window):
353
    """Test the previous item in the playback menu."""
354
    qtbot.mouseClick(window.playback, Qt.LeftButton)
355
    qtbot.keyClick(window.playback, Qt.Key_Down)
356
    qtbot.keyClick(window.playback, Qt.Key_Down)
357
    qtbot.keyClick(window.playback, Qt.Key_Down)
358
    qtbot.keyClick(window.playback, Qt.Key_Enter)
359
360
361
def test_playback_next(qtbot, window):
362
    """Test the next item in the playback menu."""
363
    qtbot.mouseClick(window.playback, Qt.LeftButton)
364
    qtbot.keyClick(window.playback, Qt.Key_Down)
365
    qtbot.keyClick(window.playback, Qt.Key_Down)
366
    qtbot.keyClick(window.playback, Qt.Key_Down)
367
    qtbot.keyClick(window.playback, Qt.Key_Down)
368
    qtbot.keyClick(window.playback, Qt.Key_Enter)
369