8000 fix tests on ppc machines · python/cpython@d062bd7 · GitHub
[go: up one dir, main page]

Skip to content

Commit d062bd7

Browse files
committed
fix tests on ppc machines
1 parent 7303f06 commit d062bd7

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

Lib/test/test_ctypes/test_dlerror.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import _ctypes
22
import os
33
import platform
4+
import re
45
import sys
56
import test.support
67
import unittest
@@ -133,24 +134,36 @@ def configure_locales(func):
133134
@classmethod
134135
def setUpClass(cls):
135136
cls.libc_filename = find_library("c")
137+
if cls.libc_filename is None:
138+
raise unittest.SkipTest('cannot find libc')
139+
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)
136153

137154
@configure_locales
138155
def test_localized_error_from_dll(self):
139156
dll = CDLL(self.libc_filename)
140157
with self.assertRaises(AttributeError) as cm:
141158
dll.this_name_does_not_exist
142-
if sys.platform.startswith('linux'):
143-
# On macOS, the filename is not reported by dlerror().
144-
self.assertIn(self.libc_filename, str(cm.exception))
159+
self.check_filename_in_dlerror(str(cm.exception))
145160

146161
@configure_locales
147162
def test_localized_error_in_dll(self):
148163
dll = CDLL(self.libc_filename)
149164
with self.assertRaises(ValueError) as cm:
150165
c_int.in_dll(dll, 'this_name_does_not_exist')
151-
if sys.platform.startswith('linux'):
152-
# On macOS, the filename is not reported by dlerror().
153-
self.assertIn(self.libc_filename, str(cm.exception))
166+
self.check_filename_in_dlerror(str(cm.exception))
154167

155168
@unittest.skipUnless(hasattr(_ctypes, 'dlopen'),
156169
'test requires _ctypes.dlopen()')
@@ -174,9 +187,7 @@ def test_localized_error_dlsym(self):
174187
dll = _ctypes.dlopen(self.libc_filename)
175188
with self.assertRaises(OSError) as cm:
176189
_ctypes.dlsym(dll, 'this_name_does_not_exist')
177-
if sys.platform.startswith('linux'):
178-
# On macOS, the filename is not reported by dlerror().
179-
self.assertIn(self.libc_filename, str(cm.exception))
190+
self.check_filename_in_dlerror(str(cm.exception))
180191

181192

182193
if __name__ == "__main__":

0 commit comments

Comments
 (0)
0