Skip to content

Commit

Permalink
Merge pull request #3274 from pygame-community/remove-deprecated-surf…
Browse files Browse the repository at this point in the history
…array-funcs-from-tests

Fix *most of* the Deprecation Warnings in surfarray_test
  • Loading branch information
ankith26 authored Dec 31, 2024
2 parents 1b89e60 + d0b8e73 commit c4eba16
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions test/surfarray_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
rint,
arange,
__version__ as np_version,
array,
)

import pygame
Expand Down Expand Up @@ -487,17 +488,19 @@ def do_blit(surf, arr):

# this test should be removed soon, when the function is deleted
def test_get_arraytype(self):
array_type = pygame.surfarray.get_arraytype()
with self.assertWarns(DeprecationWarning):
array_type = pygame.surfarray.get_arraytype()

self.assertEqual(array_type, "numpy", f"unknown array type {array_type}")
self.assertEqual(array_type, "numpy", f"unknown array type {array_type}")

# this test should be removed soon, when the function is deleted
def test_get_arraytypes(self):
arraytypes = pygame.surfarray.get_arraytypes()
self.assertIn("numpy", arraytypes)
with self.assertWarns(DeprecationWarning):
arraytypes = pygame.surfarray.get_arraytypes()
self.assertIn("numpy", arraytypes)

for atype in arraytypes:
self.assertEqual(atype, "numpy", f"unknown array type {atype}")
for atype in arraytypes:
self.assertEqual(atype, "numpy", f"unknown array type {atype}")

def test_make_surface(self):
# How does one properly test this with 2d arrays. It makes no sense
Expand Down Expand Up @@ -711,24 +714,23 @@ def test_use_arraytype(self):
def do_use_arraytype(atype):
pygame.surfarray.use_arraytype(atype)

pygame.surfarray.use_arraytype("numpy")
self.assertEqual(pygame.surfarray.get_arraytype(), "numpy")
self.assertRaises(ValueError, do_use_arraytype, "not an option")
with self.assertWarns(DeprecationWarning):
pygame.surfarray.use_arraytype("numpy")
self.assertEqual(pygame.surfarray.get_arraytype(), "numpy")
self.assertRaises(ValueError, do_use_arraytype, "not an option")

def test_surf_lock(self):
sf = pygame.Surface((5, 5), 0, 32)
for atype in pygame.surfarray.get_arraytypes():
pygame.surfarray.use_arraytype(atype)

ar = pygame.surfarray.pixels2d(sf)
self.assertTrue(sf.get_locked())
ar = pygame.surfarray.pixels2d(sf)
self.assertTrue(sf.get_locked())

sf.unlock()
self.assertTrue(sf.get_locked())
sf.unlock()
self.assertTrue(sf.get_locked())

del ar
self.assertFalse(sf.get_locked())
self.assertEqual(sf.get_locks(), ())
del ar
self.assertFalse(sf.get_locked())
self.assertEqual(sf.get_locks(), ())


if __name__ == "__main__":
Expand Down

0 comments on commit c4eba16

Please sign in to comment.