diff options
author | Martin v. Löwis <martin@v.loewis.de> | 2007-02-13 10:10:39 +0000 |
---|---|---|
committer | Martin v. Löwis <martin@v.loewis.de> | 2007-02-13 10:10:39 +0000 |
commit | 84f6de9d7e4a65089531699f1c6efc4e15d13dd2 (patch) | |
tree | f93cdaeb3b4d3ba7f5f0d41403f27da7800d7224 /Lib/test/test_zipfile.py | |
parent | c6d626ed9f49daf84e72c817bce274a3547325ad (diff) | |
download | cpython-git-84f6de9d7e4a65089531699f1c6efc4e15d13dd2.tar.gz |
Patch #1517891: Make 'a' create the file if it doesn't exist.
Fixes #1514451.
Diffstat (limited to 'Lib/test/test_zipfile.py')
-rw-r--r-- | Lib/test/test_zipfile.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/Lib/test/test_zipfile.py b/Lib/test/test_zipfile.py index 2d206df5c3..c17039f227 100644 --- a/Lib/test/test_zipfile.py +++ b/Lib/test/test_zipfile.py @@ -307,6 +307,28 @@ class PyZipFileTests(unittest.TestCase): class OtherTests(unittest.TestCase): + def testCreateNonExistentFileForAppend(self): + if os.path.exists(TESTFN): + os.unlink(TESTFN) + + filename = 'testfile.txt' + content = 'hello, world. this is some content.' + + try: + zf = zipfile.ZipFile(TESTFN, 'a') + zf.writestr(filename, content) + zf.close() + except IOError, (errno, errmsg): + self.fail('Could not append data to a non-existent zip file.') + + self.assert_(os.path.exists(TESTFN)) + + zf = zipfile.ZipFile(TESTFN, 'r') + self.assertEqual(zf.read(filename), content) + zf.close() + + os.unlink(TESTFN) + def testCloseErroneousFile(self): # This test checks that the ZipFile constructor closes the file object # it opens if there's an error in the file. If it doesn't, the traceback |