From d062bd7d37158ee6e6d9a286b54a92e368fe1bc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Tue, 17 Dec 2024 17:10:15 +0100 Subject: [PATCH 1/2] fix tests on ppc machines --- Lib/test/test_ctypes/test_dlerror.py | 29 +++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/Lib/test/test_ctypes/test_dlerror.py b/Lib/test/test_ctypes/test_dlerror.py index c3c34d43481d36..d4d7eb8612606c 100644 --- a/Lib/test/test_ctypes/test_dlerror.py +++ b/Lib/test/test_ctypes/test_dlerror.py @@ -1,6 +1,7 @@ import _ctypes import os import platform +import re import sys import test.support import unittest @@ -133,24 +134,36 @@ def configure_locales(func): @classmethod def setUpClass(cls): cls.libc_filename = find_library("c") + if cls.libc_filename is None: + raise unittest.SkipTest('cannot find libc') + + def check_filename_in_dlerror(self, error_message): + if not sys.platform.startswith('linux'): + # On macOS, the filename is not reported by dlerror(). + return + + if not re.match(r'(i[3-6]86|x86_64)$', platform.machine()): + # On some architectures, the libc file is detected + # to be 'libc.so.6' but is incorrectly reported by + # dlerror() as libc-X.Y.so. + self.skipTest('do not search for filename ' + 'in dlerror() error message') + + self.assertIn(self.libc_filename, error_message) @configure_locales def test_localized_error_from_dll(self): dll = CDLL(self.libc_filename) with self.assertRaises(AttributeError) as cm: dll.this_name_does_not_exist - if sys.platform.startswith('linux'): - # On macOS, the filename is not reported by dlerror(). - self.assertIn(self.libc_filename, str(cm.exception)) + self.check_filename_in_dlerror(str(cm.exception)) @configure_locales def test_localized_error_in_dll(self): dll = CDLL(self.libc_filename) with self.assertRaises(ValueError) as cm: c_int.in_dll(dll, 'this_name_does_not_exist') - if sys.platform.startswith('linux'): - # On macOS, the filename is not reported by dlerror(). - self.assertIn(self.libc_filename, str(cm.exception)) + self.check_filename_in_dlerror(str(cm.exception)) @unittest.skipUnless(hasattr(_ctypes, 'dlopen'), 'test requires _ctypes.dlopen()') @@ -174,9 +187,7 @@ def test_localized_error_dlsym(self): dll = _ctypes.dlopen(self.libc_filename) with self.assertRaises(OSError) as cm: _ctypes.dlsym(dll, 'this_name_does_not_exist') - if sys.platform.startswith('linux'): - # On macOS, the filename is not reported by dlerror(). - self.assertIn(self.libc_filename, str(cm.exception)) + self.check_filename_in_dlerror(str(cm.exception)) if __name__ == "__main__": From a1c32ceb663574a0e2be4d8d728dcaab62f355df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Tue, 17 Dec 2024 18:34:38 +0100 Subject: [PATCH 2/2] remove un-necessary check --- Lib/test/test_ctypes/test_dlerror.py | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/Lib/test/test_ctypes/test_dlerror.py b/Lib/test/test_ctypes/test_dlerror.py index d4d7eb8612606c..6bf492399cbf95 100644 --- a/Lib/test/test_ctypes/test_dlerror.py +++ b/Lib/test/test_ctypes/test_dlerror.py @@ -1,7 +1,6 @@ import _ctypes import os import platform -import re import sys import test.support import unittest @@ -137,33 +136,17 @@ def setUpClass(cls): if cls.libc_filename is None: raise unittest.SkipTest('cannot find libc') - def check_filename_in_dlerror(self, error_message): - if not sys.platform.startswith('linux'): - # On macOS, the filename is not reported by dlerror(). - return - - if not re.match(r'(i[3-6]86|x86_64)$', platform.machine()): - # On some architectures, the libc file is detected - # to be 'libc.so.6' but is incorrectly reported by - # dlerror() as libc-X.Y.so. - self.skipTest('do not search for filename ' - 'in dlerror() error message') - - self.assertIn(self.libc_filename, error_message) - @configure_locales def test_localized_error_from_dll(self): dll = CDLL(self.libc_filename) - with self.assertRaises(AttributeError) as cm: + with self.assertRaises(AttributeError): dll.this_name_does_not_exist - self.check_filename_in_dlerror(str(cm.exception)) @configure_locales def test_localized_error_in_dll(self): dll = CDLL(self.libc_filename) - with self.assertRaises(ValueError) as cm: + with self.assertRaises(ValueError): c_int.in_dll(dll, 'this_name_does_not_exist') - self.check_filename_in_dlerror(str(cm.exception)) @unittest.skipUnless(hasattr(_ctypes, 'dlopen'), 'test requires _ctypes.dlopen()') @@ -185,9 +168,8 @@ def test_localized_error_dlopen(self): @configure_locales def test_localized_error_dlsym(self): dll = _ctypes.dlopen(self.libc_filename) - with self.assertRaises(OSError) as cm: + with self.assertRaises(OSError): _ctypes.dlsym(dll, 'this_name_does_not_exist') - self.check_filename_in_dlerror(str(cm.exception)) if __name__ == "__main__":