File: py314-refcount-tests.patch

package info (click to toggle)
pygame 2.6.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 42,952 kB
  • sloc: ansic: 66,926; python: 48,797; javascript: 1,153; objc: 224; sh: 121; makefile: 59; cpp: 25
file content (263 lines) | stat: -rw-r--r-- 9,523 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
From: =?utf-8?q?Ren=C3=A9_Dudfield?= <renesd@gmail.com>
Date: Mon, 8 Dec 2025 19:34:06 +0000
Subject: freetype_test: mask_test: rwobject_test: Change ref counts for py
 3.14

Are these correct? I don't know.

But apparently the garbage collector changed and reference counts
changed.

Origin: https://github.com/pygame/pygame/pull/4599/commits/ac69c0be7e165d967123ffaf2075f81357a5a25e
Bug-Debian: https://bugs.debian.org/1121999
Last-Update: 2025-12-08
---
 test/freetype_test.py | 17 +++++++++--
 test/mask_test.py     | 84 ++++++++++++++++++++++++++++++++++++++++++---------
 test/rwobject_test.py |  6 +++-
 3 files changed, 89 insertions(+), 18 deletions(-)

diff --git a/test/freetype_test.py b/test/freetype_test.py
index 25551d8..d00db8a 100644
--- a/test/freetype_test.py
+++ b/test/freetype_test.py
@@ -1609,16 +1609,27 @@ class FreeTypeFontTest(unittest.TestCase):
         else:
             array = arrinter.Array(rect.size, "u", 1)
             o = font.render_raw(text)
-            self.assertEqual(getrefcount(o), 2)
+            # if python 3.14+, getrefcount returns 1 instead of 2
+            if sys.version_info >= (3, 14):
+                self.assertEqual(getrefcount(o), 1)
+            else:
+                self.assertEqual(getrefcount(o), 2)
             self.assertEqual(getrefcount(o[0]), 2)
             self.assertEqual(getrefcount(o[1]), 2)
             self.assertEqual(getrefcount(font.render_raw_to(array, text)), 1)
             o = font.get_metrics("AB")
-            self.assertEqual(getrefcount(o), 2)
+            if sys.version_info >= (3, 14):
+                self.assertEqual(getrefcount(o), 1)
+            else:
+                self.assertEqual(getrefcount(o), 2)
+
             for i in range(len(o)):
                 self.assertEqual(getrefcount(o[i]), 2, "refcount fail for item %d" % i)
             o = font.get_sizes()
-            self.assertEqual(getrefcount(o), 2)
+            if sys.version_info >= (3, 14):
+                self.assertEqual(getrefcount(o), 1)
+            else:
+                self.assertEqual(getrefcount(o), 2)
             for i in range(len(o)):
                 self.assertEqual(getrefcount(o[i]), 2, "refcount fail for item %d" % i)
 
diff --git a/test/mask_test.py b/test/mask_test.py
index bd7daf5..3bd7062 100644
--- a/test/mask_test.py
+++ b/test/mask_test.py
@@ -2579,7 +2579,11 @@ class MaskTypeTest(unittest.TestCase):
     @unittest.skipIf(IS_PYPY, "Segfaults on pypy")
     def test_to_surface(self):
         """Ensures empty and full masks can be drawn onto surfaces."""
-        expected_ref_count = 3
+        if sys.version_info >= (3, 14):
+            expected_ref_count = 2
+        else:
+            expected_ref_count = 3
+
         size = (33, 65)
         surface = pygame.Surface(size, SRCALPHA, 32)
         surface_color = pygame.Color("red")
@@ -2599,7 +2603,11 @@ class MaskTypeTest(unittest.TestCase):
 
     def test_to_surface__create_surface(self):
         """Ensures empty and full masks can be drawn onto a created surface."""
-        expected_ref_count = 2
+        if sys.version_info >= (3, 14):
+            expected_ref_count = 1
+        else:
+            expected_ref_count = 2
+
         expected_flag = SRCALPHA
         expected_depth = 32
         size = (33, 65)
@@ -2624,7 +2632,11 @@ class MaskTypeTest(unittest.TestCase):
 
     def test_to_surface__surface_param(self):
         """Ensures to_surface accepts a surface arg/kwarg."""
-        expected_ref_count = 4
+        if sys.version_info >= (3, 14):
+            expected_ref_count = 3
+        else:
+            expected_ref_count = 4
+
         expected_color = pygame.Color("white")
         surface_color = pygame.Color("red")
         size = (5, 3)
@@ -2648,7 +2660,11 @@ class MaskTypeTest(unittest.TestCase):
 
     def test_to_surface__setsurface_param(self):
         """Ensures to_surface accepts a setsurface arg/kwarg."""
-        expected_ref_count = 2
+        if sys.version_info >= (3, 14):
+            expected_ref_count = 1
+        else:
+            expected_ref_count = 2
+
         expected_flag = SRCALPHA
         expected_depth = 32
         expected_color = pygame.Color("red")
@@ -2675,7 +2691,11 @@ class MaskTypeTest(unittest.TestCase):
 
     def test_to_surface__unsetsurface_param(self):
         """Ensures to_surface accepts a unsetsurface arg/kwarg."""
-        expected_ref_count = 2
+        if sys.version_info >= (3, 14):
+            expected_ref_count = 1
+        else:
+            expected_ref_count = 2
+
         expected_flag = SRCALPHA
         expected_depth = 32
         expected_color = pygame.Color("red")
@@ -2701,7 +2721,11 @@ class MaskTypeTest(unittest.TestCase):
 
     def test_to_surface__setcolor_param(self):
         """Ensures to_surface accepts a setcolor arg/kwarg."""
-        expected_ref_count = 2
+        if sys.version_info >= (3, 14):
+            expected_ref_count = 1
+        else:
+            expected_ref_count = 2
+
         expected_flag = SRCALPHA
         expected_depth = 32
         expected_color = pygame.Color("red")
@@ -2738,7 +2762,11 @@ class MaskTypeTest(unittest.TestCase):
 
     def test_to_surface__unsetcolor_param(self):
         """Ensures to_surface accepts a unsetcolor arg/kwarg."""
-        expected_ref_count = 2
+        if sys.version_info >= (3, 14):
+            expected_ref_count = 1
+        else:
+            expected_ref_count = 2
+
         expected_flag = SRCALPHA
         expected_depth = 32
         expected_color = pygame.Color("red")
@@ -2777,7 +2805,11 @@ class MaskTypeTest(unittest.TestCase):
 
     def test_to_surface__dest_param(self):
         """Ensures to_surface accepts a dest arg/kwarg."""
-        expected_ref_count = 2
+        if sys.version_info >= (3, 14):
+            expected_ref_count = 1
+        else:
+            expected_ref_count = 2
+
         expected_flag = SRCALPHA
         expected_depth = 32
         default_surface_color = (0, 0, 0, 0)
@@ -2833,7 +2865,11 @@ class MaskTypeTest(unittest.TestCase):
     @unittest.expectedFailure
     def test_to_surface__area_param(self):
         """Ensures to_surface accepts an area arg/kwarg."""
-        expected_ref_count = 2
+        if sys.version_info >= (3, 14):
+            expected_ref_count = 1
+        else:
+            expected_ref_count = 2
+
         expected_flag = SRCALPHA
         expected_depth = 32
         default_surface_color = (0, 0, 0, 0)
@@ -3327,7 +3363,11 @@ class MaskTypeTest(unittest.TestCase):
         This tests many different parameter combinations with full and empty
         masks.
         """
-        expected_ref_count = 2
+        if sys.version_info >= (3, 14):
+            expected_ref_count = 1
+        else:
+            expected_ref_count = 2
+
         expected_flag = SRCALPHA
         expected_depth = 32
         size = (5, 3)
@@ -3411,7 +3451,11 @@ class MaskTypeTest(unittest.TestCase):
         This tests many different parameter combinations with full and empty
         masks.
         """
-        expected_ref_count = 4
+        if sys.version_info >= (3, 14):
+            expected_ref_count = 3
+        else:
+            expected_ref_count = 4
+
         expected_flag = SRCALPHA
         expected_depth = 32
         size = (5, 3)
@@ -5273,7 +5317,11 @@ class MaskTypeTest(unittest.TestCase):
 
     def test_to_surface__surface_with_zero_size(self):
         """Ensures zero sized surfaces are handled correctly."""
-        expected_ref_count = 3
+        if sys.version_info >= (3, 14):
+            expected_ref_count = 2
+        else:
+            expected_ref_count = 3
+
         size = (0, 0)
         surface = pygame.Surface(size)
         mask = pygame.mask.Mask((3, 4), fill=True)
@@ -5287,7 +5335,11 @@ class MaskTypeTest(unittest.TestCase):
 
     def test_to_surface__setsurface_with_zero_size(self):
         """Ensures zero sized setsurfaces are handled correctly."""
-        expected_ref_count = 2
+        if sys.version_info >= (3, 14):
+            expected_ref_count = 1
+        else:
+            expected_ref_count = 2
+
         expected_flag = SRCALPHA
         expected_depth = 32
         expected_color = pygame.Color("white")  # Default setcolor.
@@ -5307,7 +5359,11 @@ class MaskTypeTest(unittest.TestCase):
 
     def test_to_surface__unsetsurface_with_zero_size(self):
         """Ensures zero sized unsetsurfaces are handled correctly."""
-        expected_ref_count = 2
+        if sys.version_info >= (3, 14):
+            expected_ref_count = 1
+        else:
+            expected_ref_count = 2
+
         expected_flag = SRCALPHA
         expected_depth = 32
         expected_color = pygame.Color("black")  # Default unsetcolor.
diff --git a/test/rwobject_test.py b/test/rwobject_test.py
index 31723ae..3441b04 100644
--- a/test/rwobject_test.py
+++ b/test/rwobject_test.py
@@ -1,5 +1,6 @@
 import pathlib
 import unittest
+import sys
 
 from pygame import encode_string, encode_file_path
 
@@ -83,7 +84,10 @@ class RWopsEncodeStringTest(unittest.TestCase):
             bpath = encode_string(bpath)
             self.assertEqual(getrefcount(bpath), before)
             bpath = encode_string(upath)
-            self.assertEqual(getrefcount(bpath), before)
+            if sys.version_info >= (3, 14):
+                self.assertEqual(getrefcount(bpath), before - 1)
+            else:
+                self.assertEqual(getrefcount(bpath), before)
 
     def test_smp(self):
         utf_8 = b"a\xF0\x93\x82\xA7b"