Tests the same as test_walkpackages_filesys, only with a zip file.
(self)
| 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.""" |
| 191 | |
| 192 | zip = 'test_walkpackages_zipfile.zip' |
| 193 | pkg1 = 'test_walkpackages_zipfile' |
| 194 | pkg2 = 'sub' |
| 195 | |
| 196 | zip_file = os.path.join(self.dirname, zip) |
| 197 | z = zipfile.ZipFile(zip_file, 'w') |
| 198 | z.writestr(pkg2 + '/__init__.py', "") |
| 199 | z.writestr(pkg2 + '/' + pkg1 + '/__init__.py', "") |
| 200 | z.writestr(pkg2 + '/' + pkg1 + '/mod.py', "") |
| 201 | z.writestr(pkg1 + '/__init__.py', "") |
| 202 | z.writestr(pkg1 + '/' + pkg2 + '/__init__.py', "") |
| 203 | z.writestr(pkg1 + '/' + pkg2 + '/mod.py', "") |
| 204 | z.close() |
| 205 | |
| 206 | sys.path.insert(0, zip_file) |
| 207 | expected = [ |
| 208 | 'sub', |
| 209 | 'sub.test_walkpackages_zipfile', |
| 210 | 'sub.test_walkpackages_zipfile.mod', |
| 211 | 'test_walkpackages_zipfile', |
| 212 | 'test_walkpackages_zipfile.sub', |
| 213 | 'test_walkpackages_zipfile.sub.mod', |
| 214 | ] |
| 215 | actual= [e[1] for e in pkgutil.walk_packages([zip_file])] |
| 216 | self.assertEqual(actual, expected) |
| 217 | del sys.path[0] |
| 218 | |
| 219 | for pkg in expected: |
| 220 | if pkg.endswith('mod'): |
| 221 | continue |
| 222 | del sys.modules[pkg] |
| 223 | |
| 224 | def test_walk_packages_raises_on_string_or_bytes_input(self): |
| 225 |