Skip to content

Commit c4eba16

Browse files
authored
Merge pull request #3274 from pygame-community/remove-deprecated-surfarray-funcs-from-tests
Fix *most of* the Deprecation Warnings in surfarray_test
2 parents 1b89e60 + d0b8e73 commit c4eba16

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

test/surfarray_test.py

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
rint,
1414
arange,
1515
__version__ as np_version,
16+
array,
1617
)
1718

1819
import pygame
@@ -487,17 +488,19 @@ def do_blit(surf, arr):
487488

488489
# this test should be removed soon, when the function is deleted
489490
def test_get_arraytype(self):
490-
array_type = pygame.surfarray.get_arraytype()
491+
with self.assertWarns(DeprecationWarning):
492+
array_type = pygame.surfarray.get_arraytype()
491493

492-
self.assertEqual(array_type, "numpy", f"unknown array type {array_type}")
494+
self.assertEqual(array_type, "numpy", f"unknown array type {array_type}")
493495

494496
# this test should be removed soon, when the function is deleted
495497
def test_get_arraytypes(self):
496-
arraytypes = pygame.surfarray.get_arraytypes()
497-
self.assertIn("numpy", arraytypes)
498+
with self.assertWarns(DeprecationWarning):
499+
arraytypes = pygame.surfarray.get_arraytypes()
500+
self.assertIn("numpy", arraytypes)
498501

499-
for atype in arraytypes:
500-
self.assertEqual(atype, "numpy", f"unknown array type {atype}")
502+
for atype in arraytypes:
503+
self.assertEqual(atype, "numpy", f"unknown array type {atype}")
501504

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

714-
pygame.surfarray.use_arraytype("numpy")
715-
self.assertEqual(pygame.surfarray.get_arraytype(), "numpy")
716-
self.assertRaises(ValueError, do_use_arraytype, "not an option")
717+
with self.assertWarns(DeprecationWarning):
718+
pygame.surfarray.use_arraytype("numpy")
719+
self.assertEqual(pygame.surfarray.get_arraytype(), "numpy")
720+
self.assertRaises(ValueError, do_use_arraytype, "not an option")
717721

718722
def test_surf_lock(self):
719723
sf = pygame.Surface((5, 5), 0, 32)
720-
for atype in pygame.surfarray.get_arraytypes():
721-
pygame.surfarray.use_arraytype(atype)
722724

723-
ar = pygame.surfarray.pixels2d(sf)
724-
self.assertTrue(sf.get_locked())
725+
ar = pygame.surfarray.pixels2d(sf)
726+
self.assertTrue(sf.get_locked())
725727

726-
sf.unlock()
727-
self.assertTrue(sf.get_locked())
728+
sf.unlock()
729+
self.assertTrue(sf.get_locked())
728730

729-
del ar
730-
self.assertFalse(sf.get_locked())
731-
self.assertEqual(sf.get_locks(), ())
731+
del ar
732+
self.assertFalse(sf.get_locked())
733+
self.assertEqual(sf.get_locks(), ())
732734

733735

734736
if __name__ == "__main__":

0 commit comments

Comments
 (0)