@@ -1331,6 +1331,10 @@ def __init__(self):
13311331 self .assertRaises (RuntimeError , incorrect .get_volume )
13321332
13331333 def test_snd_copy (self ):
1334+ class SubSound (mixer .Sound ):
1335+ def __init__ (self , * args , ** kwargs ):
1336+ super ().__init__ (* args , ** kwargs )
1337+
13341338 mixer .init ()
13351339
13361340 filenames = [
@@ -1340,22 +1344,55 @@ def test_snd_copy(self):
13401344 "house_lo.opus" ,
13411345 "surfonasinewave.xm" ,
13421346 ]
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 ]
13431349 if pygame .mixer .get_sdl_mixer_version () >= (2 , 6 , 0 ):
13441350 filenames .append ("house_lo.mp3" )
13451351
1346- for f in filenames :
1352+ for f , old_vol , new_vol in zip ( filenames , old_volumes , new_volumes ) :
13471353 filename = example_path (os .path .join ("data" , f ))
13481354 try :
13491355 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 )
13501386 except pygame .error :
13511387 continue
13521388 sound_copy = sound .copy ()
1389+ self .assertTrue (sound_copy , SubSound )
13531390 self .assertEqual (sound .get_length (), sound_copy .get_length ())
13541391 self .assertEqual (sound .get_num_channels (), sound_copy .get_num_channels ())
13551392 self .assertEqual (sound .get_volume (), sound_copy .get_volume ())
13561393 self .assertEqual (sound .get_raw (), sound_copy .get_raw ())
13571394
1358- sound .set_volume (0.5 )
1395+ sound .set_volume (new_vol )
13591396 self .assertNotEqual (sound .get_volume (), sound_copy .get_volume ())
13601397
13611398 del sound
0 commit comments