ยปCore Development>Code coverage>Lib/test/test_importlib/builtin/test_finder.py

Python code coverage for Lib/test/test_importlib/builtin/test_finder.py

#countcontent
1n/afrom .. import abc
2n/afrom .. import util
3n/a
4n/amachinery = util.import_importlib('importlib.machinery')
5n/a
6n/aimport sys
7n/aimport unittest
8n/a
9n/a
10n/a@unittest.skipIf(util.BUILTINS.good_name is None, 'no reasonable builtin module')
11n/aclass FindSpecTests(abc.FinderTests):
12n/a
13n/a """Test find_spec() for built-in modules."""
14n/a
15n/a def test_module(self):
16n/a # Common case.
17n/a with util.uncache(util.BUILTINS.good_name):
18n/a found = self.machinery.BuiltinImporter.find_spec(util.BUILTINS.good_name)
19n/a self.assertTrue(found)
20n/a self.assertEqual(found.origin, 'built-in')
21n/a
22n/a # Built-in modules cannot be a package.
23n/a test_package = None
24n/a
25n/a # Built-in modules cannobt be in a package.
26n/a test_module_in_package = None
27n/a
28n/a # Built-in modules cannot be a package.
29n/a test_package_in_package = None
30n/a
31n/a # Built-in modules cannot be a package.
32n/a test_package_over_module = None
33n/a
34n/a def test_failure(self):
35n/a name = 'importlib'
36n/a assert name not in sys.builtin_module_names
37n/a spec = self.machinery.BuiltinImporter.find_spec(name)
38n/a self.assertIsNone(spec)
39n/a
40n/a def test_ignore_path(self):
41n/a # The value for 'path' should always trigger a failed import.
42n/a with util.uncache(util.BUILTINS.good_name):
43n/a spec = self.machinery.BuiltinImporter.find_spec(util.BUILTINS.good_name,
44n/a ['pkg'])
45n/a self.assertIsNone(spec)
46n/a
47n/a
48n/a(Frozen_FindSpecTests,
49n/a Source_FindSpecTests
50n/a ) = util.test_both(FindSpecTests, machinery=machinery)
51n/a
52n/a
53n/a@unittest.skipIf(util.BUILTINS.good_name is None, 'no reasonable builtin module')
54n/aclass FinderTests(abc.FinderTests):
55n/a
56n/a """Test find_module() for built-in modules."""
57n/a
58n/a def test_module(self):
59n/a # Common case.
60n/a with util.uncache(util.BUILTINS.good_name):
61n/a found = self.machinery.BuiltinImporter.find_module(util.BUILTINS.good_name)
62n/a self.assertTrue(found)
63n/a self.assertTrue(hasattr(found, 'load_module'))
64n/a
65n/a # Built-in modules cannot be a package.
66n/a test_package = test_package_in_package = test_package_over_module = None
67n/a
68n/a # Built-in modules cannot be in a package.
69n/a test_module_in_package = None
70n/a
71n/a def test_failure(self):
72n/a assert 'importlib' not in sys.builtin_module_names
73n/a loader = self.machinery.BuiltinImporter.find_module('importlib')
74n/a self.assertIsNone(loader)
75n/a
76n/a def test_ignore_path(self):
77n/a # The value for 'path' should always trigger a failed import.
78n/a with util.uncache(util.BUILTINS.good_name):
79n/a loader = self.machinery.BuiltinImporter.find_module(util.BUILTINS.good_name,
80n/a ['pkg'])
81n/a self.assertIsNone(loader)
82n/a
83n/a
84n/a(Frozen_FinderTests,
85n/a Source_FinderTests
86n/a ) = util.test_both(FinderTests, machinery=machinery)
87n/a
88n/a
89n/aif __name__ == '__main__':
90n/a unittest.main()