Skip to content

Commit f42f761

Browse files
authored
Merge pull request #2640 from pygame-community/ankith26-newbuf-check
Remove `HAVE_NEWBUF` checks in tests
2 parents 8666e9d + 1adc18a commit f42f761

File tree

12 files changed

+37
-70
lines changed

12 files changed

+37
-70
lines changed

src_c/_pygame.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -349,12 +349,6 @@ typedef enum {
349349
PGS_PREALLOC = 0x01000000
350350
} PygameSurfaceFlags;
351351

352-
// TODO Implement check below in a way that does not break CI
353-
/* New buffer protocol (PEP 3118) implemented on all supported Py versions.
354-
#if !defined(Py_TPFLAGS_HAVE_NEWBUFFER)
355-
#error No support for PEP 3118/Py_TPFLAGS_HAVE_NEWBUFFER. Please use a
356-
supported Python version. #endif */
357-
358352
#define RAISE(x, y) (PyErr_SetString((x), (y)), NULL)
359353
#define RAISERETURN(x, y, r) \
360354
PyErr_SetString((x), (y)); \

src_c/mixer.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,8 +1005,7 @@ static PyTypeObject pgSound_Type = {
10051005
.tp_basicsize = sizeof(pgSoundObject),
10061006
.tp_dealloc = (destructor)sound_dealloc,
10071007
.tp_as_buffer = sound_as_buffer,
1008-
.tp_flags =
1009-
(Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_NEWBUFFER),
1008+
.tp_flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE),
10101009
.tp_doc = DOC_MIXER_SOUND,
10111010
.tp_weaklistoffset = offsetof(pgSoundObject, weakreflist),
10121011
.tp_methods = sound_methods,

src_c/pgcompat.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,4 @@
1717

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

20-
#ifndef Py_TPFLAGS_HAVE_NEWBUFFER
21-
#define Py_TPFLAGS_HAVE_NEWBUFFER 0
22-
#endif
23-
2420
#endif /* ~PGCOMPAT_INTERNAL_H */

test/base_test.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,7 @@ def get__array_struct__(self):
193193
o = Exporter(shape, typechar, itemsize)
194194
self.assertEqual(getrefcount(o.__array_struct__), 1)
195195

196-
if pygame.HAVE_NEWBUF:
197-
from pygame.tests.test_utils import buftools
196+
from pygame.tests.test_utils import buftools
198197

199198
def NEWBUF_assertSame(self, proxy, exp):
200199
buftools = self.buftools
@@ -209,7 +208,6 @@ def NEWBUF_assertSame(self, proxy, exp):
209208
self.assertEqual(imp.strides, exp.strides)
210209
self.assertTrue(imp.suboffsets is None)
211210

212-
@unittest.skipIf(not pygame.HAVE_NEWBUF, "newbuf not implemented")
213211
@unittest.skipIf(IS_PYPY, "pypy no likey")
214212
def test_newbuf(self):
215213
from pygame.bufferproxy import BufferProxy
@@ -250,7 +248,6 @@ def test_newbuf(self):
250248
v = BufferProxy(o)
251249
self.NEWBUF_assertSame(v, o)
252250

253-
@unittest.skipIf(not pygame.HAVE_NEWBUF, "newbuf not implemented")
254251
def test_bad_format(self):
255252
from pygame.bufferproxy import BufferProxy
256253
from pygame.newbuffer import BufferMixin
@@ -280,7 +277,6 @@ def test_bad_format(self):
280277
b = BufferProxy(exp)
281278
self.assertRaises(ValueError, Importer, b, PyBUF_FORMAT)
282279

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

385-
@unittest.skipIf(IS_PYPY or (not pygame.HAVE_NEWBUF), "newbuf with ctypes")
381+
@unittest.skipIf(IS_PYPY, "newbuf with ctypes")
386382
def test_PgObject_AsBuffer_PyBUF_flags(self):
387383
from pygame.bufferproxy import BufferProxy
388384
import ctypes

test/bufferproxy_test.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,6 @@ def __repr__(self):
255255
self.assertEqual(r[:2], "*<")
256256
self.assertEqual(r[-2:], ">*")
257257

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

test/color_test.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1088,7 +1088,6 @@ def test_arraystruct(self):
10881088
for j in range(i):
10891089
self.assertEqual(data[j], c[j])
10901090

1091-
@unittest.skipIf(not pygame.HAVE_NEWBUF, "newbuf not implemented")
10921091
def test_newbuf(self):
10931092
from pygame.tests.test_utils import buftools
10941093
from ctypes import cast, POINTER, c_uint8

test/freetype_test.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1246,7 +1246,6 @@ def test_freetype_Font_bgcolor(self):
12461246

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

1249-
@unittest.skipIf(not pygame.HAVE_NEWBUF, "newbuf not implemented")
12501249
@unittest.skipIf(IS_PYPY, "pypy no likey")
12511250
def test_newbuf(self):
12521251
from pygame.tests.test_utils import buftools

test/mixer_test.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,13 +359,11 @@ def test_array_interface(self):
359359
self.assertEqual(d["strides"], (2,))
360360
self.assertEqual(d["data"], (snd._samples_address, False))
361361

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

368-
@unittest.skipIf(not pygame.HAVE_NEWBUF, "newbuf not implemented")
369367
@unittest.skipIf(IS_PYPY, "pypy no likey")
370368
def test_newbuf__twho_channel(self):
371369
mixer.init(22050, -16, 2)

test/pixelarray_test.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,11 +1450,9 @@ def test_slicing(self):
14501450
self.assert_surfaces_equal(sf3, sf2)
14511451

14521452

1453-
@unittest.skipIf(not pygame.HAVE_NEWBUF, "newbuf not implemented")
14541453
@unittest.skipIf(IS_PYPY, "pypy having issues")
14551454
class PixelArrayNewBufferTest(unittest.TestCase, TestMixin):
1456-
if pygame.HAVE_NEWBUF:
1457-
from pygame.tests.test_utils import buftools
1455+
from pygame.tests.test_utils import buftools
14581456

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

test/pixelcopy_test.py

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -593,43 +593,41 @@ def test_map_array(self):
593593
del numpy
594594

595595

596-
@unittest.skipIf(not pygame.HAVE_NEWBUF, "newbuf not implemented")
597596
@unittest.skipIf(IS_PYPY, "pypy having illegal instruction on mac")
598597
class PixelCopyTestWithArrayNewBuf(unittest.TestCase):
599-
if pygame.HAVE_NEWBUF:
600-
from pygame.tests.test_utils import buftools
601-
602-
class Array2D(buftools.Exporter):
603-
def __init__(self, initializer):
604-
from ctypes import cast, POINTER, c_uint32
605-
606-
Array2D = PixelCopyTestWithArrayNewBuf.Array2D
607-
super().__init__((3, 5), format="=I", strides=(20, 4))
608-
self.content = cast(self.buf, POINTER(c_uint32))
609-
for i, v in enumerate(initializer):
610-
self.content[i] = v
611-
612-
def __getitem__(self, key):
613-
byte_index = key[0] * 5 + key[1]
614-
if not (0 <= byte_index < 15):
615-
raise IndexError("%s is out of range", key)
616-
return self.content[byte_index]
617-
618-
class Array3D(buftools.Exporter):
619-
def __init__(self, initializer):
620-
from ctypes import cast, POINTER, c_uint8
621-
622-
Array3D = PixelCopyTestWithArrayNewBuf.Array3D
623-
super().__init__((3, 5, 3), format="B", strides=(20, 4, 1))
624-
self.content = cast(self.buf, POINTER(c_uint8))
625-
for i, v in enumerate(initializer):
626-
self.content[i] = v
627-
628-
def __getitem__(self, key):
629-
byte_index = key[0] * 20 + key[1] * 4 + key[2]
630-
if not (0 <= byte_index < 60):
631-
raise IndexError("%s is out of range", key)
632-
return self.content[byte_index]
598+
from pygame.tests.test_utils import buftools
599+
600+
class Array2D(buftools.Exporter):
601+
def __init__(self, initializer):
602+
from ctypes import cast, POINTER, c_uint32
603+
604+
Array2D = PixelCopyTestWithArrayNewBuf.Array2D
605+
super().__init__((3, 5), format="=I", strides=(20, 4))
606+
self.content = cast(self.buf, POINTER(c_uint32))
607+
for i, v in enumerate(initializer):
608+
self.content[i] = v
609+
610+
def __getitem__(self, key):
611+
byte_index = key[0] * 5 + key[1]
612+
if not (0 <= byte_index < 15):
613+
raise IndexError("%s is out of range", key)
614+
return self.content[byte_index]
615+
616+
class Array3D(buftools.Exporter):
617+
def __init__(self, initializer):
618+
from ctypes import cast, POINTER, c_uint8
619+
620+
Array3D = PixelCopyTestWithArrayNewBuf.Array3D
621+
super().__init__((3, 5, 3), format="B", strides=(20, 4, 1))
622+
self.content = cast(self.buf, POINTER(c_uint8))
623+
for i, v in enumerate(initializer):
624+
self.content[i] = v
625+
626+
def __getitem__(self, key):
627+
byte_index = key[0] * 20 + key[1] * 4 + key[2]
628+
if not (0 <= byte_index < 60):
629+
raise IndexError("%s is out of range", key)
630+
return self.content[byte_index]
633631

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

0 commit comments

Comments
 (0)