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

Remove HAVE_NEWBUF checks in tests #2640

Merged
merged 3 commits into from
Dec 30, 2023
Merged
Show file tree
Hide file tree
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
6 changes: 0 additions & 6 deletions src_c/_pygame.h
Original file line number Diff line number Diff line change
Expand Up @@ -349,12 +349,6 @@ typedef enum {
PGS_PREALLOC = 0x01000000
} PygameSurfaceFlags;

// TODO Implement check below in a way that does not break CI
/* New buffer protocol (PEP 3118) implemented on all supported Py versions.
#if !defined(Py_TPFLAGS_HAVE_NEWBUFFER)
#error No support for PEP 3118/Py_TPFLAGS_HAVE_NEWBUFFER. Please use a
supported Python version. #endif */

#define RAISE(x, y) (PyErr_SetString((x), (y)), NULL)
#define RAISERETURN(x, y, r) \
PyErr_SetString((x), (y)); \
Expand Down
3 changes: 1 addition & 2 deletions src_c/mixer.c
Original file line number Diff line number Diff line change
Expand Up @@ -1005,8 +1005,7 @@ static PyTypeObject pgSound_Type = {
.tp_basicsize = sizeof(pgSoundObject),
.tp_dealloc = (destructor)sound_dealloc,
.tp_as_buffer = sound_as_buffer,
.tp_flags =
(Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_NEWBUFFER),
.tp_flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE),
.tp_doc = DOC_MIXER_SOUND,
.tp_weaklistoffset = offsetof(pgSoundObject, weakreflist),
.tp_methods = sound_methods,
Expand Down
4 changes: 0 additions & 4 deletions src_c/pgcompat.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,4 @@

#define RELATIVE_MODULE(m) ("." m)

#ifndef Py_TPFLAGS_HAVE_NEWBUFFER
#define Py_TPFLAGS_HAVE_NEWBUFFER 0
#endif

#endif /* ~PGCOMPAT_INTERNAL_H */
8 changes: 2 additions & 6 deletions test/base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,7 @@ def get__array_struct__(self):
o = Exporter(shape, typechar, itemsize)
self.assertEqual(getrefcount(o.__array_struct__), 1)

if pygame.HAVE_NEWBUF:
from pygame.tests.test_utils import buftools
from pygame.tests.test_utils import buftools

def NEWBUF_assertSame(self, proxy, exp):
buftools = self.buftools
Expand All @@ -209,7 +208,6 @@ def NEWBUF_assertSame(self, proxy, exp):
self.assertEqual(imp.strides, exp.strides)
self.assertTrue(imp.suboffsets is None)

@unittest.skipIf(not pygame.HAVE_NEWBUF, "newbuf not implemented")
@unittest.skipIf(IS_PYPY, "pypy no likey")
def test_newbuf(self):
from pygame.bufferproxy import BufferProxy
Expand Down Expand Up @@ -250,7 +248,6 @@ def test_newbuf(self):
v = BufferProxy(o)
self.NEWBUF_assertSame(v, o)

@unittest.skipIf(not pygame.HAVE_NEWBUF, "newbuf not implemented")
def test_bad_format(self):
from pygame.bufferproxy import BufferProxy
from pygame.newbuffer import BufferMixin
Expand Down Expand Up @@ -280,7 +277,6 @@ def test_bad_format(self):
b = BufferProxy(exp)
self.assertRaises(ValueError, Importer, b, PyBUF_FORMAT)

@unittest.skipIf(not pygame.HAVE_NEWBUF, "newbuf not implemented")
@unittest.skipIf(IS_PYPY, "fails on pypy")
def test_PgDict_AsBuffer_PyBUF_flags(self):
from pygame.bufferproxy import BufferProxy
Expand Down Expand Up @@ -382,7 +378,7 @@ def test_PgDict_AsBuffer_PyBUF_flags(self):
self.assertEqual(b.buf, 1000000)
self.assertRaises(BufferError, Importer, a, buftools.PyBUF_FULL)

@unittest.skipIf(IS_PYPY or (not pygame.HAVE_NEWBUF), "newbuf with ctypes")
@unittest.skipIf(IS_PYPY, "newbuf with ctypes")
def test_PgObject_AsBuffer_PyBUF_flags(self):
from pygame.bufferproxy import BufferProxy
import ctypes
Expand Down
1 change: 0 additions & 1 deletion test/bufferproxy_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,6 @@ def __repr__(self):
self.assertEqual(r[:2], "*<")
self.assertEqual(r[-2:], ">*")

@unittest.skipIf(not pygame.HAVE_NEWBUF, "newbuf not implemented")
def NEWBUF_test_newbuf(self):
from ctypes import string_at

Expand Down
1 change: 0 additions & 1 deletion test/color_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1088,7 +1088,6 @@ def test_arraystruct(self):
for j in range(i):
self.assertEqual(data[j], c[j])

@unittest.skipIf(not pygame.HAVE_NEWBUF, "newbuf not implemented")
def test_newbuf(self):
from pygame.tests.test_utils import buftools
from ctypes import cast, POINTER, c_uint8
Expand Down
1 change: 0 additions & 1 deletion test/freetype_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1246,7 +1246,6 @@ def test_freetype_Font_bgcolor(self):

self.assertRaises(AttributeError, setattr, f, "bgcolor", None)

@unittest.skipIf(not pygame.HAVE_NEWBUF, "newbuf not implemented")
@unittest.skipIf(IS_PYPY, "pypy no likey")
def test_newbuf(self):
from pygame.tests.test_utils import buftools
Expand Down
2 changes: 0 additions & 2 deletions test/mixer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,13 +359,11 @@ def test_array_interface(self):
self.assertEqual(d["strides"], (2,))
self.assertEqual(d["data"], (snd._samples_address, False))

@unittest.skipIf(not pygame.HAVE_NEWBUF, "newbuf not implemented")
@unittest.skipIf(IS_PYPY, "pypy no likey")
def test_newbuf__one_channel(self):
mixer.init(22050, -16, 1)
self._NEWBUF_export_check()

@unittest.skipIf(not pygame.HAVE_NEWBUF, "newbuf not implemented")
@unittest.skipIf(IS_PYPY, "pypy no likey")
def test_newbuf__twho_channel(self):
mixer.init(22050, -16, 2)
Expand Down
4 changes: 1 addition & 3 deletions test/pixelarray_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1450,11 +1450,9 @@ def test_slicing(self):
self.assert_surfaces_equal(sf3, sf2)


@unittest.skipIf(not pygame.HAVE_NEWBUF, "newbuf not implemented")
@unittest.skipIf(IS_PYPY, "pypy having issues")
class PixelArrayNewBufferTest(unittest.TestCase, TestMixin):
if pygame.HAVE_NEWBUF:
from pygame.tests.test_utils import buftools
from pygame.tests.test_utils import buftools

bitsize_to_format = {8: "B", 16: "=H", 24: "3x", 32: "=I"}

Expand Down
68 changes: 33 additions & 35 deletions test/pixelcopy_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,43 +593,41 @@ def test_map_array(self):
del numpy


@unittest.skipIf(not pygame.HAVE_NEWBUF, "newbuf not implemented")
@unittest.skipIf(IS_PYPY, "pypy having illegal instruction on mac")
class PixelCopyTestWithArrayNewBuf(unittest.TestCase):
if pygame.HAVE_NEWBUF:
from pygame.tests.test_utils import buftools

class Array2D(buftools.Exporter):
def __init__(self, initializer):
from ctypes import cast, POINTER, c_uint32

Array2D = PixelCopyTestWithArrayNewBuf.Array2D
super().__init__((3, 5), format="=I", strides=(20, 4))
self.content = cast(self.buf, POINTER(c_uint32))
for i, v in enumerate(initializer):
self.content[i] = v

def __getitem__(self, key):
byte_index = key[0] * 5 + key[1]
if not (0 <= byte_index < 15):
raise IndexError("%s is out of range", key)
return self.content[byte_index]

class Array3D(buftools.Exporter):
def __init__(self, initializer):
from ctypes import cast, POINTER, c_uint8

Array3D = PixelCopyTestWithArrayNewBuf.Array3D
super().__init__((3, 5, 3), format="B", strides=(20, 4, 1))
self.content = cast(self.buf, POINTER(c_uint8))
for i, v in enumerate(initializer):
self.content[i] = v

def __getitem__(self, key):
byte_index = key[0] * 20 + key[1] * 4 + key[2]
if not (0 <= byte_index < 60):
raise IndexError("%s is out of range", key)
return self.content[byte_index]
from pygame.tests.test_utils import buftools

class Array2D(buftools.Exporter):
def __init__(self, initializer):
from ctypes import cast, POINTER, c_uint32

Array2D = PixelCopyTestWithArrayNewBuf.Array2D
super().__init__((3, 5), format="=I", strides=(20, 4))
self.content = cast(self.buf, POINTER(c_uint32))
for i, v in enumerate(initializer):
self.content[i] = v

def __getitem__(self, key):
byte_index = key[0] * 5 + key[1]
if not (0 <= byte_index < 15):
raise IndexError("%s is out of range", key)
return self.content[byte_index]

class Array3D(buftools.Exporter):
def __init__(self, initializer):
from ctypes import cast, POINTER, c_uint8

Array3D = PixelCopyTestWithArrayNewBuf.Array3D
super().__init__((3, 5, 3), format="B", strides=(20, 4, 1))
self.content = cast(self.buf, POINTER(c_uint8))
for i, v in enumerate(initializer):
self.content[i] = v

def __getitem__(self, key):
byte_index = key[0] * 20 + key[1] * 4 + key[2]
if not (0 <= byte_index < 60):
raise IndexError("%s is out of range", key)
return self.content[byte_index]

surface = pygame.Surface((3, 5), 0, 32)

Expand Down
6 changes: 0 additions & 6 deletions test/surface_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3001,7 +3001,6 @@ def test_array_interface_rgb(self):
s = pygame.Surface((4, 2), 0, 32)
self._check_interface_rgba(s, plane)

@unittest.skipIf(not pygame.HAVE_NEWBUF, "newbuf not implemented")
def test_newbuf_PyBUF_flags_bytes(self):
from pygame.tests.test_utils import buftools

Expand Down Expand Up @@ -3061,7 +3060,6 @@ def test_newbuf_PyBUF_flags_bytes(self):
self.assertEqual(b.ndim, 1)
self.assertEqual(b.strides, (1,))

@unittest.skipIf(not pygame.HAVE_NEWBUF, "newbuf not implemented")
def test_newbuf_PyBUF_flags_0D(self):
# This is the same handler as used by get_buffer(), so just
# confirm that it succeeds for one case.
Expand All @@ -3081,7 +3079,6 @@ def test_newbuf_PyBUF_flags_0D(self):
self.assertFalse(b.readonly)
self.assertEqual(b.buf, s._pixels_address)

@unittest.skipIf(not pygame.HAVE_NEWBUF, "newbuf not implemented")
def test_newbuf_PyBUF_flags_1D(self):
from pygame.tests.test_utils import buftools

Expand Down Expand Up @@ -3120,7 +3117,6 @@ def test_newbuf_PyBUF_flags_1D(self):
self.assertTrue(b.format is None)
self.assertEqual(b.strides, (s.get_bytesize(),))

@unittest.skipIf(not pygame.HAVE_NEWBUF, "newbuf not implemented")
def test_newbuf_PyBUF_flags_2D(self):
from pygame.tests.test_utils import buftools

Expand Down Expand Up @@ -3191,7 +3187,6 @@ def test_newbuf_PyBUF_flags_2D(self):
self.assertRaises(BufferError, Importer, a, buftools.PyBUF_F_CONTIGUOUS)
self.assertRaises(BufferError, Importer, a, buftools.PyBUF_ANY_CONTIGUOUS)

@unittest.skipIf(not pygame.HAVE_NEWBUF, "newbuf not implemented")
def test_newbuf_PyBUF_flags_3D(self):
from pygame.tests.test_utils import buftools

Expand Down Expand Up @@ -3242,7 +3237,6 @@ def test_newbuf_PyBUF_flags_3D(self):
self.assertRaises(BufferError, Importer, a, buftools.PyBUF_F_CONTIGUOUS)
self.assertRaises(BufferError, Importer, a, buftools.PyBUF_ANY_CONTIGUOUS)

@unittest.skipIf(not pygame.HAVE_NEWBUF, "newbuf not implemented")
def test_newbuf_PyBUF_flags_rgba(self):
# All color plane views are handled by the same routine,
# so only one plane need be checked.
Expand Down
3 changes: 0 additions & 3 deletions test/test_utils/buftools.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
"""
import pygame

if not pygame.HAVE_NEWBUF:
emsg = "This Pygame build does not support the new buffer protocol"
raise ImportError(emsg)
import pygame.newbuffer
from pygame.newbuffer import (
PyBUF_SIMPLE,
Expand Down
Loading