@@ -1331,6 +1331,10 @@ def __init__(self):
1331
1331
self .assertRaises (RuntimeError , incorrect .get_volume )
1332
1332
1333
1333
def test_snd_copy (self ):
1334
+ class SubSound (mixer .Sound ):
1335
+ def __init__ (self , * args , ** kwargs ):
1336
+ super ().__init__ (* args , ** kwargs )
1337
+
1334
1338
mixer .init ()
1335
1339
1336
1340
filenames = [
@@ -1340,22 +1344,55 @@ def test_snd_copy(self):
1340
1344
"house_lo.opus" ,
1341
1345
"surfonasinewave.xm" ,
1342
1346
]
1347
+ old_volumes = [0.1 , 0.2 , 0.5 , 0.7 , 1.0 ]
1348
+ new_volumes = [0.2 , 0.3 , 0.7 , 1.0 , 0.1 ]
1343
1349
if pygame .mixer .get_sdl_mixer_version () >= (2 , 6 , 0 ):
1344
1350
filenames .append ("house_lo.mp3" )
1345
1351
1346
- for f in filenames :
1352
+ for f , old_vol , new_vol in zip ( filenames , old_volumes , new_volumes ) :
1347
1353
filename = example_path (os .path .join ("data" , f ))
1348
1354
try :
1349
1355
sound = mixer .Sound (file = filename )
1356
+ sound .set_volume (old_vol )
1357
+ except pygame .error :
1358
+ continue
1359
+ sound_copy = sound .copy ()
1360
+ self .assertEqual (sound .get_length (), sound_copy .get_length ())
1361
+ self .assertEqual (sound .get_num_channels (), sound_copy .get_num_channels ())
1362
+ self .assertEqual (sound .get_volume (), sound_copy .get_volume ())
1363
+ self .assertEqual (sound .get_raw (), sound_copy .get_raw ())
1364
+
1365
+ sound .set_volume (new_vol )
1366
+ self .assertNotEqual (sound .get_volume (), sound_copy .get_volume ())
1367
+
1368
+ del sound
1369
+
1370
+ # Test on the copy for playable sounds
1371
+ channel = sound_copy .play ()
1372
+ if channel is None :
1373
+ continue
1374
+ self .assertTrue (channel .get_busy ())
1375
+ sound_copy .stop ()
1376
+ self .assertFalse (channel .get_busy ())
1377
+ sound_copy .play ()
1378
+ self .assertEqual (sound_copy .get_num_channels (), 1 )
1379
+
1380
+ # Test copying a subclass of Sound
1381
+ for f , old_vol , new_vol in zip (filenames , old_volumes , new_volumes ):
1382
+ filename = example_path (os .path .join ("data" , f ))
1383
+ try :
1384
+ sound = SubSound (file = filename )
1385
+ sound .set_volume (old_vol )
1350
1386
except pygame .error :
1351
1387
continue
1352
1388
sound_copy = sound .copy ()
1389
+ self .assertTrue (sound_copy , SubSound )
1353
1390
self .assertEqual (sound .get_length (), sound_copy .get_length ())
1354
1391
self .assertEqual (sound .get_num_channels (), sound_copy .get_num_channels ())
1355
1392
self .assertEqual (sound .get_volume (), sound_copy .get_volume ())
1356
1393
self .assertEqual (sound .get_raw (), sound_copy .get_raw ())
1357
1394
1358
- sound .set_volume (0.5 )
1395
+ sound .set_volume (new_vol )
1359
1396
self .assertNotEqual (sound .get_volume (), sound_copy .get_volume ())
1360
1397
1361
1398
del sound
0 commit comments