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

Python code coverage for Lib/test/test_importlib/frozen/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 unittest
7n/a
8n/a
9n/aclass FindSpecTests(abc.FinderTests):
10n/a
11n/a """Test finding frozen modules."""
12n/a
13n/a def find(self, name, path=None):
14n/a finder = self.machinery.FrozenImporter
15n/a return finder.find_spec(name, path)
16n/a
17n/a def test_module(self):
18n/a name = '__hello__'
19n/a spec = self.find(name)
20n/a self.assertEqual(spec.origin, 'frozen')
21n/a
22n/a def test_package(self):
23n/a spec = self.find('__phello__')
24n/a self.assertIsNotNone(spec)
25n/a
26n/a def test_module_in_package(self):
27n/a spec = self.find('__phello__.spam', ['__phello__'])
28n/a self.assertIsNotNone(spec)
29n/a
30n/a # No frozen package within another package to test with.
31n/a test_package_in_package = None
32n/a
33n/a # No easy way to test.
34n/a test_package_over_module = None
35n/a
36n/a def test_failure(self):
37n/a spec = self.find('<not real>')
38n/a self.assertIsNone(spec)
39n/a
40n/a
41n/a(Frozen_FindSpecTests,
42n/a Source_FindSpecTests
43n/a ) = util.test_both(FindSpecTests, machinery=machinery)
44n/a
45n/a
46n/aclass FinderTests(abc.FinderTests):
47n/a
48n/a """Test finding frozen modules."""
49n/a
50n/a def find(self, name, path=None):
51n/a finder = self.machinery.FrozenImporter
52n/a return finder.find_module(name, path)
53n/a
54n/a def test_module(self):
55n/a name = '__hello__'
56n/a loader = self.find(name)
57n/a self.assertTrue(hasattr(loader, 'load_module'))
58n/a
59n/a def test_package(self):
60n/a loader = self.find('__phello__')
61n/a self.assertTrue(hasattr(loader, 'load_module'))
62n/a
63n/a def test_module_in_package(self):
64n/a loader = self.find('__phello__.spam', ['__phello__'])
65n/a self.assertTrue(hasattr(loader, 'load_module'))
66n/a
67n/a # No frozen package within another package to test with.
68n/a test_package_in_package = None
69n/a
70n/a # No easy way to test.
71n/a test_package_over_module = None
72n/a
73n/a def test_failure(self):
74n/a loader = self.find('<not real>')
75n/a self.assertIsNone(loader)
76n/a
77n/a
78n/a(Frozen_FinderTests,
79n/a Source_FinderTests
80n/a ) = util.test_both(FinderTests, machinery=machinery)
81n/a
82n/a
83n/aif __name__ == '__main__':
84n/a unittest.main()