Skip to content

Commit 63ae32c

Browse files
committed
Fix the Deprecation Warnings in surfarray_test
1 parent a8c2997 commit 63ae32c

File tree

1 file changed

+24
-22
lines changed

1 file changed

+24
-22
lines changed

test/surfarray_test.py

Lines changed: 24 additions & 22 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
@@ -114,10 +115,10 @@ def _make_array3d(self, dtype):
114115

115116
def _fill_array2d(self, arr, surf):
116117
palette = self.test_palette
117-
arr[:5, :6] = surf.map_rgb(palette[1])
118-
arr[5:, :6] = surf.map_rgb(palette[2])
119-
arr[:5, 6:] = surf.map_rgb(palette[3])
120-
arr[5:, 6:] = surf.map_rgb(palette[4])
118+
arr[:5, :6] = array(surf.map_rgb(palette[1])).astype(int)
119+
arr[5:, :6] = array(surf.map_rgb(palette[2])).astype(int)
120+
arr[:5, 6:] = array(surf.map_rgb(palette[3])).astype(int)
121+
arr[5:, 6:] = array(surf.map_rgb(palette[4])).astype(int)
121122

122123
def _fill_array3d(self, arr):
123124
palette = self.test_palette
@@ -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)