| 1 |
from test.test_importlib import abc, util |
| 2 |
|
| 3 |
machinery = util.import_importlib('importlib.machinery') |
| 4 |
|
| 5 |
import unittest |
| 6 |
import sys |
| 7 |
|
| 8 |
|
| 9 |
class FinderTests(abc.FinderTests): |
| 10 |
|
| 11 |
"""Test the finder for extension modules.""" |
| 12 |
|
| 13 |
def setUp(self): |
| 14 |
if not self.machinery.EXTENSION_SUFFIXES or not util.EXTENSIONS: |
| 15 |
raise unittest.SkipTest("Requires dynamic loading support.") |
| 16 |
if util.EXTENSIONS.name in sys.builtin_module_names: |
| 17 |
raise unittest.SkipTest( |
| 18 |
f"{util.EXTENSIONS.name} is a builtin module" |
| 19 |
) |
| 20 |
|
| 21 |
def find_spec(self, fullname): |
| 22 |
importer = self.machinery.FileFinder(util.EXTENSIONS.path, |
| 23 |
(self.machinery.ExtensionFileLoader, |
| 24 |
self.machinery.EXTENSION_SUFFIXES)) |
| 25 |
|
| 26 |
return importer.find_spec(fullname) |
| 27 |
|
| 28 |
def test_module(self): |
| 29 |
self.assertTrue(self.find_spec(util.EXTENSIONS.name)) |
| 30 |
|
| 31 |
|
| 32 |
test_package = test_package_in_package = None |
| 33 |
|
| 34 |
|
| 35 |
test_module_in_package = None |
| 36 |
|
| 37 |
|
| 38 |
test_package_over_module = None |
| 39 |
|
| 40 |
def test_failure(self): |
| 41 |
self.assertIsNone(self.find_spec('asdfjkl;')) |
| 42 |
|
| 43 |
|
| 44 |
(Frozen_FinderTests, |
| 45 |
Source_FinderTests |
| 46 |
) = util.test_both(FinderTests, machinery=machinery) |
| 47 |
|
| 48 |
|
| 49 |
if __name__ == '__main__': |
| 50 |
unittest.main() |