[3.12] GH-115979: update test_importlib to work under WASI SDK 21 (GH-116754) (GH-116759)

GH-115979: update test_importlib to work under WASI SDK 21 (GH-116754)
(cherry picked from commit 61733a2fb9)

Co-authored-by: Brett Cannon <brett@python.org>
This commit is contained in:
Miss Islington (bot) 2024-03-13 22:31:09 +01:00 committed by GitHub
parent 592c0e26c0
commit 0cc504771f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 44 additions and 27 deletions

View file

@ -6,6 +6,7 @@ from importlib import machinery, util, invalidate_caches
import marshal
import os
import os.path
from test import support
from test.support import import_helper
from test.support import os_helper
import unittest
@ -22,25 +23,34 @@ if 'errno' in sys.builtin_module_names:
if 'importlib' not in sys.builtin_module_names:
BUILTINS.bad_name = 'importlib'
EXTENSIONS = types.SimpleNamespace()
EXTENSIONS.path = None
EXTENSIONS.ext = None
EXTENSIONS.filename = None
EXTENSIONS.file_path = None
EXTENSIONS.name = '_testsinglephase'
if support.is_wasi:
# dlopen() is a shim for WASI as of WASI SDK which fails by default.
# We don't provide an implementation, so tests will fail.
# But we also don't want to turn off dynamic loading for those that provide
# a working implementation.
def _extension_details():
global EXTENSIONS
EXTENSIONS = None
else:
EXTENSIONS = types.SimpleNamespace()
EXTENSIONS.path = None
EXTENSIONS.ext = None
EXTENSIONS.filename = None
EXTENSIONS.file_path = None
EXTENSIONS.name = '_testsinglephase'
def _extension_details():
global EXTENSIONS
for path in sys.path:
for ext in machinery.EXTENSION_SUFFIXES:
filename = EXTENSIONS.name + ext
file_path = os.path.join(path, filename)
if os.path.exists(file_path):
EXTENSIONS.path = path
EXTENSIONS.ext = ext
EXTENSIONS.filename = filename
EXTENSIONS.file_path = file_path
return
def _extension_details():
global EXTENSIONS
for path in sys.path:
for ext in machinery.EXTENSION_SUFFIXES:
filename = EXTENSIONS.name + ext
file_path = os.path.join(path, filename)
if os.path.exists(file_path):
EXTENSIONS.path = path
EXTENSIONS.ext = ext
EXTENSIONS.filename = filename
EXTENSIONS.file_path = file_path
return
_extension_details()