Skip to content

Commit 0841ca7

Browse files
authored
gh-105751: Remove dead code in test_ctypes (#105817)
* Remove "except: print(tp); raise" debug code. * Remove unused NoNullHandle() function. * Remove commented code.
1 parent da911a6 commit 0841ca7

15 files changed

+37
-128
lines changed

Lib/test/test_ctypes/test_as_parameter.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ def test_callbacks(self):
8181
MyCallback = CFUNCTYPE(c_int, c_int)
8282

8383
def callback(value):
84-
#print "called back with", value
8584
return value
8685

8786
cb = MyCallback(callback)
@@ -118,7 +117,6 @@ def test_callbacks_2(self):
118117
f.argtypes = [c_int, MyCallback]
119118

120119
def callback(value):
121-
#print "called back with", value
122120
self.assertEqual(type(value), int)
123121
return value
124122

Lib/test/test_ctypes/test_bitfields.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ class BITS(Structure):
3131
func = CDLL(_ctypes_test.__file__).unpack_bitfields
3232
func.argtypes = POINTER(BITS), c_char
3333

34-
##for n in "ABCDEFGHIMNOPQRS":
35-
## print n, hex(getattr(BITS, n).size), getattr(BITS, n).offset
3634

3735
class C_Test(unittest.TestCase):
3836

Lib/test/test_ctypes/test_callbacks.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919
class Callbacks(unittest.TestCase):
2020
functype = CFUNCTYPE
2121

22-
## def tearDown(self):
23-
## gc.collect()
24-
2522
def callback(self, *args):
2623
self.got_args = args
2724
return args[-1]
@@ -43,8 +40,6 @@ def check_type(self, typ, arg):
4340
self.assertEqual(self.got_args, (-3, arg))
4441
self.assertEqual(result, arg)
4542

46-
################
47-
4843
def test_byte(self):
4944
self.check_type(c_byte, 42)
5045
self.check_type(c_byte, -42)

Lib/test/test_ctypes/test_find.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def setUpClass(cls):
2323
lib_glu = find_library("GLU")
2424
lib_gle = find_library("gle")
2525

26-
## print, for debugging
26+
# print, for debugging
2727
if test.support.verbose:
2828
print("OpenGL libraries:")
2929
for item in (("GL", lib_gl),

Lib/test/test_ctypes/test_funcptr.py

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,9 @@ class WNDCLASS(Structure):
7373

7474
WNDPROC_2 = WINFUNCTYPE(c_long, c_int, c_int, c_int, c_int)
7575

76-
# This is no longer true, now that WINFUNCTYPE caches created types internally.
77-
## # CFuncPtr subclasses are compared by identity, so this raises a TypeError:
78-
## self.assertRaises(TypeError, setattr, wndclass,
79-
## "lpfnWndProc", WNDPROC_2(wndproc))
80-
# instead:
81-
8276
self.assertIs(WNDPROC, WNDPROC_2)
83-
# 'wndclass.lpfnWndProc' leaks 94 references. Why?
8477
self.assertEqual(wndclass.lpfnWndProc(1, 2, 3, 4), 10)
8578

86-
8779
f = wndclass.lpfnWndProc
8880

8981
del wndclass
@@ -92,24 +84,14 @@ class WNDCLASS(Structure):
9284
self.assertEqual(f(10, 11, 12, 13), 46)
9385

9486
def test_dllfunctions(self):
95-
96-
def NoNullHandle(value):
97-
if not value:
98-
raise ctypes.WinError()
99-
return value
100-
10187
strchr = lib.my_strchr
10288
strchr.restype = c_char_p
10389
strchr.argtypes = (c_char_p, c_char)
10490
self.assertEqual(strchr(b"abcdefghi", b"b"), b"bcdefghi")
10591
self.assertEqual(strchr(b"abcdefghi", b"x"), None)
10692

107-
10893
strtok = lib.my_strtok
10994
strtok.restype = c_char_p
110-
# Neither of this does work: strtok changes the buffer it is passed
111-
## strtok.argtypes = (c_char_p, c_char_p)
112-
## strtok.argtypes = (c_string, c_char_p)
11395

11496
def c_string(init):
11597
size = len(init) + 1
@@ -118,10 +100,6 @@ def c_string(init):
118100
s = b"a\nb\nc"
119101
b = c_string(s)
120102

121-
## b = (c_char * (len(s)+1))()
122-
## b.value = s
123-
124-
## b = c_string(s)
125103
self.assertEqual(strtok(b, b"\n"), b"a")
126104
self.assertEqual(strtok(None, b"\n"), b"b")
127105
self.assertEqual(strtok(None, b"\n"), b"c")

Lib/test/test_ctypes/test_functions.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,6 @@ def test_pointers(self):
227227
result = f(byref(c_int(99)))
228228
self.assertNotEqual(result.contents, 99)
229229

230-
################################################################
231230
def test_shorts(self):
232231
f = dll._testfunc_callback_i_if
233232

@@ -245,9 +244,6 @@ def callback(v):
245244
f(2**18, cb)
246245
self.assertEqual(args, expected)
247246

248-
################################################################
249-
250-
251247
def test_callbacks(self):
252248
f = dll._testfunc_callback_i_if
253249
f.restype = c_int
@@ -256,7 +252,6 @@ def test_callbacks(self):
256252
MyCallback = CFUNCTYPE(c_int, c_int)
257253

258254
def callback(value):
259-
#print "called back with", value
260255
return value
261256

262257
cb = MyCallback(callback)
@@ -289,7 +284,6 @@ def test_callbacks_2(self):
289284
f.argtypes = [c_int, MyCallback]
290285

291286
def callback(value):
292-
#print "called back with", value
293287
self.assertEqual(type(value), int)
294288
return value
295289

Lib/test/test_ctypes/test_internals.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,6 @@ class Y(Structure):
8080
y = Y()
8181
y.x = x
8282
self.assertEqual(y._objects, {"0": {"0": s1, "1": s2}})
83-
## x = y.x
84-
## del y
85-
## print x._b_base_._objects
8683

8784
def test_ptr_struct(self):
8885
class X(Structure):
@@ -94,9 +91,6 @@ class X(Structure):
9491

9592
x = X()
9693
x.data = a
97-
##XXX print x._objects
98-
##XXX print x.data[0]
99-
##XXX print x.data._objects
10094

10195

10296
if __name__ == '__main__':

Lib/test/test_ctypes/test_keeprefs.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,19 +115,14 @@ class X(Structure):
115115
c_int(99)
116116
x.p[0]
117117
print(x.p[0])
118-
## del x
119-
## print "2?", sys.getrefcount(i)
120-
## del i
121118
gc.collect()
122119
for i in range(320):
123120
c_int(99)
124121
x.p[0]
125122
print(x.p[0])
126123
print(x.p.contents)
127-
## print x._objects
128124

129125
x.p[0] = "spam spam"
130-
## print x.p[0]
131126
print("+" * 42)
132127
print(x._objects)
133128

@@ -144,9 +139,6 @@ class RECT(Structure):
144139

145140
r.a = pointer(p1)
146141
r.b = pointer(p1)
147-
## from pprint import pprint as pp
148-
## pp(p1._objects)
149-
## pp(r._objects)
150142

151143
r.a[0].x = 42
152144
r.a[0].y = 99

Lib/test/test_ctypes/test_numbers.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,6 @@ class c_int_S(_SimpleCData):
225225

226226

227227
def run_test(rep, msg, func, arg=None):
228-
## items = [None] * rep
229228
items = range(rep)
230229
from time import perf_counter as clock
231230
if arg is not None:
@@ -243,7 +242,6 @@ def run_test(rep, msg, func, arg=None):
243242

244243
def check_perf():
245244
# Construct 5 objects
246-
from ctypes import c_int
247245

248246
REP = 200000
249247

Lib/test/test_ctypes/test_parameters.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,6 @@ def test_c_wchar(self):
103103
def test_int_pointers(self):
104104
LPINT = POINTER(c_int)
105105

106-
## p = pointer(c_int(42))
107-
## x = LPINT.from_param(p)
108106
x = LPINT.from_param(pointer(c_int(42)))
109107
self.assertEqual(x.contents.value, 42)
110108
self.assertEqual(LPINT(c_int(42)).contents.value, 42)

0 commit comments

Comments
 (0)