ยปCore Development>Code coverage>Lib/test/test_importlib/import_/test___loader__.py

Python code coverage for Lib/test/test_importlib/import_/test___loader__.py

#countcontent
1n/afrom importlib import machinery
2n/aimport sys
3n/aimport types
4n/aimport unittest
5n/a
6n/afrom .. import util
7n/a
8n/a
9n/aclass SpecLoaderMock:
10n/a
11n/a def find_spec(self, fullname, path=None, target=None):
12n/a return machinery.ModuleSpec(fullname, self)
13n/a
14n/a def create_module(self, spec):
15n/a return None
16n/a
17n/a def exec_module(self, module):
18n/a pass
19n/a
20n/a
21n/aclass SpecLoaderAttributeTests:
22n/a
23n/a def test___loader__(self):
24n/a loader = SpecLoaderMock()
25n/a with util.uncache('blah'), util.import_state(meta_path=[loader]):
26n/a module = self.__import__('blah')
27n/a self.assertEqual(loader, module.__loader__)
28n/a
29n/a
30n/a(Frozen_SpecTests,
31n/a Source_SpecTests
32n/a ) = util.test_both(SpecLoaderAttributeTests, __import__=util.__import__)
33n/a
34n/a
35n/aclass LoaderMock:
36n/a
37n/a def find_module(self, fullname, path=None):
38n/a return self
39n/a
40n/a def load_module(self, fullname):
41n/a sys.modules[fullname] = self.module
42n/a return self.module
43n/a
44n/a
45n/aclass LoaderAttributeTests:
46n/a
47n/a def test___loader___missing(self):
48n/a module = types.ModuleType('blah')
49n/a try:
50n/a del module.__loader__
51n/a except AttributeError:
52n/a pass
53n/a loader = LoaderMock()
54n/a loader.module = module
55n/a with util.uncache('blah'), util.import_state(meta_path=[loader]):
56n/a module = self.__import__('blah')
57n/a self.assertEqual(loader, module.__loader__)
58n/a
59n/a def test___loader___is_None(self):
60n/a module = types.ModuleType('blah')
61n/a module.__loader__ = None
62n/a loader = LoaderMock()
63n/a loader.module = module
64n/a with util.uncache('blah'), util.import_state(meta_path=[loader]):
65n/a returned_module = self.__import__('blah')
66n/a self.assertEqual(loader, module.__loader__)
67n/a
68n/a
69n/a(Frozen_Tests,
70n/a Source_Tests
71n/a ) = util.test_both(LoaderAttributeTests, __import__=util.__import__)
72n/a
73n/a
74n/aif __name__ == '__main__':
75n/a unittest.main()