From 63ae32cefa5e903254f0ea29a2ccbf7c510e5ae8 Mon Sep 17 00:00:00 2001 From: Dan Lawrence Date: Mon, 30 Dec 2024 15:41:15 +0000 Subject: [PATCH 1/3] Fix the Deprecation Warnings in surfarray_test --- test/surfarray_test.py | 46 ++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/test/surfarray_test.py b/test/surfarray_test.py index 2288f9b862..947bb3a677 100644 --- a/test/surfarray_test.py +++ b/test/surfarray_test.py @@ -13,6 +13,7 @@ rint, arange, __version__ as np_version, + array ) import pygame @@ -114,10 +115,10 @@ def _make_array3d(self, dtype): def _fill_array2d(self, arr, surf): palette = self.test_palette - arr[:5, :6] = surf.map_rgb(palette[1]) - arr[5:, :6] = surf.map_rgb(palette[2]) - arr[:5, 6:] = surf.map_rgb(palette[3]) - arr[5:, 6:] = surf.map_rgb(palette[4]) + arr[:5, :6] = array(surf.map_rgb(palette[1])).astype(int) + arr[5:, :6] = array(surf.map_rgb(palette[2])).astype(int) + arr[:5, 6:] = array(surf.map_rgb(palette[3])).astype(int) + arr[5:, 6:] = array(surf.map_rgb(palette[4])).astype(int) def _fill_array3d(self, arr): palette = self.test_palette @@ -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 @@ -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__": From e8f79d1647c1f1dcb50df6f5b3424ff153d6c3f1 Mon Sep 17 00:00:00 2001 From: Dan Lawrence Date: Mon, 30 Dec 2024 15:42:30 +0000 Subject: [PATCH 2/3] formatting --- test/surfarray_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/surfarray_test.py b/test/surfarray_test.py index 947bb3a677..45bce35912 100644 --- a/test/surfarray_test.py +++ b/test/surfarray_test.py @@ -13,7 +13,7 @@ rint, arange, __version__ as np_version, - array + array, ) import pygame From d0b8e73abc2dad51e869d4826700bcfbffaca0d9 Mon Sep 17 00:00:00 2001 From: Dan Lawrence Date: Tue, 31 Dec 2024 09:02:48 +0000 Subject: [PATCH 3/3] Revert numpy array().astype(int) fix Ankith believes we can fix this better in the library code. --- test/surfarray_test.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/surfarray_test.py b/test/surfarray_test.py index 45bce35912..bfcf8f15fe 100644 --- a/test/surfarray_test.py +++ b/test/surfarray_test.py @@ -115,10 +115,10 @@ def _make_array3d(self, dtype): def _fill_array2d(self, arr, surf): palette = self.test_palette - arr[:5, :6] = array(surf.map_rgb(palette[1])).astype(int) - arr[5:, :6] = array(surf.map_rgb(palette[2])).astype(int) - arr[:5, 6:] = array(surf.map_rgb(palette[3])).astype(int) - arr[5:, 6:] = array(surf.map_rgb(palette[4])).astype(int) + arr[:5, :6] = surf.map_rgb(palette[1]) + arr[5:, :6] = surf.map_rgb(palette[2]) + arr[:5, 6:] = surf.map_rgb(palette[3]) + arr[5:, 6:] = surf.map_rgb(palette[4]) def _fill_array3d(self, arr): palette = self.test_palette