Skip to content

Commit

Permalink
Merge pull request #1881 from khuang0312/master
Browse files Browse the repository at this point in the history
Added unit test for surface.get_colorkey(). Closes #1801
  • Loading branch information
illume committed Jun 3, 2020
2 parents 108d07f + a258989 commit 0e7b35b
Showing 1 changed file with 39 additions and 8 deletions.
47 changes: 39 additions & 8 deletions test/surface_test.py
Expand Up @@ -1000,14 +1000,45 @@ def test_get_clip(self):
rectangle = s.get_clip()
self.assertEqual(rectangle, (0, 0, 800, 600))

def todo_test_get_colorkey(self):
surf = pygame.surface((2, 2), 0, 24)
self.assertIsNone(surf.get_colorykey())
colorkey = pygame.Color(20, 40, 60)
surf.set_colorkey(colorkey)
ck = surf.get_colorkey()
self.assertIsInstance(ck, pygame.Color)
self.assertEqual(ck, colorkey)
def test_get_colorkey(self):
# if set_colorkey is not used
s = pygame.Surface((800, 600))
self.assertIsNone(s.get_colorkey())

# if set_colorkey is used
s.set_colorkey(None)
self.assertIsNone(s.get_colorkey())

# setting up remainder of tests...
r, g, b, a = 20, 40, 60, 12
colorkey = pygame.Color(r, g, b)
s.set_colorkey(colorkey)

#test for ideal case
self.assertEqual(s.get_colorkey(), (r, g, b, 255))

#test for if the color_key is set using pygame.RLEACCEL
s.set_colorkey(colorkey, pygame.RLEACCEL)
self.assertEqual(s.get_colorkey(), (r, g, b, 255))

#test for if the color key is not what's expected
s.set_colorkey(pygame.Color(r + 1, g + 1, b + 1))
self.assertNotEqual(s.get_colorkey(), (r, g, b, 255))

s.set_colorkey(pygame.Color(r, g, b, a)) # regardless of whether alpha is not 255, colorkey returned from surface is always 255
self.assertEqual(s.get_colorkey(), (r, g, b, 255))

# test for using method after display.quit() is called...
with self.assertRaises(pygame.error):
s = pygame.display.set_mode()
pygame.display.quit()
s.get_colorkey()

# test for using method when display is created with OpenGL and the SDL version is 1
if SDL1: # SLD1 is a bool defined at the top...
with self.assertRaises(pygame.error):
s = pygame.display.set_mode(flags=pygame.OPENGL)
s.get_colorkey()

def test_get_height(self):
sizes = ((1, 1), (119, 10), (10, 119), (1, 1000), (1000, 1), (1000, 1000))
Expand Down

0 comments on commit 0e7b35b

Please sign in to comment.