| 1 |
from test.test_importlib import abc, util |
| 2 |
|
| 3 |
machinery = util.import_importlib('importlib.machinery') |
| 4 |
|
| 5 |
import sys |
| 6 |
import unittest |
| 7 |
import warnings |
| 8 |
|
| 9 |
|
| 10 |
@unittest.skipIf(util.BUILTINS.good_name is None, 'no reasonable builtin module') |
| 11 |
class FindSpecTests(abc.FinderTests): |
| 12 |
|
| 13 |
"""Test find_spec() for built-in modules.""" |
| 14 |
|
| 15 |
def test_module(self): |
| 16 |
|
| 17 |
with util.uncache(util.BUILTINS.good_name): |
| 18 |
found = self.machinery.BuiltinImporter.find_spec(util.BUILTINS.good_name) |
| 19 |
self.assertTrue(found) |
| 20 |
self.assertEqual(found.origin, 'built-in') |
| 21 |
|
| 22 |
|
| 23 |
test_package = None |
| 24 |
|
| 25 |
|
| 26 |
test_module_in_package = None |
| 27 |
|
| 28 |
|
| 29 |
test_package_in_package = None |
| 30 |
|
| 31 |
|
| 32 |
test_package_over_module = None |
| 33 |
|
| 34 |
def test_failure(self): |
| 35 |
name = 'importlib' |
| 36 |
assert name not in sys.builtin_module_names |
| 37 |
spec = self.machinery.BuiltinImporter.find_spec(name) |
| 38 |
self.assertIsNone(spec) |
| 39 |
|
| 40 |
|
| 41 |
(Frozen_FindSpecTests, |
| 42 |
Source_FindSpecTests |
| 43 |
) = util.test_both(FindSpecTests, machinery=machinery) |
| 44 |
|
| 45 |
|
| 46 |
@unittest.skipIf(util.BUILTINS.good_name is None, 'no reasonable builtin module') |
| 47 |
class FinderTests(abc.FinderTests): |
| 48 |
|
| 49 |
"""Test find_module() for built-in modules.""" |
| 50 |
|
| 51 |
def test_module(self): |
| 52 |
|
| 53 |
with util.uncache(util.BUILTINS.good_name): |
| 54 |
with warnings.catch_warnings(): |
| 55 |
warnings.simplefilter("ignore", DeprecationWarning) |
| 56 |
found = self.machinery.BuiltinImporter.find_module(util.BUILTINS.good_name) |
| 57 |
self.assertTrue(found) |
| 58 |
self.assertTrue(hasattr(found, 'load_module')) |
| 59 |
|
| 60 |
|
| 61 |
test_package = test_package_in_package = test_package_over_module = None |
| 62 |
|
| 63 |
|
| 64 |
test_module_in_package = None |
| 65 |
|
| 66 |
def test_failure(self): |
| 67 |
assert 'importlib' not in sys.builtin_module_names |
| 68 |
with warnings.catch_warnings(): |
| 69 |
warnings.simplefilter("ignore", DeprecationWarning) |
| 70 |
loader = self.machinery.BuiltinImporter.find_module('importlib') |
| 71 |
self.assertIsNone(loader) |
| 72 |
|
| 73 |
|
| 74 |
(Frozen_FinderTests, |
| 75 |
Source_FinderTests |
| 76 |
) = util.test_both(FinderTests, machinery=machinery) |
| 77 |
|
| 78 |
|
| 79 |
if __name__ == '__main__': |
| 80 |
unittest.main() |