cpython: 9649acf7d472 (original) (raw)
--- a/Lib/pkgutil.py +++ b/Lib/pkgutil.py @@ -375,7 +375,7 @@ try: if len(fn)==2 and fn[1].startswith('init.py'): if fn[0] not in yielded: yielded[fn[0]] = 1
yield fn[0], True[](#l1.7)
yield prefix + fn[0], True[](#l1.8)
--- a/Lib/test/test_pkgutil.py +++ b/Lib/test/test_pkgutil.py @@ -7,7 +7,6 @@ import pkgutil import os import os.path import tempfile -import types import shutil import zipfile @@ -101,6 +100,83 @@ class PkgutilTests(unittest.TestCase): for t in pkgutil.walk_packages(path=[self.dirname]): self.fail("unexpected package found")
- def test_walkpackages_filesys(self):
pkg1 = 'test_walkpackages_filesys'[](#l2.16)
pkg1_dir = os.path.join(self.dirname, pkg1)[](#l2.17)
os.mkdir(pkg1_dir)[](#l2.18)
f = open(os.path.join(pkg1_dir, '__init__.py'), "wb")[](#l2.19)
f.close()[](#l2.20)
os.mkdir(os.path.join(pkg1_dir, 'sub'))[](#l2.21)
f = open(os.path.join(pkg1_dir, 'sub', '__init__.py'), "wb")[](#l2.22)
f.close()[](#l2.23)
f = open(os.path.join(pkg1_dir, 'sub', 'mod.py'), "wb")[](#l2.24)
f.close()[](#l2.25)
# Now, to juice it up, let's add the opposite packages, too.[](#l2.27)
pkg2 = 'sub'[](#l2.28)
pkg2_dir = os.path.join(self.dirname, pkg2)[](#l2.29)
os.mkdir(pkg2_dir)[](#l2.30)
f = open(os.path.join(pkg2_dir, '__init__.py'), "wb")[](#l2.31)
f.close()[](#l2.32)
os.mkdir(os.path.join(pkg2_dir, 'test_walkpackages_filesys'))[](#l2.33)
f = open(os.path.join(pkg2_dir, 'test_walkpackages_filesys', '__init__.py'), "wb")[](#l2.34)
f.close()[](#l2.35)
f = open(os.path.join(pkg2_dir, 'test_walkpackages_filesys', 'mod.py'), "wb")[](#l2.36)
f.close()[](#l2.37)
expected = [[](#l2.39)
'sub',[](#l2.40)
'sub.test_walkpackages_filesys',[](#l2.41)
'sub.test_walkpackages_filesys.mod',[](#l2.42)
'test_walkpackages_filesys',[](#l2.43)
'test_walkpackages_filesys.sub',[](#l2.44)
'test_walkpackages_filesys.sub.mod',[](#l2.45)
][](#l2.46)
actual= [e[1] for e in pkgutil.walk_packages([self.dirname])][](#l2.47)
self.assertEqual(actual, expected)[](#l2.48)
for pkg in expected:[](#l2.50)
if pkg.endswith('mod'):[](#l2.51)
continue[](#l2.52)
del sys.modules[pkg][](#l2.53)
- def test_walkpackages_zipfile(self):
"""Tests the same as test_walkpackages_filesys, only with a zip file."""[](#l2.56)
zip = 'test_walkpackages_zipfile.zip'[](#l2.58)
pkg1 = 'test_walkpackages_zipfile'[](#l2.59)
pkg2 = 'sub'[](#l2.60)
zip_file = os.path.join(self.dirname, zip)[](#l2.62)
z = zipfile.ZipFile(zip_file, 'w')[](#l2.63)
z.writestr(pkg2 + '/__init__.py', "")[](#l2.64)
z.writestr(pkg2 + '/' + pkg1 + '/__init__.py', "")[](#l2.65)
z.writestr(pkg2 + '/' + pkg1 + '/mod.py', "")[](#l2.66)
z.writestr(pkg1 + '/__init__.py', "")[](#l2.67)
z.writestr(pkg1 + '/' + pkg2 + '/__init__.py', "")[](#l2.68)
z.writestr(pkg1 + '/' + pkg2 + '/mod.py', "")[](#l2.69)
z.close()[](#l2.70)
sys.path.insert(0, zip_file)[](#l2.72)
expected = [[](#l2.73)
'sub',[](#l2.74)
'sub.test_walkpackages_zipfile',[](#l2.75)
'sub.test_walkpackages_zipfile.mod',[](#l2.76)
'test_walkpackages_zipfile',[](#l2.77)
'test_walkpackages_zipfile.sub',[](#l2.78)
'test_walkpackages_zipfile.sub.mod',[](#l2.79)
][](#l2.80)
actual= [e[1] for e in pkgutil.walk_packages([zip_file])][](#l2.81)
self.assertEqual(actual, expected)[](#l2.82)
del sys.path[0][](#l2.83)
for pkg in expected:[](#l2.85)
if pkg.endswith('mod'):[](#l2.86)
continue[](#l2.87)
del sys.modules[pkg][](#l2.88)
+ + + class PkgutilPEP302Tests(unittest.TestCase): class MyTestLoader(object): @@ -324,11 +400,11 @@ class ImportlibMigrationTests(unittest.T def test_importer_deprecated(self): with self.check_deprecated():
x = pkgutil.ImpImporter("")[](#l2.99)
pkgutil.ImpImporter("")[](#l2.100)
def test_loader_deprecated(self): with self.check_deprecated():
x = pkgutil.ImpLoader("", "", "", "")[](#l2.104)
pkgutil.ImpLoader("", "", "", "")[](#l2.105)
def test_get_loader_avoids_emulation(self): with check_warnings() as w:
--- a/Misc/ACKS +++ b/Misc/ACKS @@ -1137,6 +1137,7 @@ Geoff Philbrick Gavrie Philipson Adrian Phillips Christopher J. Phoenix +James Pickering Neale Pickett Jim St. Pierre Dan Pierson