• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1from test.test_importlib import abc, util
2
3machinery = util.import_importlib('importlib.machinery')
4
5import sys
6import unittest
7
8
9@unittest.skipIf(util.BUILTINS.good_name is None, 'no reasonable builtin module')
10class FindSpecTests(abc.FinderTests):
11
12    """Test find_spec() for built-in modules."""
13
14    def test_module(self):
15        # Common case.
16        with util.uncache(util.BUILTINS.good_name):
17            found = self.machinery.BuiltinImporter.find_spec(util.BUILTINS.good_name)
18            self.assertTrue(found)
19            self.assertEqual(found.origin, 'built-in')
20
21    # Built-in modules cannot be a package.
22    test_package = None
23
24    # Built-in modules cannot be in a package.
25    test_module_in_package = None
26
27    # Built-in modules cannot be a package.
28    test_package_in_package = None
29
30    # Built-in modules cannot be a package.
31    test_package_over_module = None
32
33    def test_failure(self):
34        name = 'importlib'
35        assert name not in sys.builtin_module_names
36        spec = self.machinery.BuiltinImporter.find_spec(name)
37        self.assertIsNone(spec)
38
39
40(Frozen_FindSpecTests,
41 Source_FindSpecTests
42 ) = util.test_both(FindSpecTests, machinery=machinery)
43
44
45if __name__ == '__main__':
46    unittest.main()
47