|
2 | 2 | import unittest |
3 | 3 | from ctypes import (CDLL, Structure, CFUNCTYPE, sizeof, _CFuncPtr, |
4 | 4 | c_void_p, c_char_p, c_char, c_int, c_uint, c_long) |
| 5 | +from ctypes.util import wrap_dll_function |
5 | 6 | from test.support import import_helper |
6 | 7 | _ctypes_test = import_helper.import_module("_ctypes_test") |
7 | 8 | from ._support import (_CData, PyCFuncPtrType, Py_TPFLAGS_DISALLOW_INSTANTIATION, |
@@ -130,6 +131,26 @@ def c_string(init): |
130 | 131 | def test_abstract(self): |
131 | 132 | self.assertRaises(TypeError, _CFuncPtr, 13, "name", 42, "iid") |
132 | 133 |
|
| 134 | + def test_wrap_dll_function(self): |
| 135 | + @wrap_dll_function(ctypes.pythonapi) |
| 136 | + def PyObject_GetAttr(op: ctypes.py_object, attr: ctypes.py_object) -> ctypes.py_object: |
| 137 | + pass |
| 138 | + |
| 139 | + class Foo: |
| 140 | + a = "abc" |
| 141 | + |
| 142 | + self.assertEqual(PyObject_GetAttr(Foo, "a"), "abc") |
| 143 | + |
| 144 | + with self.assertRaises(AttributeError): |
| 145 | + @wrap_dll_function(ctypes.pythonapi) |
| 146 | + def noexist(): |
| 147 | + pass |
| 148 | + |
| 149 | + with self.assertRaisesRegex(ValueError, "'PyObject_GetAttrString' missing return type annotation"): |
| 150 | + @wrap_dll_function(ctypes.pythonapi) |
| 151 | + def PyObject_GetAttrString(op: ctypes.py_object, attr: ctypes.c_char_p): |
| 152 | + pass |
| 153 | + |
133 | 154 |
|
134 | 155 | if __name__ == '__main__': |
135 | 156 | unittest.main() |
0 commit comments