Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix *most of* the Deprecation Warnings in surfarray_test #3274

Merged
merged 3 commits into from
Dec 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading