mirror of
https://github.com/python/cpython.git
synced 2025-08-03 00:23:06 +00:00
GH-115979: update test_importlib to work under WASI SDK 21 (GH-116754)
This commit is contained in:
parent
5ff012a449
commit
61733a2fb9
8 changed files with 44 additions and 27 deletions
|
@ -8,7 +8,8 @@ importlib = util.import_importlib('importlib')
|
||||||
machinery = util.import_importlib('importlib.machinery')
|
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
|
@util.case_insensitive_tests
|
||||||
class ExtensionModuleCaseSensitivityTest(util.CASEOKTestBase):
|
class ExtensionModuleCaseSensitivityTest(util.CASEOKTestBase):
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ class FinderTests(abc.FinderTests):
|
||||||
"""Test the finder for extension modules."""
|
"""Test the finder for extension modules."""
|
||||||
|
|
||||||
def setUp(self):
|
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.")
|
raise unittest.SkipTest("Requires dynamic loading support.")
|
||||||
if util.EXTENSIONS.name in sys.builtin_module_names:
|
if util.EXTENSIONS.name in sys.builtin_module_names:
|
||||||
raise unittest.SkipTest(
|
raise unittest.SkipTest(
|
||||||
|
|
|
@ -17,7 +17,7 @@ class LoaderTests:
|
||||||
"""Test ExtensionFileLoader."""
|
"""Test ExtensionFileLoader."""
|
||||||
|
|
||||||
def setUp(self):
|
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.")
|
raise unittest.SkipTest("Requires dynamic loading support.")
|
||||||
if util.EXTENSIONS.name in sys.builtin_module_names:
|
if util.EXTENSIONS.name in sys.builtin_module_names:
|
||||||
raise unittest.SkipTest(
|
raise unittest.SkipTest(
|
||||||
|
@ -99,7 +99,7 @@ class SinglePhaseExtensionModuleTests(abc.LoaderTests):
|
||||||
# Test loading extension modules without multi-phase initialization.
|
# Test loading extension modules without multi-phase initialization.
|
||||||
|
|
||||||
def setUp(self):
|
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.")
|
raise unittest.SkipTest("Requires dynamic loading support.")
|
||||||
self.name = '_testsinglephase'
|
self.name = '_testsinglephase'
|
||||||
if self.name in sys.builtin_module_names:
|
if self.name in sys.builtin_module_names:
|
||||||
|
@ -180,7 +180,7 @@ class MultiPhaseExtensionModuleTests(abc.LoaderTests):
|
||||||
# Test loading extension modules with multi-phase initialization (PEP 489).
|
# Test loading extension modules with multi-phase initialization (PEP 489).
|
||||||
|
|
||||||
def setUp(self):
|
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.")
|
raise unittest.SkipTest("Requires dynamic loading support.")
|
||||||
self.name = '_testmultiphase'
|
self.name = '_testmultiphase'
|
||||||
if self.name in sys.builtin_module_names:
|
if self.name in sys.builtin_module_names:
|
||||||
|
|
|
@ -5,6 +5,8 @@ machinery = util.import_importlib('importlib.machinery')
|
||||||
import unittest
|
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:
|
class PathHookTests:
|
||||||
|
|
||||||
"""Test the path hook for extension modules."""
|
"""Test the path hook for extension modules."""
|
||||||
|
|
|
@ -502,7 +502,8 @@ class FactoryTests:
|
||||||
self.assertEqual(spec.loader, self.fileloader)
|
self.assertEqual(spec.loader, self.fileloader)
|
||||||
self.assertEqual(spec.origin, self.path)
|
self.assertEqual(spec.origin, self.path)
|
||||||
self.assertIs(spec.loader_state, None)
|
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.assertEqual(spec.cached, self.cached)
|
||||||
self.assertTrue(spec.has_location)
|
self.assertTrue(spec.has_location)
|
||||||
|
|
||||||
|
@ -601,7 +602,8 @@ class FactoryTests:
|
||||||
self.assertEqual(spec.loader, self.fileloader)
|
self.assertEqual(spec.loader, self.fileloader)
|
||||||
self.assertEqual(spec.origin, self.path)
|
self.assertEqual(spec.origin, self.path)
|
||||||
self.assertIs(spec.loader_state, None)
|
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.assertEqual(spec.cached, self.cached)
|
||||||
self.assertTrue(spec.has_location)
|
self.assertTrue(spec.has_location)
|
||||||
|
|
||||||
|
@ -626,7 +628,8 @@ class FactoryTests:
|
||||||
self.assertEqual(spec.loader, self.pkgloader)
|
self.assertEqual(spec.loader, self.pkgloader)
|
||||||
self.assertEqual(spec.origin, self.path)
|
self.assertEqual(spec.origin, self.path)
|
||||||
self.assertIs(spec.loader_state, None)
|
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.assertEqual(spec.cached, self.cached)
|
||||||
self.assertTrue(spec.has_location)
|
self.assertTrue(spec.has_location)
|
||||||
|
|
||||||
|
|
|
@ -577,7 +577,7 @@ class PEP3147Tests:
|
||||||
with util.temporary_pycache_prefix(pycache_prefix):
|
with util.temporary_pycache_prefix(pycache_prefix):
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
self.util.cache_from_source(path, optimization=''),
|
self.util.cache_from_source(path, optimization=''),
|
||||||
expect)
|
os.path.normpath(expect))
|
||||||
|
|
||||||
@unittest.skipIf(sys.implementation.cache_tag is None,
|
@unittest.skipIf(sys.implementation.cache_tag is None,
|
||||||
'requires sys.implementation.cache_tag to not be None')
|
'requires sys.implementation.cache_tag to not be None')
|
||||||
|
|
|
@ -6,6 +6,7 @@ from importlib import machinery, util, invalidate_caches
|
||||||
import marshal
|
import marshal
|
||||||
import os
|
import os
|
||||||
import os.path
|
import os.path
|
||||||
|
from test import support
|
||||||
from test.support import import_helper
|
from test.support import import_helper
|
||||||
from test.support import os_helper
|
from test.support import os_helper
|
||||||
import unittest
|
import unittest
|
||||||
|
@ -22,25 +23,34 @@ if 'errno' in sys.builtin_module_names:
|
||||||
if 'importlib' not in sys.builtin_module_names:
|
if 'importlib' not in sys.builtin_module_names:
|
||||||
BUILTINS.bad_name = 'importlib'
|
BUILTINS.bad_name = 'importlib'
|
||||||
|
|
||||||
EXTENSIONS = types.SimpleNamespace()
|
if support.is_wasi:
|
||||||
EXTENSIONS.path = None
|
# dlopen() is a shim for WASI as of WASI SDK which fails by default.
|
||||||
EXTENSIONS.ext = None
|
# We don't provide an implementation, so tests will fail.
|
||||||
EXTENSIONS.filename = None
|
# But we also don't want to turn off dynamic loading for those that provide
|
||||||
EXTENSIONS.file_path = None
|
# a working implementation.
|
||||||
EXTENSIONS.name = '_testsinglephase'
|
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():
|
def _extension_details():
|
||||||
global EXTENSIONS
|
global EXTENSIONS
|
||||||
for path in sys.path:
|
for path in sys.path:
|
||||||
for ext in machinery.EXTENSION_SUFFIXES:
|
for ext in machinery.EXTENSION_SUFFIXES:
|
||||||
filename = EXTENSIONS.name + ext
|
filename = EXTENSIONS.name + ext
|
||||||
file_path = os.path.join(path, filename)
|
file_path = os.path.join(path, filename)
|
||||||
if os.path.exists(file_path):
|
if os.path.exists(file_path):
|
||||||
EXTENSIONS.path = path
|
EXTENSIONS.path = path
|
||||||
EXTENSIONS.ext = ext
|
EXTENSIONS.ext = ext
|
||||||
EXTENSIONS.filename = filename
|
EXTENSIONS.filename = filename
|
||||||
EXTENSIONS.file_path = file_path
|
EXTENSIONS.file_path = file_path
|
||||||
return
|
return
|
||||||
|
|
||||||
_extension_details()
|
_extension_details()
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Update test_importlib so that it passes under WASI SDK 21.
|
Loading…
Add table
Add a link
Reference in a new issue