1
1
import _ctypes
2
2
import os
3
3
import platform
4
- import re
5
4
import sys
6
5
import test .support
7
6
import unittest
@@ -137,33 +136,17 @@ def setUpClass(cls):
137
136
if cls .libc_filename is None :
138
137
raise unittest .SkipTest ('cannot find libc' )
139
138
140
- def check_filename_in_dlerror (self , error_message ):
141
- if not sys .platform .startswith ('linux' ):
142
- # On macOS, the filename is not reported by dlerror().
143
- return
144
-
145
- if not re .match (r'(i[3-6]86|x86_64)$' , platform .machine ()):
146
- # On some architectures, the libc file is detected
147
- # to be 'libc.so.6' but is incorrectly reported by
148
- # dlerror() as libc-X.Y.so.
149
- self .skipTest ('do not search for filename '
150
- 'in dlerror() error message' )
151
-
152
- self .assertIn (self .libc_filename , error_message )
153
-
154
139
@configure_locales
155
140
def test_localized_error_from_dll (self ):
156
141
dll = CDLL (self .libc_filename )
157
- with self .assertRaises (AttributeError ) as cm :
142
+ with self .assertRaises (AttributeError ):
158
143
dll .this_name_does_not_exist
159
- self .check_filename_in_dlerror (str (cm .exception ))
160
144
161
145
@configure_locales
162
146
def test_localized_error_in_dll (self ):
163
147
dll = CDLL (self .libc_filename )
164
- with self .assertRaises (ValueError ) as cm :
148
+ with self .assertRaises (ValueError ):
165
149
c_int .in_dll (dll , 'this_name_does_not_exist' )
166
- self .check_filename_in_dlerror (str (cm .exception ))
167
150
168
151
@unittest .skipUnless (hasattr (_ctypes , 'dlopen' ),
169
152
'test requires _ctypes.dlopen()' )
@@ -185,9 +168,8 @@ def test_localized_error_dlopen(self):
185
168
@configure_locales
186
169
def test_localized_error_dlsym (self ):
187
170
dll = _ctypes .dlopen (self .libc_filename )
188
- with self .assertRaises (OSError ) as cm :
171
+ with self .assertRaises (OSError ):
189
172
_ctypes .dlsym (dll , 'this_name_does_not_exist' )
190
- self .check_filename_in_dlerror (str (cm .exception ))
191
173
192
174
193
175
if __name__ == "__main__" :
0 commit comments