2009-01-22 23:43:07 +01:00
|
|
|
from importlib import machinery
|
2009-01-30 01:22:35 +01:00
|
|
|
from .. import abc
|
2009-02-01 05:00:05 +01:00
|
|
|
from .. import util
|
2009-01-18 01:24:28 +01:00
|
|
|
|
|
|
|
import sys
|
|
|
|
import unittest
|
|
|
|
|
2009-01-30 01:22:35 +01:00
|
|
|
class FinderTests(abc.FinderTests):
|
2009-01-18 01:24:28 +01:00
|
|
|
|
|
|
|
"""Test find_module() for built-in modules."""
|
|
|
|
|
|
|
|
assert 'errno' in sys.builtin_module_names
|
|
|
|
name = 'errno'
|
|
|
|
|
2009-01-27 02:41:57 +01:00
|
|
|
def test_module(self):
|
2009-01-18 01:24:28 +01:00
|
|
|
# Common case.
|
2009-02-01 05:00:05 +01:00
|
|
|
with util.uncache(self.name):
|
2009-01-27 02:41:57 +01:00
|
|
|
self.assert_(machinery.BuiltinImporter.find_module(self.name))
|
|
|
|
|
|
|
|
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')
|
|
|
|
self.assert_(loader is None)
|
2009-01-18 01:24:28 +01:00
|
|
|
|
|
|
|
def test_ignore_path(self):
|
|
|
|
# The value for 'path' should always trigger a failed import.
|
2009-02-01 05:00:05 +01:00
|
|
|
with util.uncache(self.name):
|
2009-01-27 02:41:57 +01:00
|
|
|
loader = machinery.BuiltinImporter.find_module(self.name, ['pkg'])
|
|
|
|
self.assert_(loader is None)
|
2009-01-18 01:24:28 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_main():
|
|
|
|
from test.support import run_unittest
|
|
|
|
run_unittest(FinderTests)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
test_main()
|