Skip to content

Commit fc93bc8

Browse files
Add some tests for pointer
1 parent 2373c63 commit fc93bc8

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

Lib/test/test_ctypes/test_pointers.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,10 @@ def test_basics(self):
127127
def test_from_address(self):
128128
a = array.array('i', [100, 200, 300, 400, 500])
129129
addr = a.buffer_info()[0]
130-
p = POINTER(POINTER(c_int))
130+
p1 = POINTER(c_int)
131+
p2 = POINTER(p1)
132+
133+
self.assertIsNot(p1, p2)
131134

132135
def test_other(self):
133136
class Table(Structure):
@@ -224,15 +227,37 @@ def test_pointer_types_equal(self):
224227

225228
self.assertIs(t1, t2)
226229

230+
p1 = t1(c_int(1))
231+
p2 = t2(c_int(1))
232+
p3 = pointer(c_int(1))
233+
234+
self.assertIsInstance(p1, t1)
235+
self.assertIsInstance(p2, t1)
236+
self.assertIsInstance(p3, t1)
237+
227238
def test_incomplete_pointer_types_not_equal(self):
228239
t1 = POINTER("LP_C")
229240
t2 = POINTER("LP_C")
230241

231242
self.assertIsNot(t1, t2)
232243

244+
def test_incomplete_pointer_types_cannot_instantiate(self):
245+
t1 = POINTER("LP_C")
246+
with self.assertRaisesRegex(TypeError, "has no _type_"):
247+
t1()
248+
249+
msg = "<class 'str'> must have storage info"
250+
with self.assertRaisesRegex(TypeError, msg):
251+
pointer("LP_C")
252+
233253
def test_pointer_set_type_twice(self):
234254
t1 = POINTER(c_int)
255+
self.assertIs(c_int.__pointer_type__, t1)
256+
self.assertIs(t1._type_, c_int)
257+
235258
t1.set_type(c_int)
259+
self.assertIs(c_int.__pointer_type__, t1)
260+
self.assertIs(t1._type_, c_int)
236261

237262
def test_pointer_set_wrong_type(self):
238263
t1 = POINTER(c_int)
@@ -243,6 +268,12 @@ def test_pointer_not_ctypes_type(self):
243268
with self.assertRaisesRegex(TypeError, "must have storage info"):
244269
POINTER(int)
245270

271+
with self.assertRaisesRegex(TypeError, "must have storage info"):
272+
pointer(int)
273+
274+
with self.assertRaisesRegex(TypeError, "must have storage info"):
275+
pointer(int(1))
276+
246277
def test_pointer_set_python_type(self):
247278
p1 = POINTER(c_int)
248279
with self.assertRaisesRegex(TypeError, "must have storage info"):

0 commit comments

Comments
 (0)