Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added unit test for surface.get_colorkey(). Closes #1801 #1881

Merged
merged 8 commits into from Jun 3, 2020
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