2009-01-22 18:43:07 -04:00
|
|
|
from importlib import machinery
|
2009-01-29 20:22:35 -04:00
|
|
|
from .. import abc
|
2009-02-01 00:00:05 -04:00
|
|
|
from .. import util
|
2009-03-14 22:41:33 -03:00
|
|
|
from . import util as builtin_util
|
2009-01-17 20:24:28 -04:00
|
|
|
|
|
|
|
import sys
|
|
|
|
import unittest
|
|
|
|
|
2009-01-29 20:22:35 -04:00
|
|
|
class FinderTests(abc.FinderTests):
|
2009-01-17 20:24:28 -04:00
|
|
|
|
|
|
|
"""Test find_module() for built-in modules."""
|
|
|
|
|
2009-01-26 21:41:57 -04:00
|
|
|
def test_module(self):
|
2009-01-17 20:24:28 -04:00
|
|
|
# Common case.
|
2009-03-14 22:41:33 -03:00
|
|
|
with util.uncache(builtin_util.NAME):
|
|
|
|
found = machinery.BuiltinImporter.find_module(builtin_util.NAME)
|
2009-08-13 05:51:18 -03:00
|
|
|
self.assertTrue(found)
|
2009-01-26 21:41:57 -04:00
|
|
|
|
|
|
|
def test_package(self):
|
|
|
|
# Built-in modules cannot be a package.
|
|
|
|
pass
|
|
|
|
|
|
|
|
def test_module_in_package(self):
|
|
|
|
# Built-in modules cannobt be in a package.
|
|
|
|
pass
|
|
|
|
|
|
|
|
def test_package_in_package(self):
|
|
|
|
# Built-in modules cannot be a package.
|
|
|
|
pass
|
|
|
|
|
|
|
|
def test_package_over_module(self):
|
|
|
|
# Built-in modules cannot be a package.
|
|
|
|
pass
|
|
|
|
|
|
|
|
def test_failure(self):
|
|
|
|
assert 'importlib' not in sys.builtin_module_names
|
|
|
|
loader = machinery.BuiltinImporter.find_module('importlib')
|
2009-08-13 05:51:18 -03:00
|
|
|
self.assertTrue(loader is None)
|
2009-01-17 20:24:28 -04:00
|
|
|
|
|
|
|
def test_ignore_path(self):
|
|
|
|
# The value for 'path' should always trigger a failed import.
|
2009-03-14 22:41:33 -03:00
|
|
|
with util.uncache(builtin_util.NAME):
|
|
|
|
loader = machinery.BuiltinImporter.find_module(builtin_util.NAME,
|
|
|
|
['pkg'])
|
2009-08-13 05:51:18 -03:00
|
|
|
self.assertTrue(loader is None)
|
2009-01-17 20:24:28 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_main():
|
|
|
|
from test.support import run_unittest
|
|
|
|
run_unittest(FinderTests)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
test_main()
|