summaryrefslogtreecommitdiff
path: root/pkg_resources/tests/test_pkg_resources.py
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2017-12-24 19:18:59 -0600
committerGitHub <noreply@github.com>2017-12-24 19:18:59 -0600
commit1ad2c11ca1d8535c61215b184d18bf713ef813c9 (patch)
treed59aa23daa67db73200b82c7c39e1a117fd719c7 /pkg_resources/tests/test_pkg_resources.py
parente001996ab483c7c725e8894f560fb84c43150bcc (diff)
parent0d0baed8da468b2cedb9aa6caf60dc15fdeebd34 (diff)
downloadpython-setuptools-git-38.2.5.tar.gz
Merge pull request #1232 from duggelz/dgreiman/issue118838.2.5
Fix trailing slash handling in pkg_resources.ZipProvider
Diffstat (limited to 'pkg_resources/tests/test_pkg_resources.py')
-rw-r--r--pkg_resources/tests/test_pkg_resources.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/pkg_resources/tests/test_pkg_resources.py b/pkg_resources/tests/test_pkg_resources.py
index c6a7ac97..f2c00b29 100644
--- a/pkg_resources/tests/test_pkg_resources.py
+++ b/pkg_resources/tests/test_pkg_resources.py
@@ -62,10 +62,21 @@ class TestZipProvider(object):
zip_info.filename = 'data.dat'
zip_info.date_time = cls.ref_time.timetuple()
zip_egg.writestr(zip_info, 'hello, world!')
+ zip_info = zipfile.ZipInfo()
+ zip_info.filename = 'subdir/mod2.py'
+ zip_info.date_time = cls.ref_time.timetuple()
+ zip_egg.writestr(zip_info, 'x = 6\n')
+ zip_info = zipfile.ZipInfo()
+ zip_info.filename = 'subdir/data2.dat'
+ zip_info.date_time = cls.ref_time.timetuple()
+ zip_egg.writestr(zip_info, 'goodbye, world!')
zip_egg.close()
egg.close()
sys.path.append(egg.name)
+ subdir = os.path.join(egg.name, 'subdir')
+ sys.path.append(subdir)
+ cls.finalizers.append(EggRemover(subdir))
cls.finalizers.append(EggRemover(egg.name))
@classmethod
@@ -73,6 +84,30 @@ class TestZipProvider(object):
for finalizer in cls.finalizers:
finalizer()
+ def test_resource_listdir(self):
+ import mod
+ zp = pkg_resources.ZipProvider(mod)
+
+ expected_root = ['data.dat', 'mod.py', 'subdir']
+ assert sorted(zp.resource_listdir('')) == expected_root
+ assert sorted(zp.resource_listdir('/')) == expected_root
+
+ expected_subdir = ['data2.dat', 'mod2.py']
+ assert sorted(zp.resource_listdir('subdir')) == expected_subdir
+ assert sorted(zp.resource_listdir('subdir/')) == expected_subdir
+
+ assert zp.resource_listdir('nonexistent') == []
+ assert zp.resource_listdir('nonexistent/') == []
+
+ import mod2
+ zp2 = pkg_resources.ZipProvider(mod2)
+
+ assert sorted(zp2.resource_listdir('')) == expected_subdir
+ assert sorted(zp2.resource_listdir('/')) == expected_subdir
+
+ assert zp2.resource_listdir('subdir') == []
+ assert zp2.resource_listdir('subdir/') == []
+
def test_resource_filename_rewrites_on_change(self):
"""
If a previous call to get_resource_filename has saved the file, but