Source

pygame / test / sndarray_test.py

Diff from to

File test/sndarray_test.py

 else:
     from test.test_utils import test_not_implemented, unittest
 import pygame
+from pygame.compat import as_bytes
 
 arraytype = ""
 try:
             self.fail("no array package installed")
 
         def check_array(size, channels, test_data):
-            pygame.mixer.init(22050, size, channels)
             try:
+                pygame.mixer.init(22050, size, channels)
+            except pygame.error:
                 # Not all sizes are supported on all systems.
+                return
+            try:
                 __, sz, __ = pygame.mixer.get_init()
                 if sz == size:
                     srcarr = array(test_data, self.array_dtypes[size])
             self.fail("no array package installed")
 
         def check_sound(size, channels, test_data):
-            pygame.mixer.init(22050, size, channels)
             try:
+                pygame.mixer.init(22050, size, channels)
+            except pygame.error:
                 # Not all sizes are supported on all systems.
+                return
+            try:
                 __, sz, __ = pygame.mixer.get_init()
                 if sz == size:
                     srcarr = array(test_data, self.array_dtypes[size])
         if not arraytype:
             self.fail("no array package installed")
 
+        null_byte = as_bytes('\x00')
         def check_sample(size, channels, test_data):
-            pygame.mixer.init(22050, size, channels)
             try:
+                pygame.mixer.init(22050, size, channels)
+            except pygame.error:
                 # Not all sizes are supported on all systems.
+                return
+            try:
                 __, sz, __ = pygame.mixer.get_init()
                 if sz == size:
-                    zeroed = '\0' * ((abs(size) // 8) *
-                                     len(test_data) *
-                                     channels)
-                    snd = pygame.mixer.Sound(buffer(zeroed))
+                    zeroed = null_byte * ((abs(size) // 8) *
+                                          len(test_data) *
+                                          channels)
+                    snd = pygame.mixer.Sound(buffer=zeroed)
                     samples = pygame.sndarray.samples(snd)
                     self._assert_compatible(samples, size)
-                    print ('X %s' % (samples.shape,))
-                    print ('Y %s' % (test_data,))
+                    ##print ('X %s' % (samples.shape,))
+                    ##print ('Y %s' % (test_data,))
                     samples[...] = test_data
                     arr = pygame.sndarray.array(snd)
                     self.failUnless(alltrue(samples == arr),