Anonymous avatar Anonymous committed 639de8e

Added in numerous test for pygame.Surface methods.

Comments (0)

Files changed (4)

test/color_test.py

 ################################################################################
 
     def test_correct_gamma__verified_against_python_implementation(self):
+        "|tags:slow|"
         # gamma_correct defined at top of page
 
         gammas = map(lambda i: i / 10.0, range(1, 31)) # [0.1 .. 3.0]

test/display_test.py

 class DisplayModuleTest( unittest.TestCase ):
     def test_update( self ):
         """ see if pygame.display.update takes rects with negative values.
+            "|Tags:display|"
         """
 
-        if 0:
+        if 1:
             pygame.init()
             screen = pygame.display.set_mode((100,100))
             screen.fill((55,55,55))
             pygame.quit()
             #  I think it's because unittest runs stuff in threads
             # here's a stack trace...
+            
+            # NOTE to author of above:
+            #   unittest doesn't run tests in threads    
+            #   segfault was probably caused by another tests need 
+            #   for a "clean slate"
+            
             """
     #0  0x08103b7c in PyFrame_New ()
     #1  0x080bd666 in PyEval_EvalCodeEx ()
     #10 0x08054e31 in _start ()
 
             """
-
-
-
-    def test_init__quit( self ):
-        """ see if initing, and quiting works.
-        """
-        # old test, was disabled so placing reminder
-        self.assert_(test_not_implemented())
-        
-        if 0:
-            pygame.init()
-            screen = pygame.display.set_mode((100,100))
-            #pygame.quit()
-    
     def test_Info(self):
     
         # __doc__ (as of 2008-06-25) for pygame.display.Info:

test/scrap_test.py

 import pygame
 import pygame.scrap as scrap
 
-class ScrapModuleTest(unittest.TestCase):
+class ScrapModuleTest(unittest.TestCase):    
     def test_contains(self):
 
         # __doc__ (as of 2008-06-25) for pygame.scrap.contains:
         self.assertEquals (r, "buf")
 
 if __name__ == '__main__':
-    test_utils.get_command_line_options()
-
-    #TODO....
     pygame.init ()
     pygame.display.set_mode ((1, 1))
     scrap.init ()
-    #unittest.main()
+    unittest.main()

test/surface_test.py

         self.assertEqual(bound_rect.height, 31)
 
 
-    def test_blit(self):
+    def test_blit(self):        # See blit_test.py
 
         # __doc__ (as of 2008-06-25) for pygame.surface.Surface.blit:
 
           # Surface.convert(): return Surface
           # change the pixel format of an image
 
-        self.assert_(test_not_implemented()) 
+        self.assert_(test_not_implemented())
 
     def test_convert_alpha(self):
 
 
           # Surface.copy(): return Surface
           # create a new copy of a Surface
-
-        self.assert_(test_not_implemented()) 
+        
+        color = (25, 25, 25, 25)
+        s1 = pygame.Surface((32,32), pygame.SRCALPHA, 32)
+        s1.fill(color)
+        
+        s2 = s1.copy()
+        
+        s1rect = s1.get_rect()
+        s2rect = s2.get_rect()
+        
+        self.assert_(s1rect.size == s2rect.size)
+        self.assert_(s2.get_at((10,10)) == color)
 
     def test_fill(self):
 
 
           # Surface.fill(color, rect=None, special_flags=0): return Rect
           # fill Surface with a solid color
+        
+        color = (25, 25, 25, 25)
+        fill_rect = pygame.Rect(0, 0, 16, 16)
+        
+        s1 = pygame.Surface((32,32), pygame.SRCALPHA, 32)
+        s1.fill(color, fill_rect)   
+        
+        for pt in test_utils.rect_area_pts(fill_rect):
+            self.assert_(s1.get_at(pt) == color )
+        
+        for pt in test_utils.rect_outer_bounds(fill_rect):
+            self.assert_(s1.get_at(pt) != color )
 
-        self.assert_(test_not_implemented()) 
+        self.assert_(test_not_implemented())
 
     def test_get_abs_offset(self):
 
 
         self.assert_(test_not_implemented()) 
 
+    ########################################################################
+
     def test_get_alpha(self):
 
         # __doc__ (as of 2008-06-25) for pygame.surface.Surface.get_alpha:
           # Surface.get_alpha(): return int_value or None
           # get the current Surface transparency value
 
+        s1 = pygame.Surface((32,32), pygame.SRCALPHA, 32)
+        self.assert_(s1.get_alpha() == 255)
+        
+        for alpha in (0, 32, 127, 255):
+            s1.set_alpha(alpha)
+            for t in range(4): s1.set_alpha(s1.get_alpha())
+            self.assert_(s1.get_alpha() == alpha)
+                
+    def test_set_alpha(self):
+        # __doc__ (as of 2008-06-25) for pygame.surface.Surface.set_alpha:
+    
+          # Surface.set_alpha(value, flags=0): return None
+          # Surface.set_alpha(None): return None
+          # set the alpha value for the full Surface image
+    
         self.assert_(test_not_implemented()) 
-
+    
+    ########################################################################
+    
     def test_get_at(self):
 
         # __doc__ (as of 2008-06-25) for pygame.surface.Surface.get_at:
 
         self.assert_(test_not_implemented()) 
 
+    ########################################################################
+
     def test_get_bitsize(self):
-
         # __doc__ (as of 2008-06-25) for pygame.surface.Surface.get_bitsize:
 
           # Surface.get_bitsize(): return int
 
           # Surface.get_bytesize(): return int
           # get the bytes used per Surface pixel
+        
+        s1 = pygame.Surface((32,32), pygame.SRCALPHA, 32)
+        self.assert_(s1.get_bytesize() == 4)
+        self.assert_(s1.get_bitsize() == 32)
 
-        self.assert_(test_not_implemented()) 
+    ########################################################################
 
     def test_get_clip(self):
 
 
         self.assert_(test_not_implemented()) 
 
-    def test_get_colorkey(self):
-
-        # __doc__ (as of 2008-06-25) for pygame.surface.Surface.get_colorkey:
-
-          # Surface.get_colorkey(): return RGB or None
-          # Get the current transparent colorkey
-
-        self.assert_(test_not_implemented()) 
-
     def test_get_flags(self):
 
         # __doc__ (as of 2008-06-25) for pygame.surface.Surface.get_flags:
 
           # Surface.get_flags(): return int
           # get the additional flags used for the Surface
-
-        self.assert_(test_not_implemented()) 
-
-    def test_get_height(self):
-
-        # __doc__ (as of 2008-06-25) for pygame.surface.Surface.get_height:
-
-          # Surface.get_height(): return height
-          # get the height of the Surface
-
-        self.assert_(test_not_implemented()) 
+        
+        s1 = pygame.Surface((32,32), pygame.SRCALPHA, 32)
+        self.assert_(s1.get_flags() == pygame.SRCALPHA)
 
     def test_get_locked(self):
 
           # find the position of a child subsurface inside a parent
 
         self.assert_(test_not_implemented()) 
-
-    def test_get_palette(self):
-
-        # __doc__ (as of 2008-06-25) for pygame.surface.Surface.get_palette:
-
-          # Surface.get_palette(): return [RGB, RGB, RGB, ...]
-          # get the color index palette for an 8bit Surface
-
+    
+    ########################################################################
+    
+    def test_subsurface(self):
+        # __doc__ (as of 2008-06-25) for pygame.surface.Surface.subsurface:
+    
+          # Surface.subsurface(Rect): return Surface
+          # create a new surface that references its parent
+    
         self.assert_(test_not_implemented()) 
-
-    def test_get_palette_at(self):
-
-        # __doc__ (as of 2008-06-25) for pygame.surface.Surface.get_palette_at:
-
-          # Surface.get_palette_at(index): return RGB
-          # get the color for a single entry in a palette
-
-        self.assert_(test_not_implemented()) 
-
+    
     def test_get_parent(self):
 
         # __doc__ (as of 2008-06-25) for pygame.surface.Surface.get_parent:
           # Surface.get_parent(): return Surface
           # find the parent of a subsurface
 
-        self.assert_(test_not_implemented()) 
+        parent = pygame.Surface((16, 16))
+        child = parent.subsurface((0,0,5,5))
+
+        self.assert_(child.get_parent() is parent) 
+        
+    ########################################################################
 
     def test_get_pitch(self):
 
 
           # Surface.get_rect(**kwargs): return Rect
           # get the rectangular area of the Surface
-
-        self.assert_(test_not_implemented())
+        
+        surf = pygame.Surface((16, 16))
+        
+        rect = surf.get_rect()
+        
+        self.assert_(rect.size == (16, 16))
 
     def test_get_shifts(self):
 
 
         self.assert_(test_not_implemented()) 
 
+    ########################################################################
+
     def test_get_size(self):
-
         # __doc__ (as of 2008-06-25) for pygame.surface.Surface.get_size:
 
           # Surface.get_size(): return (width, height)
 
         self.assert_(test_not_implemented()) 
 
-    def test_get_width(self):
+    def test_get_width__size_and_height(self):
 
         # __doc__ (as of 2008-06-25) for pygame.surface.Surface.get_width:
 
           # Surface.get_width(): return width
           # get the width of the Surface
+        
+        for w in xrange(0, 255, 32):
+            for h in xrange(0, 127, 15):
+                s = pygame.Surface((w, h))
+                self.assertEquals(s.get_width(), w) 
+                self.assertEquals(s.get_height(), h) 
+                self.assertEquals(s.get_size(), (w, h))
 
-        self.assert_(test_not_implemented()) 
+    ########################################################################
 
     def test_lock(self):
 
           # Surface.lock(): return None
           # lock the Surface memory for pixel access
 
-        self.assert_(test_not_implemented()) 
+        self.assert_(test_not_implemented())
 
     def test_map_rgb(self):
 
 
         self.assert_(test_not_implemented()) 
 
-    def test_set_alpha(self):
-
-        # __doc__ (as of 2008-06-25) for pygame.surface.Surface.set_alpha:
-
-          # Surface.set_alpha(value, flags=0): return None
-          # Surface.set_alpha(None): return None
-          # set the alpha value for the full Surface image
-
+    ########################################################################
+    
+    def test_get_colorkey(self):
+        
+        # __doc__ (as of 2008-06-25) for pygame.surface.Surface.get_colorkey:
+    
+          # Surface.get_colorkey(): return RGB or None
+          # Get the current transparent colorkey
+    
         self.assert_(test_not_implemented()) 
-
+    
     def test_set_colorkey(self):
 
         # __doc__ (as of 2008-06-25) for pygame.surface.Surface.set_colorkey:
           # Surface.set_colorkey(Color, flags=0): return None
           # Surface.set_colorkey(None): return None
           # Set the transparent colorkey
+        
+        s = pygame.Surface((16,16), pygame.SRCALPHA, 32)
+        
+        colorkeys = ((20,189,20, 255),(128,50,50,255), (23, 21, 255,255))
 
-        self.assert_(test_not_implemented()) 
+        for colorkey in colorkeys:
+            s.set_colorkey(colorkey)
+            for t in range(4): s.set_colorkey(s.get_colorkey())
+            self.assertEquals(s.get_colorkey(), colorkey) 
+
+    ########################################################################
 
     def test_set_palette(self):
 
           # Surface.set_palette([RGB, RGB, RGB, ...]): return None
           # set the color palette for an 8bit Surface
 
+        self.assert_(test_not_implemented())
+
+    def test_get_palette(self):
+
+        # __doc__ (as of 2008-06-25) for pygame.surface.Surface.get_palette:
+
+          # Surface.get_palette(): return [RGB, RGB, RGB, ...]
+          # get the color index palette for an 8bit Surface
+
         self.assert_(test_not_implemented()) 
 
+    ########################################################################
+
     def test_set_palette_at(self):
 
         # __doc__ (as of 2008-06-25) for pygame.surface.Surface.set_palette_at:
 
         self.assert_(test_not_implemented()) 
 
-    def test_subsurface(self):
+    def test_get_palette_at(self):
 
-        # __doc__ (as of 2008-06-25) for pygame.surface.Surface.subsurface:
+        # __doc__ (as of 2008-06-25) for pygame.surface.Surface.get_palette_at:
 
-          # Surface.subsurface(Rect): return Surface
-          # create a new surface that references its parent
+          # Surface.get_palette_at(index): return RGB
+          # get the color for a single entry in a palette
 
         self.assert_(test_not_implemented()) 
 
+    ########################################################################
+
     def test_unlock(self):
 
         # __doc__ (as of 2008-06-25) for pygame.surface.Surface.unlock:
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.