Anonymous avatar Anonymous committed e19d49b

Use proper palettes in tests.

Comments (0)

Files changed (2)

test/sdl_video_surface_blit_test.py

     import pgunittest as unittest
 
 import pygame2
+from pygame2.colorpalettes import CGAPALETTE
 from pygame2 import Color, Rect
 import pygame2.sdl.video as video
 import pygame2.sdl.constants as constants
 
-def get_cga_palette ():
-    return [
-        Color ("#000000"), # black
-        Color ("#0000AA"), # blue
-        Color ("#00AA00"), # green
-        Color ("#00AAAA"), # cyan
-        Color ("#AA0000"), # red
-        Color ("#AA00AA"), # magenta
-        Color ("#AA5500"), # brown
-        Color ("#AAAAAA"), # white
-        
-        Color ("#555555"), # gray
-        Color ("#5555FF"), # blue
-        Color ("#55FF55"), # green
-        Color ("#55FFFF"), # cyan
-        Color ("#FF5555"), # red
-        Color ("#FF55FF"), # magenta
-        Color ("#FFFF55"), # yellow
-        Color ("#FFFFFF"), # white
-    ]
-
 class SDLVideoSurfaceBlitTest (unittest.TestCase):
     # __doc__ (as of 2009-05-15) for pygame2.sdl.video.Surface.blit:
 
         for bpp in modes:
             sf2 = video.Surface (5,  5, bpp)
             if bpp == 8:
-                sf2.set_palette (get_cga_palette())
+                sf2.set_palette (CGAPALETTE)
 
             sf1.fill (color1)
             sf2.fill (color2)
         for bpp in modes:
             sf2 = video.Surface ( 5,  5, bpp)
             if bpp == 8:
-                sf2.set_palette (get_cga_palette())
+                sf2.set_palette (CGAPALETTE)
         
             sf1.fill (color1)
             sf2.fill (color2)
         for bpp in modes:
             sf2 = video.Surface ( 5,  5, bpp)
             if bpp == 8:
-                sf2.set_palette (get_cga_palette())
+                sf2.set_palette (CGAPALETTE)
         
             sf1.fill (color1)
             sf2.fill (color2)
         color1 = Color (127, 0, 0)
         color2 = Color (0, 127, 0)
         sf1 = video.Surface (10, 10, 8)
-        sf1.set_palette (get_cga_palette())
+        sf1.set_palette (CGAPALETTE)
         for bpp in modes:
             sf2 = video.Surface ( 5,  5, 8)
             if bpp == 8:
-                sf2.set_palette (get_cga_palette())
+                sf2.set_palette (CGAPALETTE)
         
             sf1.fill (color1)
             sf2.fill (color2)
         for bpp in modes:
             sf2 = video.Surface ( 5,  5, bpp)
             if bpp == 8:
-                sf2.set_palette (get_cga_palette())
+                sf2.set_palette (CGAPALETTE)
         
             sf1.fill (color1)
             sf2.fill (color2)
         for bpp in modes:
             sf2 = video.Surface ( 5,  5, bpp)
             if bpp == 8:
-                sf2.set_palette (get_cga_palette())
+                sf2.set_palette (CGAPALETTE)
         
             sf1.fill (color1)
             sf2.fill (color2)
         for bpp in modes:
             sf2 = video.Surface (5, 5, bpp)
             if bpp == 8:
-                sf2.set_palette (get_cga_palette())
+                sf2.set_palette (CGAPALETTE)
         
             sf1.fill (color1)
             sf2.fill (color2)
         color1 = Color (127, 0, 0)
         color2 = Color (0, 127, 0)
         sf1 = video.Surface (10, 10, 8)
-        sf1.set_palette (get_cga_palette())
+        sf1.set_palette (CGAPALETTE)
         for bpp in modes:
             sf2 = video.Surface ( 5,  5, bpp)
             if bpp == 8:
-                sf2.set_palette (get_cga_palette())
+                sf2.set_palette (CGAPALETTE)
         
             sf1.fill (color1)
             sf2.fill (color2)
         for bpp in modes:
             sf2 = video.Surface ( 5,  5, bpp)
             if bpp == 8:
-                sf2.set_palette (get_cga_palette())
+                sf2.set_palette (CGAPALETTE)
         
             sf1.fill (color1)
             sf2.fill (color2)
         for bpp in modes:
             sf2 = video.Surface ( 5,  5, bpp)
             if bpp == 8:
-                sf2.set_palette (get_cga_palette())
+                sf2.set_palette (CGAPALETTE)
         
             sf1.fill (color1)
             sf2.fill (color2)
         for bpp in modes:
             sf2 = video.Surface ( 5,  5, bpp)
             if bpp == 8:
-                sf2.set_palette (get_cga_palette())
+                sf2.set_palette (CGAPALETTE)
         
             sf1.fill (color1)
             sf2.fill (color2)
         color1 = Color (255, 255, 255)
         color2 = Color (0, 127, 0)
         sf1 = video.Surface (10, 10, 8)
-        sf1.set_palette (get_cga_palette())
+        sf1.set_palette (CGAPALETTE)
         for bpp in modes:
             sf2 = video.Surface ( 5,  5, bpp)
             if bpp == 8:
-                sf2.set_palette (get_cga_palette())
+                sf2.set_palette (CGAPALETTE)
         
             sf1.fill (color1)
             sf2.fill (color2)
         for bpp in modes:
             sf2 = video.Surface ( 5,  5, bpp)
             if bpp == 8:
-                sf2.set_palette (get_cga_palette())
+                sf2.set_palette (CGAPALETTE)
         
             sf1.fill (color1)
             sf2.fill (color2)
         for bpp in modes:
             sf2 = video.Surface ( 5,  5, bpp)
             if bpp == 8:
-                sf2.set_palette (get_cga_palette())
+                sf2.set_palette (CGAPALETTE)
         
             sf1.fill (color1)
             sf2.fill (color2)
         for bpp in modes:
             sf2 = video.Surface ( 5,  5, bpp)
             if bpp == 8:
-                sf2.set_palette (get_cga_palette())
+                sf2.set_palette (CGAPALETTE)
         
             sf1.fill (color1)
             sf2.fill (color2)
         color1 = Color (30, 10, 100)
         color2 = Color (0, 127, 24)
         sf1 = video.Surface (10, 10, 8)
-        sf1.set_palette (get_cga_palette())
+        sf1.set_palette (CGAPALETTE)
         for bpp in modes:
             sf2 = video.Surface ( 5,  5, bpp)
             if bpp == 8:
-                sf2.set_palette (get_cga_palette())
+                sf2.set_palette (CGAPALETTE)
         
             sf1.fill (color1)
             sf2.fill (color2)
         for bpp in modes:
             sf2 = video.Surface ( 5,  5, bpp)
             if bpp == 8:
-                sf2.set_palette (get_cga_palette())
+                sf2.set_palette (CGAPALETTE)
         
             sf1.fill (color1)
             sf2.fill (color2)
         for bpp in modes:
             sf2 = video.Surface ( 5,  5, bpp)
             if bpp == 8:
-                sf2.set_palette (get_cga_palette())
+                sf2.set_palette (CGAPALETTE)
         
             sf1.fill (color1)
             sf2.fill (color2)
         for bpp in modes:
             sf2 = video.Surface ( 5,  5, bpp)
             if bpp == 8:
-                sf2.set_palette (get_cga_palette())
+                sf2.set_palette (CGAPALETTE)
         
             sf1.fill (color1)
             sf2.fill (color2)
         color1 = Color (255, 100, 12)
         color2 = Color (133, 127, 16)
         sf1 = video.Surface (10, 10, 8)
-        sf1.set_palette (get_cga_palette())
+        sf1.set_palette (CGAPALETTE)
         for bpp in modes:
             sf2 = video.Surface ( 5,  5, bpp)
             if bpp == 8:
-                sf2.set_palette (get_cga_palette())
+                sf2.set_palette (CGAPALETTE)
         
             sf1.fill (color1)
             sf2.fill (color2)
         for bpp in modes:
             sf2 = video.Surface (5, 5, bpp)
             if bpp == 8:
-                sf2.set_palette (get_cga_palette())
+                sf2.set_palette (CGAPALETTE)
         
             sf1.fill (color1)
             sf2.fill (color2)
             
             # Color (1, 3, 0)
             ca, cb = sf1.get_at (0, 0), sf2.get_at (0, 0)
-            c2 = Color ((ca.r * cb.r) >> 8, (ca.g * cb.g) >> 8, (ca.b * cb.b) >> 8)
+            c2 = Color ((ca.r * cb.r) >> 8, (ca.g * cb.g) >> 8,
+                        (ca.b * cb.b) >> 8)
             sf1.blit (sf2, blendargs=constants.BLEND_RGB_MULT)
             self._cmpcolor (sf1, sf2, c2, Rect (0, 0, 5, 5))
             self._cmpcolor (sf1, sf2, color1, Rect (5, 5, 5, 5))
             # Color (0, 0, 0)
             sf2.fill (Color (0, 0, 0))
             ca, cb = sf1.get_at (0, 0), sf2.get_at (0, 0)
-            c2 = Color ((ca.r * cb.r) >> 8, (ca.g * cb.g) >> 8, (ca.b * cb.b) >> 8)
+            c2 = Color ((ca.r * cb.r) >> 8, (ca.g * cb.g) >> 8,
+                        (ca.b * cb.b) >> 8)
             sf1.blit (sf2, blendargs=constants.BLEND_RGB_MULT)
             self._cmpcolor (sf1, sf2, c2, Rect (0, 0, 5, 5))
             self._cmpcolor (sf1, sf2, color1, Rect (5, 5, 5, 5))
         for bpp in modes:
             sf2 = video.Surface (5, 5, bpp)
             if bpp == 8:
-                sf2.set_palette (get_cga_palette())
+                sf2.set_palette (CGAPALETTE)
         
             sf1.fill (color1)
             sf2.fill (color2)
             ca, cb = sf1.get_at (0, 0), sf2.get_at (0, 0)
-            c2 = Color ((ca.r * cb.r) >> 8, (ca.g * cb.g) >> 8, (ca.b * cb.b) >> 8)
+            c2 = Color ((ca.r * cb.r) >> 8, (ca.g * cb.g) >> 8,
+                        (ca.b * cb.b) >> 8)
         
             # Solid, multiply blit.
             
             # Color (2, 5, 0)
             sf2.fill (Color (255, 178, 177))
             ca, cb = sf1.get_at (0, 0), sf2.get_at (0, 0)
-            c2 = Color ((ca.r * cb.r) >> 8, (ca.g * cb.g) >> 8, (ca.b * cb.b) >> 8)
+            c2 = Color ((ca.r * cb.r) >> 8, (ca.g * cb.g) >> 8,
+                        (ca.b * cb.b) >> 8)
             sf1.blit (sf2, blendargs=constants.BLEND_RGB_MULT)
             self._cmpcolor (sf1, sf2, c2, Rect (0, 0, 5, 5))
             self._cmpcolor (sf1, sf2, color1, Rect (5, 5, 5, 5))
             
             # Color (1, 3, 0)
             ca, cb = sf1.get_at (0, 0), sf2.get_at (0, 0)
-            c2 = Color ((ca.r * cb.r) >> 8, (ca.g * cb.g) >> 8, (ca.b * cb.b) >> 8)
+            c2 = Color ((ca.r * cb.r) >> 8, (ca.g * cb.g) >> 8,
+                        (ca.b * cb.b) >> 8)
             sf1.blit (sf2, blendargs=constants.BLEND_RGB_MULT)
             self._cmpcolor (sf1, sf2, c2, Rect (0, 0, 5, 5))
             self._cmpcolor (sf1, sf2, color1, Rect (5, 5, 5, 5))
             # Color (0, 0, 0)
             sf2.fill (Color (0, 0, 0))
             ca, cb = sf1.get_at (0, 0), sf2.get_at (0, 0)
-            c2 = Color ((ca.r * cb.r) >> 8, (ca.g * cb.g) >> 8, (ca.b * cb.b) >> 8)
+            c2 = Color ((ca.r * cb.r) >> 8, (ca.g * cb.g) >> 8,
+                        (ca.b * cb.b) >> 8)
             sf1.blit (sf2, blendargs=constants.BLEND_RGB_MULT)
             self._cmpcolor (sf1, sf2, c2, Rect (0, 0, 5, 5))
             self._cmpcolor (sf1, sf2, color1, Rect (5, 5, 5, 5))
         for bpp in modes:
             sf2 = video.Surface (5, 5, bpp)
             if bpp == 8:
-                sf2.set_palette (get_cga_palette())
+                sf2.set_palette (CGAPALETTE)
         
             sf1.fill (color1)
             sf2.fill (color2)
             ca, cb = sf1.get_at (0, 0), sf2.get_at (0, 0)
-            c2 = Color ((ca.r * cb.r) >> 8, (ca.g * cb.g) >> 8, (ca.b * cb.b) >> 8)
+            c2 = Color ((ca.r * cb.r) >> 8, (ca.g * cb.g) >> 8,
+                        (ca.b * cb.b) >> 8)
         
             # Solid, multiply blit.
             
             # Color (2, 5, 0)
             sf2.fill (Color (255, 178, 177))
             ca, cb = sf1.get_at (0, 0), sf2.get_at (0, 0)
-            c2 = Color ((ca.r * cb.r) >> 8, (ca.g * cb.g) >> 8, (ca.b * cb.b) >> 8)
+            c2 = Color ((ca.r * cb.r) >> 8, (ca.g * cb.g) >> 8,
+                        (ca.b * cb.b) >> 8)
             sf1.blit (sf2, blendargs=constants.BLEND_RGB_MULT)
             self._cmpcolor (sf1, sf2, c2, Rect (0, 0, 5, 5))
             self._cmpcolor (sf1, sf2, color1, Rect (5, 5, 5, 5))
             
             # Color (1, 3, 0)
             ca, cb = sf1.get_at (0, 0), sf2.get_at (0, 0)
-            c2 = Color ((ca.r * cb.r) >> 8, (ca.g * cb.g) >> 8, (ca.b * cb.b) >> 8)
+            c2 = Color ((ca.r * cb.r) >> 8, (ca.g * cb.g) >> 8,
+                        (ca.b * cb.b) >> 8)
             sf1.blit (sf2, blendargs=constants.BLEND_RGB_MULT)
             self._cmpcolor (sf1, sf2, c2, Rect (0, 0, 5, 5))
             self._cmpcolor (sf1, sf2, color1, Rect (5, 5, 5, 5))
             # Color (0, 0, 0)
             sf2.fill (Color (0, 0, 0))
             ca, cb = sf1.get_at (0, 0), sf2.get_at (0, 0)
-            c2 = Color ((ca.r * cb.r) >> 8, (ca.g * cb.g) >> 8, (ca.b * cb.b) >> 8)
+            c2 = Color ((ca.r * cb.r) >> 8, (ca.g * cb.g) >> 8,
+                        (ca.b * cb.b) >> 8)
             sf1.blit (sf2, blendargs=constants.BLEND_RGB_MULT)
             self._cmpcolor (sf1, sf2, c2, Rect (0, 0, 5, 5))
             self._cmpcolor (sf1, sf2, color1, Rect (5, 5, 5, 5))
         color1 = Color (8, 50, 10)
         color2 = Color (127, 44, 12)
         sf1 = video.Surface (10, 10, 8)
-        sf1.set_palette (get_cga_palette())
+        sf1.set_palette (CGAPALETTE)
         for bpp in modes:
             sf2 = video.Surface (5, 5, bpp)
             if bpp == 8:
-                sf2.set_palette (get_cga_palette())
+                sf2.set_palette (CGAPALETTE)
         
             sf1.fill (color1)
             sf2.fill (color2)
             ca, cb = sf1.get_at (0, 0), sf2.get_at (0, 0)
-            c2 = Color ((ca.r * cb.r) >> 8, (ca.g * cb.g) >> 8, (ca.b * cb.b) >> 8)
+            c2 = Color ((ca.r * cb.r) >> 8, (ca.g * cb.g) >> 8,
+                        (ca.b * cb.b) >> 8)
         
             # Solid, multiply blit.
             
             # Color (2, 5, 0)
             sf2.fill (Color (255, 178, 177))
             ca, cb = sf1.get_at (0, 0), sf2.get_at (0, 0)
-            c2 = Color ((ca.r * cb.r) >> 8, (ca.g * cb.g) >> 8, (ca.b * cb.b) >> 8)
+            c2 = Color ((ca.r * cb.r) >> 8, (ca.g * cb.g) >> 8,
+                        (ca.b * cb.b) >> 8)
             sf1.blit (sf2, blendargs=constants.BLEND_RGB_MULT)
             self._cmpcolor (sf1, sf2, c2, Rect (0, 0, 5, 5))
             self._cmpcolor (sf1, sf2, color1, Rect (5, 5, 5, 5))
             
             # Color (1, 3, 0)
             ca, cb = sf1.get_at (0, 0), sf2.get_at (0, 0)
-            c2 = Color ((ca.r * cb.r) >> 8, (ca.g * cb.g) >> 8, (ca.b * cb.b) >> 8)
+            c2 = Color ((ca.r * cb.r) >> 8, (ca.g * cb.g) >> 8,
+                        (ca.b * cb.b) >> 8)
             sf1.blit (sf2, blendargs=constants.BLEND_RGB_MULT)
             self._cmpcolor (sf1, sf2, c2, Rect (0, 0, 5, 5))
             self._cmpcolor (sf1, sf2, color1, Rect (5, 5, 5, 5))
             # Color (0, 0, 0)
             sf2.fill (Color (0, 0, 0))
             ca, cb = sf1.get_at (0, 0), sf2.get_at (0, 0)
-            c2 = Color ((ca.r * cb.r) >> 8, (ca.g * cb.g) >> 8, (ca.b * cb.b) >> 8)
+            c2 = Color ((ca.r * cb.r) >> 8, (ca.g * cb.g) >> 8,
+                        (ca.b * cb.b) >> 8)
             sf1.blit (sf2, blendargs=constants.BLEND_RGB_MULT)
             self._cmpcolor (sf1, sf2, c2, Rect (0, 0, 5, 5))
             self._cmpcolor (sf1, sf2, color1, Rect (5, 5, 5, 5))

test/sdl_video_surface_test.py

     import io as stringio
 
 import pygame2
+from pygame2.colorpalettes import CGAPALETTE
 from pygame2 import Rect, Color
 import pygame2.sdl.video as video
 import pygame2.sdl.image as image
 import pygame2.sdlimage as sdlimage
 import pygame2.sdl.constants as constants
 
-def get_cga_palette ():
-    return [
-        Color ("#000000"), # black
-        Color ("#0000AA"), # blue
-        Color ("#00AA00"), # green
-        Color ("#00AAAA"), # cyan
-        Color ("#AA0000"), # red
-        Color ("#AA00AA"), # magenta
-        Color ("#AA5500"), # brown
-        Color ("#AAAAAA"), # white
-        
-        Color ("#555555"), # gray
-        Color ("#5555FF"), # blue
-        Color ("#55FF55"), # green
-        Color ("#55FFFF"), # cyan
-        Color ("#FF5555"), # red
-        Color ("#FF55FF"), # magenta
-        Color ("#FFFF55"), # yellow
-        Color ("#FFFFFF"), # white
-    ]
-
 class SDLVideoSurfaceTest (unittest.TestCase):
 
     def _cmppixels (self, sf1, sf2):
         for bpp in modes:
             sf = video.Surface (10, 10, bpp)
             if bpp == 8:
-                sf.set_palette (get_cga_palette ())
+                sf.set_palette (CGAPALETTE)
             sfcopy = sf.copy ()
         
             self.assertEqual (sf.size, sfcopy.size)
         for bpp in modes:
             sf = video.Surface (10, 20, bpp)
             if bpp == 8:
-                sf.set_palette (get_cga_palette ())
+                sf.set_palette (CGAPALETTE)
 
             self._cmpcolor (sf, Color ("black"))
             sf.fill (Color ("cyan"))
         for bpp in modes:
             sf = video.Surface (10, 10, bpp)
             if bpp == 8:
-                sf.set_palette (get_cga_palette ())
+                sf.set_palette (CGAPALETTE)
 
             color = Color (100, 50, 20)
             sf.fill (color)
         for bpp in modes:
             sf = video.Surface (10, 10, bpp)
             if bpp == 8:
-                sf.set_palette (get_cga_palette ())
+                sf.set_palette (CGAPALETTE)
             self.assertEqual (sf.get_colorkey (), None)
             sf = video.Surface (10, 10, bpp, flags=constants.SRCCOLORKEY)
             if bpp == 8:
-                sf.set_palette (get_cga_palette ())
+                sf.set_palette (CGAPALETTE)
             self.assertEqual (sf.get_colorkey (), None)
         
             sf = video.Surface (10, 10, bpp)
             if bpp == 8:
-                sf.set_palette (get_cga_palette ())
+                sf.set_palette (CGAPALETTE)
             color = Color (255, 0, 0)
             key = sf.format.get_rgba (color)
             self.assertTrue (sf.set_colorkey (color))
         for bpp in modes:
             sf1 = video.Surface (16, 16, bpp)
             if bpp == 8:
-                sf1.set_palette (get_cga_palette ())
+                sf1.set_palette (CGAPALETTE)
             sf1.fill (pygame2.Color ("red"))
             bufcreat = None
             if sys.version_info[0] >= 3:
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.