MCPcopy Index your code
hub / github.com/python/cpython / test_walkpackages_filesys

Method test_walkpackages_filesys

Lib/test/test_pkgutil.py:149–187  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

147 self.fail("unexpected package found")
148
149 def test_walkpackages_filesys(self):
150 pkg1 = 'test_walkpackages_filesys'
151 pkg1_dir = os.path.join(self.dirname, pkg1)
152 os.mkdir(pkg1_dir)
153 f = open(os.path.join(pkg1_dir, '__init__.py'), "wb")
154 f.close()
155 os.mkdir(os.path.join(pkg1_dir, 'sub'))
156 f = open(os.path.join(pkg1_dir, 'sub', '__init__.py'), "wb")
157 f.close()
158 f = open(os.path.join(pkg1_dir, 'sub', 'mod.py'), "wb")
159 f.close()
160
161 # Now, to juice it up, let's add the opposite packages, too.
162 pkg2 = 'sub'
163 pkg2_dir = os.path.join(self.dirname, pkg2)
164 os.mkdir(pkg2_dir)
165 f = open(os.path.join(pkg2_dir, '__init__.py'), "wb")
166 f.close()
167 os.mkdir(os.path.join(pkg2_dir, 'test_walkpackages_filesys'))
168 f = open(os.path.join(pkg2_dir, 'test_walkpackages_filesys', '__init__.py'), "wb")
169 f.close()
170 f = open(os.path.join(pkg2_dir, 'test_walkpackages_filesys', 'mod.py'), "wb")
171 f.close()
172
173 expected = [
174 'sub',
175 'sub.test_walkpackages_filesys',
176 'sub.test_walkpackages_filesys.mod',
177 'test_walkpackages_filesys',
178 'test_walkpackages_filesys.sub',
179 'test_walkpackages_filesys.sub.mod',
180 ]
181 actual= [e[1] for e in pkgutil.walk_packages([self.dirname])]
182 self.assertEqual(actual, expected)
183
184 for pkg in expected:
185 if pkg.endswith('mod'):
186 continue
187 del sys.modules[pkg]
188
189 def test_walkpackages_zipfile(self):
190 """Tests the same as test_walkpackages_filesys, only with a zip file."""

Callers

nothing calls this directly

Calls 6

openFunction · 0.50
joinMethod · 0.45
mkdirMethod · 0.45
closeMethod · 0.45
assertEqualMethod · 0.45
endswithMethod · 0.45

Tested by

no test coverage detected