summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2024-03-13 21:31:09 (GMT)
committerGitHub <noreply@github.com>2024-03-13 21:31:09 (GMT)
commit0cc504771ff7b36293159d8a9f18757ed46ccfc5 (patch)
tree7bcf12c169fd1ca94808b3994b95adde41444e79 /Lib
parent592c0e26c00bf2bcfeb8e947000b10d518d41f86 (diff)
downloadcpython-0cc504771ff7b36293159d8a9f18757ed46ccfc5.zip
cpython-0cc504771ff7b36293159d8a9f18757ed46ccfc5.tar.gz
cpython-0cc504771ff7b36293159d8a9f18757ed46ccfc5.tar.bz2
[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 61733a2fb9dc36d2246d922146a3462a2248832d) Co-authored-by: Brett Cannon <brett@python.org>
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_importlib/extension/test_case_sensitivity.py3
-rw-r--r--Lib/test/test_importlib/extension/test_finder.py2
-rw-r--r--Lib/test/test_importlib/extension/test_loader.py6
-rw-r--r--Lib/test/test_importlib/extension/test_path_hook.py2
-rw-r--r--Lib/test/test_importlib/test_spec.py9
-rw-r--r--Lib/test/test_importlib/test_util.py2
-rw-r--r--Lib/test/test_importlib/util.py48
7 files changed, 44 insertions, 28 deletions
diff --git a/Lib/test/test_importlib/extension/test_case_sensitivity.py b/Lib/test/test_importlib/extension/test_case_sensitivity.py
index 0bb74ff..4031162 100644
--- a/Lib/test/test_importlib/extension/test_case_sensitivity.py
+++ b/Lib/test/test_importlib/extension/test_case_sensitivity.py
@@ -8,7 +8,8 @@ importlib = util.import_importlib('importlib')
machinery = util.import_importlib('importlib.machinery')
-@unittest.skipIf(util.EXTENSIONS.filename is None, f'{util.EXTENSIONS.name} not available')
+@unittest.skipIf(util.EXTENSIONS is None or util.EXTENSIONS.filename is None,
+ 'dynamic loading not supported or test module not available')
@util.case_insensitive_tests
class ExtensionModuleCaseSensitivityTest(util.CASEOKTestBase):
diff --git a/Lib/test/test_importlib/extension/test_finder.py b/Lib/test/test_importlib/extension/test_finder.py
index 1d5b6e7..3de1209 100644
--- a/Lib/test/test_importlib/extension/test_finder.py
+++ b/Lib/test/test_importlib/extension/test_finder.py
@@ -11,7 +11,7 @@ class FinderTests(abc.FinderTests):
"""Test the finder for extension modules."""
def setUp(self):
- if not self.machinery.EXTENSION_SUFFIXES:
+ if not self.machinery.EXTENSION_SUFFIXES or not util.EXTENSIONS:
raise unittest.SkipTest("Requires dynamic loading support.")
if util.EXTENSIONS.name in sys.builtin_module_names:
raise unittest.SkipTest(
diff --git a/Lib/test/test_importlib/extension/test_loader.py b/Lib/test/test_importlib/extension/test_loader.py
index 1b5a8ba..12f9e43 100644
--- a/Lib/test/test_importlib/extension/test_loader.py
+++ b/Lib/test/test_importlib/extension/test_loader.py
@@ -19,7 +19,7 @@ class LoaderTests:
"""Test ExtensionFileLoader."""
def setUp(self):
- if not self.machinery.EXTENSION_SUFFIXES:
+ if not self.machinery.EXTENSION_SUFFIXES or not util.EXTENSIONS:
raise unittest.SkipTest("Requires dynamic loading support.")
if util.EXTENSIONS.name in sys.builtin_module_names:
raise unittest.SkipTest(
@@ -101,7 +101,7 @@ class SinglePhaseExtensionModuleTests(abc.LoaderTests):
# Test loading extension modules without multi-phase initialization.
def setUp(self):
- if not self.machinery.EXTENSION_SUFFIXES:
+ if not self.machinery.EXTENSION_SUFFIXES or not util.EXTENSIONS:
raise unittest.SkipTest("Requires dynamic loading support.")
self.name = '_testsinglephase'
if self.name in sys.builtin_module_names:
@@ -182,7 +182,7 @@ class MultiPhaseExtensionModuleTests(abc.LoaderTests):
# Test loading extension modules with multi-phase initialization (PEP 489).
def setUp(self):
- if not self.machinery.EXTENSION_SUFFIXES:
+ if not self.machinery.EXTENSION_SUFFIXES or not util.EXTENSIONS:
raise unittest.SkipTest("Requires dynamic loading support.")
self.name = '_testmultiphase'
if self.name in sys.builtin_module_names:
diff --git a/Lib/test/test_importlib/extension/test_path_hook.py b/Lib/test/test_importlib/extension/test_path_hook.py
index ec9644d..314a635 100644
--- a/Lib/test/test_importlib/extension/test_path_hook.py
+++ b/Lib/test/test_importlib/extension/test_path_hook.py
@@ -5,6 +5,8 @@ machinery = util.import_importlib('importlib.machinery')
import unittest
+@unittest.skipIf(util.EXTENSIONS is None or util.EXTENSIONS.filename is None,
+ 'dynamic loading not supported or test module not available')
class PathHookTests:
"""Test the path hook for extension modules."""
diff --git a/Lib/test/test_importlib/test_spec.py b/Lib/test/test_importlib/test_spec.py
index 80aa360..0231892 100644
--- a/Lib/test/test_importlib/test_spec.py
+++ b/Lib/test/test_importlib/test_spec.py
@@ -502,7 +502,8 @@ class FactoryTests:
self.assertEqual(spec.loader, self.fileloader)
self.assertEqual(spec.origin, self.path)
self.assertIs(spec.loader_state, None)
- self.assertEqual(spec.submodule_search_locations, [os.getcwd()])
+ location = cwd if (cwd := os.getcwd()) != '/' else ''
+ self.assertEqual(spec.submodule_search_locations, [location])
self.assertEqual(spec.cached, self.cached)
self.assertTrue(spec.has_location)
@@ -601,7 +602,8 @@ class FactoryTests:
self.assertEqual(spec.loader, self.fileloader)
self.assertEqual(spec.origin, self.path)
self.assertIs(spec.loader_state, None)
- self.assertEqual(spec.submodule_search_locations, [os.getcwd()])
+ location = cwd if (cwd := os.getcwd()) != '/' else ''
+ self.assertEqual(spec.submodule_search_locations, [location])
self.assertEqual(spec.cached, self.cached)
self.assertTrue(spec.has_location)
@@ -626,7 +628,8 @@ class FactoryTests:
self.assertEqual(spec.loader, self.pkgloader)
self.assertEqual(spec.origin, self.path)
self.assertIs(spec.loader_state, None)
- self.assertEqual(spec.submodule_search_locations, [os.getcwd()])
+ location = cwd if (cwd := os.getcwd()) != '/' else ''
+ self.assertEqual(spec.submodule_search_locations, [location])
self.assertEqual(spec.cached, self.cached)
self.assertTrue(spec.has_location)
diff --git a/Lib/test/test_importlib/test_util.py b/Lib/test/test_importlib/test_util.py
index 217c1ad..e018af2 100644
--- a/Lib/test/test_importlib/test_util.py
+++ b/Lib/test/test_importlib/test_util.py
@@ -577,7 +577,7 @@ class PEP3147Tests:
with util.temporary_pycache_prefix(pycache_prefix):
self.assertEqual(
self.util.cache_from_source(path, optimization=''),
- expect)
+ os.path.normpath(expect))
@unittest.skipIf(sys.implementation.cache_tag is None,
'requires sys.implementation.cache_tag to not be None')
diff --git a/Lib/test/test_importlib/util.py b/Lib/test/test_importlib/util.py
index c25be09..a900cc1 100644
--- a/Lib/test/test_importlib/util.py
+++ b/Lib/test/test_importlib/util.py
@@ -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'
-
-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
+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
_extension_details()