cpython/Lib/test/test_importlib/extension/test_path_hook.py
Miss Islington (bot) 0cc504771f
[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>
2024-03-13 21:31:09 +00:00

33 lines
1 KiB
Python

from test.test_importlib import util
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."""
# XXX Should it only succeed for pre-existing directories?
# XXX Should it only work for directories containing an extension module?
def hook(self, entry):
return self.machinery.FileFinder.path_hook(
(self.machinery.ExtensionFileLoader,
self.machinery.EXTENSION_SUFFIXES))(entry)
def test_success(self):
# Path hook should handle a directory where a known extension module
# exists.
self.assertTrue(hasattr(self.hook(util.EXTENSIONS.path), 'find_spec'))
(Frozen_PathHooksTests,
Source_PathHooksTests
) = util.test_both(PathHookTests, machinery=machinery)
if __name__ == '__main__':
unittest.main()