Skip to content

Commit 7075280

Browse files
authored
Change mixer to use FileNotFoundError and fix related tests (#2001)
* Change pygame.error to FIleNotFoundError * fix test failing incorrectly * Fix related test * Update docs to reflect changes * Remove unnecessary error assignment * Remove unused variables
1 parent 2ee2e73 commit 7075280

File tree

4 files changed

+5
-11
lines changed

4 files changed

+5
-11
lines changed

docs/reST/ref/music.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ MP3 in most cases.
3434
the type of music data in the object. For example: :code:`load(fileobj, "ogg")`.
3535

3636
.. versionchanged:: 2.0.2 Added optional ``namehint`` argument
37+
.. versionchanged:: 2.2.0 Raises ``FileNotFoundError`` instead of :exc:`pygame.error` if file cannot be found
3738

3839
.. ## pygame.mixer.music.load ##
3940
@@ -243,6 +244,7 @@ MP3 in most cases.
243244
pygame.mixer.music.queue('mozart.ogg')
244245

245246
.. versionchanged:: 2.0.2 Added optional ``namehint`` argument
247+
.. versionchanged:: 2.2.0 Raises ``FileNotFoundError`` instead of :exc:`pygame.error` if file cannot be found
246248

247249
.. ## pygame.mixer.music.queue ##
248250

src_c/music.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -375,19 +375,11 @@ _load_music(PyObject *obj, char *namehint)
375375
Mix_Music *new_music = NULL;
376376
char *ext = NULL, *type = NULL;
377377
SDL_RWops *rw = NULL;
378-
PyObject *_type = NULL;
379-
PyObject *error = NULL;
380-
PyObject *_traceback = NULL;
381378

382379
MIXER_INIT_CHECK();
383380

384381
rw = pgRWops_FromObject(obj, &ext);
385-
if (rw ==
386-
NULL) { /* stop on NULL, error already set is what we SHOULD do */
387-
PyErr_Fetch(&_type, &error, &_traceback);
388-
PyErr_SetObject(pgExc_SDLError, error);
389-
Py_XDECREF(_type);
390-
Py_XDECREF(_traceback);
382+
if (rw == NULL) {
391383
return NULL;
392384
}
393385
if (namehint) {

test/mixer_music_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def test_queue__invalid_sound_type(self):
174174

175175
def test_queue__invalid_filename(self):
176176
"""Ensures queue() correctly handles invalid filenames."""
177-
with self.assertRaises(pygame.error):
177+
with self.assertRaises(FileNotFoundError):
178178
pygame.mixer.music.queue("")
179179

180180
def test_music_pause__unpause(self):

test/mixer_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def test_get_init__returns_exact_values_used_for_init(self):
9393
frequency, size, channels = init_conf.values()
9494
if (frequency, size) == (22050, 16):
9595
continue
96-
mixer.init(frequency, size, channels)
96+
mixer.init(frequency, size, channels, allowedchanges=0)
9797

9898
mixer_conf = mixer.get_init()
9999

0 commit comments

Comments
 (0)