Skip to content

Commit 1c05250

Browse files
committed
fix tests
1 parent f06d6a5 commit 1c05250

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

Lib/test/test_ctypes/test_dlerror.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -147,20 +147,22 @@ def test_localized_error_from_dll(self):
147147
with tempfile.TemporaryDirectory() as outdir:
148148
dstname = self.make_empty_lib(outdir, 'test_from_dll.so')
149149
dll = CDLL(dstname)
150-
# on macOS, the filename is not reported by dlerror()
151-
pat = '.+' if sys.platform == 'darwin' else r'test_from_dll\.so'
152-
with self.assertRaisesRegex(AttributeError, pat):
150+
with self.assertRaises(AttributeError) as cm:
153151
dll.foo
152+
if sys.platform.startswith('linux'):
153+
# On macOS or Windows, the filename is not reported by dlerror()
154+
self.assertIn('test_from_dll.so', str(cm.exception))
154155

155156
@configure_locales
156157
def test_localized_error_in_dll(self):
157158
with tempfile.TemporaryDirectory() as outdir:
158159
dstname = self.make_empty_lib(outdir, 'test_in_dll.so')
159160
dll = CDLL(dstname)
160-
# on macOS, the filename is not reported by dlerror()
161-
pat = '.+' if sys.platform == 'darwin' else r'test_in_dll\.so'
162-
with self.assertRaisesRegex(ValueError, pat):
161+
with self.assertRaises(ValueError) as cm:
163162
c_int.in_dll(dll, 'foo')
163+
if sys.platform.startswith('linux'):
164+
# On macOS or Windows, the filename is not reported by dlerror()
165+
self.assertIn('test_in_dll.so', str(cm.exception))
164166

165167
@unittest.skipUnless(hasattr(_ctypes, 'dlopen'),
166168
'test requires _ctypes.dlopen()')
@@ -184,10 +186,11 @@ def test_localized_error_dlsym(self):
184186
with tempfile.TemporaryDirectory() as outdir:
185187
dstname = self.make_empty_lib(outdir, 'test_dlsym.so')
186188
dll = _ctypes.dlopen(dstname)
187-
# on macOS, the filename is not reported by dlerror()
188-
pat = '.+' if sys.platform == 'darwin' else r'test_dlsym\.so'
189-
with self.assertRaisesRegex(OSError, pat):
189+
with self.assertRaises(OSError) as cm:
190190
_ctypes.dlsym(dll, 'foo')
191+
if sys.platform.startswith('linux'):
192+
# On macOS or Windows, the filename is not reported by dlerror()
193+
self.assertIn('test_in_dll.so', str(cm.exception))
191194

192195

193196
if __name__ == "__main__":

0 commit comments

Comments
 (0)