Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(174082)

Delta Between Two Patch Sets: Lib/test/test_importlib/test_spec.py

Issue 18864: Implementation for PEP 451 (importlib.machinery.ModuleSpec)
Left Patch Set: Created 5 years, 8 months ago
Right Patch Set: Created 5 years, 7 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « Lib/importlib/_bootstrap.py ('k') | Python/importlib.h » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 from . import util 1 from . import util
2 2
3 frozen_init, source_init = util.import_importlib('importlib') 3 frozen_init, source_init = util.import_importlib('importlib')
4 frozen_bootstrap = frozen_init._bootstrap 4 frozen_bootstrap = frozen_init._bootstrap
5 source_bootstrap = source_init._bootstrap 5 source_bootstrap = source_init._bootstrap
6 frozen_machinery, source_machinery = util.import_importlib('importlib.machinery' ) 6 frozen_machinery, source_machinery = util.import_importlib('importlib.machinery' )
7 frozen_util, source_util = util.import_importlib('importlib.util') 7 frozen_util, source_util = util.import_importlib('importlib.util')
8 8
9 import os.path 9 import os.path
10 from test.support import CleanImport 10 from test.support import CleanImport
11 import unittest 11 import unittest
12 import sys 12 import sys
13 import warnings
13 14
14 15
15 16
16 class TestLoader: 17 class TestLoader:
17 18
18 def __init__(self, path=None, is_package=None): 19 def __init__(self, path=None, is_package=None):
19 # if path: 20 # if path:
20 # if is_package: 21 # if is_package:
21 # if not path.endswith('.py'): 22 # if not path.endswith('.py'):
22 # path = os.path.join(path, '__init__.py') 23 # path = os.path.join(path, '__init__.py')
(...skipping 25 matching lines...) Expand all
48 EGGS = 1 49 EGGS = 1
49 50
50 def exec_module(self, module): 51 def exec_module(self, module):
51 module.eggs = self.EGGS 52 module.eggs = self.EGGS
52 53
53 54
54 class LegacyLoader(TestLoader): 55 class LegacyLoader(TestLoader):
55 56
56 HAM = -1 57 HAM = -1
57 58
58 @frozen_util.module_for_loader 59 with warnings.catch_warnings():
59 def load_module(self, module): 60 warnings.simplefilter("ignore", PendingDeprecationWarning)
60 module.ham = self.HAM 61
61 return module 62 @frozen_util.module_for_loader
63 def load_module(self, module):
64 module.ham = self.HAM
65 return module
62 66
63 67
64 class ModuleSpecTests: 68 class ModuleSpecTests:
65 69
66 def setUp(self): 70 def setUp(self):
67 self.name = 'spam' 71 self.name = 'spam'
68 self.path = 'spam.py' 72 self.path = 'spam.py'
69 self.cached = self.util.cache_from_source(self.path) 73 self.cached = self.util.cache_from_source(self.path)
70 self.loader = TestLoader() 74 self.loader = TestLoader()
71 self.spec = self.machinery.ModuleSpec(self.name, self.loader) 75 self.spec = self.machinery.ModuleSpec(self.name, self.loader)
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 spec = self.machinery.ModuleSpec(self.name, self.loader, 115 spec = self.machinery.ModuleSpec(self.name, self.loader,
112 is_package=True) 116 is_package=True)
113 117
114 self.assertEqual(spec.name, self.name) 118 self.assertEqual(spec.name, self.name)
115 self.assertEqual(spec.loader, self.loader) 119 self.assertEqual(spec.loader, self.loader)
116 self.assertIs(spec.origin, None) 120 self.assertIs(spec.origin, None)
117 self.assertIs(spec.loader_state, None) 121 self.assertIs(spec.loader_state, None)
118 self.assertEqual(spec.submodule_search_locations, []) 122 self.assertEqual(spec.submodule_search_locations, [])
119 self.assertIs(spec.cached, None) 123 self.assertIs(spec.cached, None)
120 self.assertFalse(spec.has_location) 124 self.assertFalse(spec.has_location)
125
126 def test_has_location_setter(self):
127 spec = self.machinery.ModuleSpec(self.name, self.loader,
128 origin='somewhere')
129 self.assertFalse(spec.has_location)
130 spec.has_location = True
131 self.assertTrue(spec.has_location)
132
133 def test_equality(self):
134 other = type(sys.implementation)(name=self.name,
135 loader=self.loader,
136 origin=None,
137 submodule_search_locations=None,
138 has_location=False,
139 cached=None,
140 )
141
142 self.assertTrue(self.spec == other)
143
144 def test_equality_location(self):
145 other = type(sys.implementation)(name=self.name,
146 loader=self.loader,
147 origin=self.path,
148 submodule_search_locations=None,
149 has_location=True,
150 cached=self.cached,
151 )
152
153 self.assertEqual(self.loc_spec, other)
154
155 def test_inequality(self):
156 other = type(sys.implementation)(name='ham',
157 loader=self.loader,
158 origin=None,
159 submodule_search_locations=None,
160 has_location=False,
161 cached=None,
162 )
163
164 self.assertNotEqual(self.spec, other)
165
166 def test_inequality_incomplete(self):
167 other = type(sys.implementation)(name=self.name,
168 loader=self.loader,
169 )
170
171 self.assertNotEqual(self.spec, other)
121 172
122 def test_package(self): 173 def test_package(self):
123 spec = self.machinery.ModuleSpec('spam.eggs', self.loader) 174 spec = self.machinery.ModuleSpec('spam.eggs', self.loader)
124 175
125 self.assertEqual(spec.parent, 'spam') 176 self.assertEqual(spec.parent, 'spam')
126 177
127 def test_package_is_package(self): 178 def test_package_is_package(self):
128 spec = self.machinery.ModuleSpec('spam.eggs', self.loader, 179 spec = self.machinery.ModuleSpec('spam.eggs', self.loader,
129 is_package=True) 180 is_package=True)
130 181
(...skipping 788 matching lines...) Expand 10 before | Expand all | Expand 10 after
919 970
920 971
921 class Frozen_FactoryTests(FactoryTests, unittest.TestCase): 972 class Frozen_FactoryTests(FactoryTests, unittest.TestCase):
922 util = frozen_util 973 util = frozen_util
923 machinery = frozen_machinery 974 machinery = frozen_machinery
924 975
925 976
926 class Source_FactoryTests(FactoryTests, unittest.TestCase): 977 class Source_FactoryTests(FactoryTests, unittest.TestCase):
927 util = source_util 978 util = source_util
928 machinery = source_machinery 979 machinery = source_machinery
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+