Skip to content

Commit 62db957

Browse files
committed
address Victor's review
- replace possible unknown symbol by a better unknown symbol (hopefully) - improve semantic naming ('libc_file' -> 'libc_filename') - ensure PyPy compatibility
1 parent 5fc2e17 commit 62db957

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

Lib/test/test_ctypes/test_dlerror.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,11 @@ def test_null_dlsym(self):
108108
self.assertEqual(os.read(pipe_r, 2), b'OK')
109109

110110
# Case #3: Test 'py_dl_sym' from Modules/_ctypes/callproc.c
111-
L = _ctypes.dlopen(dstname)
111+
dlopen = test.support.get_attribute(_ctypes, 'dlopen')
112+
dlsym = test.support.get_attribute(_ctypes, 'dlsym')
113+
L = dlopen(dstname)
112114
with self.assertRaisesRegex(OSError, "symbol 'foo' not found"):
113-
_ctypes.dlsym(L, "foo")
115+
dlsym(L, "foo")
114116

115117
# Assert that the IFUNC was called
116118
self.assertEqual(os.read(pipe_r, 2), b'OK')
@@ -130,25 +132,25 @@ def configure_locales(func):
130132

131133
@classmethod
132134
def setUpClass(cls):
133-
cls.libc_file = find_library("c")
135+
cls.libc_filename = find_library("c")
134136

135137
@configure_locales
136138
def test_localized_error_from_dll(self):
137-
dll = CDLL(self.libc_file)
139+
dll = CDLL(self.libc_filename)
138140
with self.assertRaises(AttributeError) as cm:
139-
dll.foo
141+
dll.this_name_does_not_exist
140142
if sys.platform.startswith('linux'):
141143
# On macOS, the filename is not reported by dlerror().
142-
self.assertIn(self.libc_file, str(cm.exception))
144+
self.assertIn(self.libc_filename, str(cm.exception))
143145

144146
@configure_locales
145147
def test_localized_error_in_dll(self):
146-
dll = CDLL(self.libc_file)
148+
dll = CDLL(self.libc_filename)
147149
with self.assertRaises(ValueError) as cm:
148-
c_int.in_dll(dll, 'foo')
150+
c_int.in_dll(dll, 'this_name_does_not_exist')
149151
if sys.platform.startswith('linux'):
150152
# On macOS, the filename is not reported by dlerror().
151-
self.assertIn(self.libc_file, str(cm.exception))
153+
self.assertIn(self.libc_filename, str(cm.exception))
152154

153155
@unittest.skipUnless(hasattr(_ctypes, 'dlopen'),
154156
'test requires _ctypes.dlopen()')
@@ -169,12 +171,12 @@ def test_localized_error_dlopen(self):
169171
'test requires _ctypes.dlsym()')
170172
@configure_locales
171173
def test_localized_error_dlsym(self):
172-
dll = _ctypes.dlopen(self.libc_file)
174+
dll = _ctypes.dlopen(self.libc_filename)
173175
with self.assertRaises(OSError) as cm:
174-
_ctypes.dlsym(dll, 'foo')
176+
_ctypes.dlsym(dll, 'this_name_does_not_exist')
175177
if sys.platform.startswith('linux'):
176178
# On macOS, the filename is not reported by dlerror().
177-
self.assertIn(self.libc_file, str(cm.exception))
179+
self.assertIn(self.libc_filename, str(cm.exception))
178180

179181

180182
if __name__ == "__main__":

0 commit comments

Comments
 (0)