|
14 | 14 | import random |
15 | 15 | import string |
16 | 16 | import importlib.machinery |
| 17 | +import sysconfig |
17 | 18 | from test import support |
18 | 19 | import shutil |
19 | 20 | from test.support import (Error, captured_output, cpython_only, ALWAYS_EQ, |
@@ -5195,15 +5196,29 @@ def test_windows_only_module_error(self): |
5195 | 5196 | else: |
5196 | 5197 | self.fail("ModuleNotFoundError was not raised") |
5197 | 5198 |
|
| 5199 | + @unittest.skipIf(not importlib.machinery.EXTENSION_SUFFIXES, 'Platform does not support extension modules') |
5198 | 5200 | def test_find_incompatible_extension_modules(self): |
5199 | 5201 | """_find_incompatible_extension_modules assumes the last extension in |
5200 | 5202 | importlib.machinery.EXTENSION_SUFFIXES (defined in Python/dynload_*.c) |
5201 | 5203 | is untagged (eg. .so, .pyd). |
5202 | 5204 |
|
5203 | 5205 | This test exists to make sure that assumption is correct. |
5204 | 5206 | """ |
5205 | | - if importlib.machinery.EXTENSION_SUFFIXES: |
5206 | | - self.assertEqual(len(importlib.machinery.EXTENSION_SUFFIXES[-1].split('.')), 2) |
| 5207 | + last_extension_suffix = importlib.machinery.EXTENSION_SUFFIXES[-1] |
| 5208 | + if shlib_suffix := sysconfig.get_config_var('SHLIB_SUFFIX'): |
| 5209 | + self.assertEqual(last_extension_suffix, shlib_suffix) |
| 5210 | + else: |
| 5211 | + dot, *extensions = last_extension_suffix.split('.') |
| 5212 | + self.assertEqual(dot, '') # sanity check |
| 5213 | + # if SHLIB_SUFFIX is not define, we assume the native |
| 5214 | + # shared library suffix only contains one extension |
| 5215 | + # (eg. '.so', bad eg. '.cpython-315-x86_64-linux-gnu.so') |
| 5216 | + self.assertEqual(len(extensions), 1, msg=( |
| 5217 | + 'The last suffix in importlib.machinery.EXTENSION_SUFFIXES ' |
| 5218 | + 'contains more than one extension, so it is probably different ' |
| 5219 | + 'than SHLIB_SUFFIX. It probably contains an ABI tag! ' |
| 5220 | + 'If this is a false positive, define SHLIB_SUFFIX in sysconfig.' |
| 5221 | + )) |
5207 | 5222 |
|
5208 | 5223 |
|
5209 | 5224 | class TestColorizedTraceback(unittest.TestCase): |
|
0 commit comments