|
7 | 7 | from ctypes import (CDLL, Structure, POINTER, pointer, sizeof, byref, |
8 | 8 | _pointer_type_cache, |
9 | 9 | c_void_p, c_char, c_int, c_long) |
| 10 | +import _ctypes |
10 | 11 | from test import support |
11 | 12 | from test.support import import_helper |
| 13 | +from test.support import warnings_helper |
12 | 14 | from ._support import Py_TPFLAGS_DISALLOW_INSTANTIATION, Py_TPFLAGS_IMMUTABLETYPE |
13 | 15 |
|
14 | 16 |
|
@@ -148,6 +150,28 @@ class RECT(Structure): |
148 | 150 | # to not leak references, we must clean _pointer_type_cache |
149 | 151 | del _pointer_type_cache[RECT] |
150 | 152 |
|
| 153 | +@unittest.skipUnless(sys.platform == "win32", 'Windows-specific test') |
| 154 | +class InprocessCallbacks(unittest.TestCase): |
| 155 | + def test_deprecated_py_functions(self): |
| 156 | + with import_helper.isolated_modules(): |
| 157 | + sys.modules['comtypes'] = None |
| 158 | + with warnings_helper.check_warnings((".*3.19", DeprecationWarning)): |
| 159 | + self.assertEqual(ctypes.DllCanUnloadNow(), 0) |
| 160 | + with warnings_helper.check_warnings((".*3.19", DeprecationWarning)): |
| 161 | + self.assertLess(ctypes.DllGetClassObject(0, 0, 0), 0) |
| 162 | + |
| 163 | + def test_deprecated_dll_functions(self): |
| 164 | + """C wrappers should warn, even with replaced hooks""" |
| 165 | + support.patch(self, ctypes, 'DllCanUnloadNow', lambda: 1234) |
| 166 | + support.patch(self, ctypes, 'DllGetClassObject', lambda *args: 1234) |
| 167 | + with import_helper.isolated_modules(): |
| 168 | + sys.modules['comtypes'] = None |
| 169 | + ctypes_dll = ctypes.WinDLL(_ctypes.__file__) |
| 170 | + with warnings_helper.check_warnings((".*3.19", DeprecationWarning)): |
| 171 | + self.assertEqual(ctypes_dll.DllCanUnloadNow(), 1234) |
| 172 | + with warnings_helper.check_warnings((".*3.19", DeprecationWarning)): |
| 173 | + self.assertEqual(ctypes_dll.DllGetClassObject(0, 0, 0), 1234) |
| 174 | + |
151 | 175 |
|
152 | 176 | if __name__ == '__main__': |
153 | 177 | unittest.main() |
0 commit comments