bro
This commit is contained in:
1 parent
de41a02749
commit
9af09cebd3
764 files changed
+54218
-78859
No files matched your search
@@ -1,23 +1,25 @@
|
||||
import platform
|
||||
import unittest
|
||||
import platform
|
||||
|
||||
import pygame
|
||||
import pygame.surfarray
|
||||
from numpy import (
|
||||
__version__ as np_version,
|
||||
all as np_all,
|
||||
arange,
|
||||
float32,
|
||||
float64,
|
||||
rint,
|
||||
uint8,
|
||||
uint16,
|
||||
uint32,
|
||||
uint64,
|
||||
zeros,
|
||||
float32,
|
||||
float64,
|
||||
all as alltrue,
|
||||
rint,
|
||||
arange,
|
||||
)
|
||||
|
||||
import pygame
|
||||
from pygame.locals import *
|
||||
|
||||
import pygame.surfarray
|
||||
|
||||
|
||||
IS_PYPY = "PyPy" == platform.python_implementation()
|
||||
|
||||
|
||||
@@ -111,10 +113,10 @@ class SurfarrayModuleTest(unittest.TestCase):
|
||||
|
||||
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] = surf.map_rgb(palette[1]) & 0xFFFFFFFF
|
||||
arr[5:, :6] = surf.map_rgb(palette[2]) & 0xFFFFFFFF
|
||||
arr[:5, 6:] = surf.map_rgb(palette[3]) & 0xFFFFFFFF
|
||||
arr[5:, 6:] = surf.map_rgb(palette[4]) & 0xFFFFFFFF
|
||||
|
||||
def _fill_array3d(self, arr):
|
||||
palette = self.test_palette
|
||||
@@ -233,7 +235,7 @@ class SurfarrayModuleTest(unittest.TestCase):
|
||||
),
|
||||
)
|
||||
else:
|
||||
self.assertTrue(np_all(arr == 255))
|
||||
self.assertTrue(alltrue(arr == 255))
|
||||
|
||||
# No per-pixel alpha when blanket alpha is None.
|
||||
for surf in targets:
|
||||
@@ -241,7 +243,7 @@ class SurfarrayModuleTest(unittest.TestCase):
|
||||
surf.set_alpha(None)
|
||||
arr = pygame.surfarray.array_alpha(surf)
|
||||
self.assertTrue(
|
||||
np_all(arr == 255),
|
||||
alltrue(arr == 255),
|
||||
"All alpha values should be 255 when"
|
||||
" surf.set_alpha(None) has been set."
|
||||
" bitsize: %i, flags: %i" % (surf.get_bitsize(), surf.get_flags()),
|
||||
@@ -255,12 +257,12 @@ class SurfarrayModuleTest(unittest.TestCase):
|
||||
arr = pygame.surfarray.array_alpha(surf)
|
||||
if surf.get_masks()[3]:
|
||||
self.assertFalse(
|
||||
np_all(arr == 255),
|
||||
alltrue(arr == 255),
|
||||
"bitsize: %i, flags: %i" % (surf.get_bitsize(), surf.get_flags()),
|
||||
)
|
||||
else:
|
||||
self.assertTrue(
|
||||
np_all(arr == 255),
|
||||
alltrue(arr == 255),
|
||||
"bitsize: %i, flags: %i" % (surf.get_bitsize(), surf.get_flags()),
|
||||
)
|
||||
surf.set_alpha(blanket_alpha)
|
||||
@@ -288,7 +290,7 @@ class SurfarrayModuleTest(unittest.TestCase):
|
||||
p = [surf.unmap_rgb(surf.map_rgb(c)) for c in p]
|
||||
surf.set_colorkey(None)
|
||||
arr = pygame.surfarray.array_colorkey(surf)
|
||||
self.assertTrue(np_all(arr == 255))
|
||||
self.assertTrue(alltrue(arr == 255))
|
||||
|
||||
for i in range(1, len(palette)):
|
||||
surf.set_colorkey(p[i])
|
||||
@@ -469,34 +471,39 @@ class SurfarrayModuleTest(unittest.TestCase):
|
||||
arr.shape = (1, 1, 1, 4)
|
||||
self.assertRaises(ValueError, do_blit, surf, arr)
|
||||
|
||||
# pygame-ce issue #96: round from float to int
|
||||
surf = pygame.Surface((10, 10), pygame.SRCALPHA, 32)
|
||||
w, h = surf.get_size()
|
||||
length = w * h
|
||||
for dtype in [float32, float64]:
|
||||
surf.fill((255, 255, 255, 0))
|
||||
farr = arange(0, length, dtype=dtype)
|
||||
farr.shape = w, h
|
||||
pygame.surfarray.blit_array(surf, farr)
|
||||
for x in range(w):
|
||||
for y in range(h):
|
||||
self.assertEqual(surf.get_at_mapped((x, y)), int(rint(farr[x, y])))
|
||||
# Issue #81: round from float to int
|
||||
try:
|
||||
rint
|
||||
except NameError:
|
||||
pass
|
||||
else:
|
||||
surf = pygame.Surface((10, 10), pygame.SRCALPHA, 32)
|
||||
w, h = surf.get_size()
|
||||
length = w * h
|
||||
for dtype in [float32, float64]:
|
||||
surf.fill((255, 255, 255, 0))
|
||||
farr = arange(0, length, dtype=dtype)
|
||||
farr.shape = w, h
|
||||
pygame.surfarray.blit_array(surf, farr)
|
||||
for x in range(w):
|
||||
for y in range(h):
|
||||
self.assertEqual(
|
||||
surf.get_at_mapped((x, y)), int(rint(farr[x, y]))
|
||||
)
|
||||
|
||||
# this test should be removed soon, when the function is deleted
|
||||
def test_get_arraytype(self):
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
array_type = pygame.surfarray.get_arraytype()
|
||||
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):
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
arraytypes = pygame.surfarray.get_arraytypes()
|
||||
self.assertIn("numpy", arraytypes)
|
||||
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
|
||||
@@ -513,17 +520,24 @@ class SurfarrayModuleTest(unittest.TestCase):
|
||||
surf = pygame.surfarray.make_surface(self._make_src_array3d(dtype))
|
||||
self._assert_surface(surf)
|
||||
|
||||
# pygame-ce issue #96: round from float to int
|
||||
w = 9
|
||||
h = 11
|
||||
length = w * h
|
||||
for dtype in [float32, float64]:
|
||||
farr = arange(0, length, dtype=dtype)
|
||||
farr.shape = w, h
|
||||
surf = pygame.surfarray.make_surface(farr)
|
||||
for x in range(w):
|
||||
for y in range(h):
|
||||
self.assertEqual(surf.get_at_mapped((x, y)), int(rint(farr[x, y])))
|
||||
# Issue #81: round from float to int
|
||||
try:
|
||||
rint
|
||||
except NameError:
|
||||
pass
|
||||
else:
|
||||
w = 9
|
||||
h = 11
|
||||
length = w * h
|
||||
for dtype in [float32, float64]:
|
||||
farr = arange(0, length, dtype=dtype)
|
||||
farr.shape = w, h
|
||||
surf = pygame.surfarray.make_surface(farr)
|
||||
for x in range(w):
|
||||
for y in range(h):
|
||||
self.assertEqual(
|
||||
surf.get_at_mapped((x, y)), int(rint(farr[x, y]))
|
||||
)
|
||||
|
||||
def test_map_array(self):
|
||||
arr3d = self._make_src_array3d(uint8)
|
||||
@@ -560,11 +574,6 @@ class SurfarrayModuleTest(unittest.TestCase):
|
||||
self._make_array2d(uint8),
|
||||
)
|
||||
|
||||
@unittest.skipIf(
|
||||
int(np_version.split(".")[0]) >= 2,
|
||||
"This test fails due to a change in numpy 2.0.0, and a 'proper fix' "
|
||||
"requires an API/behaviour change",
|
||||
)
|
||||
def test_pixels2d(self):
|
||||
sources = [
|
||||
self._make_surface(8),
|
||||
@@ -710,23 +719,24 @@ class SurfarrayModuleTest(unittest.TestCase):
|
||||
def do_use_arraytype(atype):
|
||||
pygame.surfarray.use_arraytype(atype)
|
||||
|
||||
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")
|
||||
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__":
|
||||
|
||||
Reference in new issue
Block a user