summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_zipfile.py
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2009-01-24 14:00:33 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2009-01-24 14:00:33 (GMT)
commit0dfcfc8b59610422def8ec49d2319ec51380e9fa (patch)
treefa998019852e76033d710bf901fc5586b5fcaa4c /Lib/test/test_zipfile.py
parent89e759d462ac9bb3463f5ff7a3f8e123af380edb (diff)
downloadcpython-0dfcfc8b59610422def8ec49d2319ec51380e9fa.zip
cpython-0dfcfc8b59610422def8ec49d2319ec51380e9fa.tar.gz
cpython-0dfcfc8b59610422def8ec49d2319ec51380e9fa.tar.bz2
Issue #4710: Extract directories properly in the zipfile module;
allow adding directories to a zipfile.
Diffstat (limited to 'Lib/test/test_zipfile.py')
-rw-r--r--Lib/test/test_zipfile.py26
1 files changed, 25 insertions, 1 deletions
diff --git a/Lib/test/test_zipfile.py b/Lib/test/test_zipfile.py
index 9cc5860..fcb55d1 100644
--- a/Lib/test/test_zipfile.py
+++ b/Lib/test/test_zipfile.py
@@ -11,9 +11,10 @@ from tempfile import TemporaryFile
from random import randint, random
import test.test_support as support
-from test.test_support import TESTFN, run_unittest
+from test.test_support import TESTFN, run_unittest, findfile
TESTFN2 = TESTFN + "2"
+TESTFNDIR = TESTFN + "d"
FIXEDTEST_SIZE = 1000
SMALL_TEST_DATA = [('_ziptest1', '1q2w3e4r5t'),
@@ -1011,6 +1012,28 @@ class TestsWithMultipleOpens(unittest.TestCase):
def tearDown(self):
os.remove(TESTFN2)
+class TestWithDirectory(unittest.TestCase):
+ def setUp(self):
+ os.mkdir(TESTFN2)
+
+ def testExtractDir(self):
+ zipf = zipfile.ZipFile(findfile("zipdir.zip"))
+ zipf.extractall(TESTFN2)
+ self.assertTrue(os.path.isdir(os.path.join(TESTFN2, "a")))
+ self.assertTrue(os.path.isdir(os.path.join(TESTFN2, "a", "b")))
+ self.assertTrue(os.path.exists(os.path.join(TESTFN2, "a", "b", "c")))
+
+ def testStoreDir(self):
+ os.mkdir(os.path.join(TESTFN2, "x"))
+ zipf = zipfile.ZipFile(TESTFN, "w")
+ zipf.write(os.path.join(TESTFN2, "x"), "x")
+ self.assertTrue(zipf.filelist[0].filename.endswith("x/"))
+
+ def tearDown(self):
+ shutil.rmtree(TESTFN2)
+ if os.path.exists(TESTFN):
+ os.remove(TESTFN)
+
class UniversalNewlineTests(unittest.TestCase):
def setUp(self):
@@ -1119,6 +1142,7 @@ class UniversalNewlineTests(unittest.TestCase):
def test_main():
run_unittest(TestsWithSourceFile, TestZip64InSmallFiles, OtherTests,
PyZipFileTests, DecryptionTests, TestsWithMultipleOpens,
+ TestWithDirectory,
UniversalNewlineTests, TestsWithRandomBinaryFiles)
if __name__ == "__main__":