Skip to content

Commit

Permalink
Merge pull request #1827 from kduggan15/mustlock_test
Browse files Browse the repository at this point in the history
Adds test for surface.mustlock()
  • Loading branch information
illume committed May 23, 2020
2 parents acfe29b + bd951e6 commit 51c55d5
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions test/surface_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1210,25 +1210,27 @@ def test_map_rgb(self):
surf.set_at((0, 0), c)
self.assertEqual(surf.get_at((0, 0)), color)

def todo_test_mustlock(self):

# __doc__ (as of 2008-08-02) for pygame.surface.Surface.mustlock:

# Surface.mustlock(): return bool
# test if the Surface requires locking
#
# Returns True if the Surface is required to be locked to access pixel
# data. Usually pure software Surfaces do not require locking. This
# method is rarely needed, since it is safe and quickest to just lock
# all Surfaces as needed.
#
# All pygame functions will automatically lock and unlock the Surface
# data as needed. If a section of code is going to make calls that
# will repeatedly lock and unlock the Surface many times, it can be
# helpful to wrap the block inside a lock and unlock pair.
#

self.fail()
def test_mustlock(self):
#Test that subsurfaces mustlock
surf = pygame.Surface((1024,1024))
subsurf=surf.subsurface((0,0,1024,1024))
self.assertTrue(subsurf.mustlock())
self.assertFalse(surf.mustlock())
#Tests nested subsurfaces
rects = ((0,0,512,512),(0,0,256,256),(0,0,128,128))
surf_stack = []
surf_stack.append(surf)
surf_stack.append(subsurf)
for rect in rects:
surf_stack.append(surf_stack[-1].subsurface(rect))
self.assertTrue(surf_stack[-1].mustlock())
self.assertTrue(surf_stack[-2].mustlock())
#Test RLEACCEL flag in set_colorkey
surf = pygame.Surface((100,100))
blit_surf = pygame.Surface((100,100))
blit_surf.set_colorkey((0,0,255), RLEACCEL)
surf.blit(blit_surf,(0,0))
self.assertEqual(blit_surf.mustlock(),(blit_surf.get_flags() & pygame.RLEACCEL) !=0)

def test_set_alpha_none(self):
"""surf.set_alpha(None) disables blending"""
Expand Down

0 comments on commit 51c55d5

Please sign in to comment.