| 1 | n/a | from importlib import machinery |
|---|
| 2 | n/a | from .. import abc |
|---|
| 3 | n/a | from .. import util |
|---|
| 4 | n/a | from . import util as builtin_util |
|---|
| 5 | n/a | |
|---|
| 6 | n/a | import sys |
|---|
| 7 | n/a | import unittest |
|---|
| 8 | n/a | |
|---|
| 9 | n/a | class FinderTests(abc.FinderTests): |
|---|
| 10 | n/a | |
|---|
| 11 | n/a | """Test find_module() for built-in modules.""" |
|---|
| 12 | n/a | |
|---|
| 13 | n/a | def test_module(self): |
|---|
| 14 | n/a | # Common case. |
|---|
| 15 | n/a | with util.uncache(builtin_util.NAME): |
|---|
| 16 | n/a | found = machinery.BuiltinImporter.find_module(builtin_util.NAME) |
|---|
| 17 | n/a | self.assertTrue(found) |
|---|
| 18 | n/a | |
|---|
| 19 | n/a | def test_package(self): |
|---|
| 20 | n/a | # Built-in modules cannot be a package. |
|---|
| 21 | n/a | pass |
|---|
| 22 | n/a | |
|---|
| 23 | n/a | def test_module_in_package(self): |
|---|
| 24 | n/a | # Built-in modules cannobt be in a package. |
|---|
| 25 | n/a | pass |
|---|
| 26 | n/a | |
|---|
| 27 | n/a | def test_package_in_package(self): |
|---|
| 28 | n/a | # Built-in modules cannot be a package. |
|---|
| 29 | n/a | pass |
|---|
| 30 | n/a | |
|---|
| 31 | n/a | def test_package_over_module(self): |
|---|
| 32 | n/a | # Built-in modules cannot be a package. |
|---|
| 33 | n/a | pass |
|---|
| 34 | n/a | |
|---|
| 35 | n/a | def test_failure(self): |
|---|
| 36 | n/a | assert 'importlib' not in sys.builtin_module_names |
|---|
| 37 | n/a | loader = machinery.BuiltinImporter.find_module('importlib') |
|---|
| 38 | n/a | self.assertIsNone(loader) |
|---|
| 39 | n/a | |
|---|
| 40 | n/a | def test_ignore_path(self): |
|---|
| 41 | n/a | # The value for 'path' should always trigger a failed import. |
|---|
| 42 | n/a | with util.uncache(builtin_util.NAME): |
|---|
| 43 | n/a | loader = machinery.BuiltinImporter.find_module(builtin_util.NAME, |
|---|
| 44 | n/a | ['pkg']) |
|---|
| 45 | n/a | self.assertIsNone(loader) |
|---|
| 46 | n/a | |
|---|
| 47 | n/a | |
|---|
| 48 | n/a | |
|---|
| 49 | n/a | def test_main(): |
|---|
| 50 | n/a | from test.support import run_unittest |
|---|
| 51 | n/a | run_unittest(FinderTests) |
|---|
| 52 | n/a | |
|---|
| 53 | n/a | |
|---|
| 54 | n/a | if __name__ == '__main__': |
|---|
| 55 | n/a | test_main() |
|---|