summaryrefslogtreecommitdiff
path: root/Lib/test/test_zipfile.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2013-02-02 19:51:37 +0200
committerSerhiy Storchaka <storchaka@gmail.com>2013-02-02 19:51:37 +0200
commit6b8024d06809254436ac3896f78e97ff64786605 (patch)
tree3f66c9d7314e2a88a8cb23a3caf67505198af3dc /Lib/test/test_zipfile.py
parentded5851238977fbec689069b811ae8937ee198cb (diff)
parent9ace04ab878b2658b421cba2c65d5888b845a5d3 (diff)
downloadcpython-6b8024d06809254436ac3896f78e97ff64786605.tar.gz
Fix the test for issue #6972.
Remove trailing dots on Windows.
Diffstat (limited to 'Lib/test/test_zipfile.py')
-rw-r--r--Lib/test/test_zipfile.py22
1 files changed, 17 insertions, 5 deletions
diff --git a/Lib/test/test_zipfile.py b/Lib/test/test_zipfile.py
index 81e30368e0..c1e20b2865 100644
--- a/Lib/test/test_zipfile.py
+++ b/Lib/test/test_zipfile.py
@@ -548,8 +548,6 @@ class TestsWithSourceFile(unittest.TestCase):
('/foo/bar', 'foo/bar'),
('/foo/../bar', 'foo/bar'),
('/foo/../../bar', 'foo/bar'),
- ('//foo/bar', 'foo/bar'),
- ('../../foo../../ba..r', 'foo../ba..r'),
]
if os.path.sep == '\\': # Windows.
hacknames.extend([
@@ -571,19 +569,32 @@ class TestsWithSourceFile(unittest.TestCase):
(r'\\?\C:\foo\bar', 'foo/bar'),
(r'C:/../C:/foo/bar', 'C_/foo/bar'),
(r'a:b\c<d>e|f"g?h*i', 'b/c_d_e_f_g_h_i'),
+ ('../../foo../../ba..r', 'foo/ba..r'),
+ ])
+ else: # Unix
+ hacknames.extend([
+ ('//foo/bar', 'foo/bar'),
+ ('../../foo../../ba..r', 'foo../ba..r'),
+ (r'foo/..\bar', r'foo/..\bar'),
])
for arcname, fixedname in hacknames:
content = b'foobar' + arcname.encode()
with zipfile.ZipFile(TESTFN2, 'w', zipfile.ZIP_STORED) as zipfp:
- zipfp.writestr(arcname, content)
+ zinfo = zipfile.ZipInfo()
+ # preserve backslashes
+ zinfo.filename = arcname
+ zinfo.external_attr = 0o600 << 16
+ zipfp.writestr(zinfo, content)
+ arcname = arcname.replace(os.sep, "/")
targetpath = os.path.join('target', 'subdir', 'subsub')
correctfile = os.path.join(targetpath, *fixedname.split('/'))
with zipfile.ZipFile(TESTFN2, 'r') as zipfp:
writtenfile = zipfp.extract(arcname, targetpath)
- self.assertEqual(writtenfile, correctfile)
+ self.assertEqual(writtenfile, correctfile,
+ msg="extract %r" % arcname)
self.check_file(correctfile, content)
shutil.rmtree('target')
@@ -596,7 +607,8 @@ class TestsWithSourceFile(unittest.TestCase):
with zipfile.ZipFile(TESTFN2, 'r') as zipfp:
writtenfile = zipfp.extract(arcname)
- self.assertEqual(writtenfile, correctfile)
+ self.assertEqual(writtenfile, correctfile,
+ msg="extract %r" % arcname)
self.check_file(correctfile, content)
shutil.rmtree(fixedname.split('/')[0])