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