mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
Merged revisions 59822-59841 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r59822 | georg.brandl | 2008-01-07 17:43:47 +0100 (Mon, 07 Jan 2008) | 2 lines Restore "somenamedtuple" as the "class" for named tuple attrs. ........ r59824 | georg.brandl | 2008-01-07 18:09:35 +0100 (Mon, 07 Jan 2008) | 2 lines Patch #602345 by Neal Norwitz and me: add -B option and PYTHONDONTWRITEBYTECODE envvar to skip writing bytecode. ........ r59827 | georg.brandl | 2008-01-07 18:25:53 +0100 (Mon, 07 Jan 2008) | 2 lines patch #1668: clarify envvar docs; rename THREADDEBUG to PYTHONTHREADDEBUG. ........ r59830 | georg.brandl | 2008-01-07 19:16:36 +0100 (Mon, 07 Jan 2008) | 2 lines Make Python compile with --disable-unicode. ........ r59831 | georg.brandl | 2008-01-07 19:23:27 +0100 (Mon, 07 Jan 2008) | 2 lines Restructure urllib doc structure. ........ r59833 | georg.brandl | 2008-01-07 19:41:34 +0100 (Mon, 07 Jan 2008) | 2 lines Fix #define ordering. ........ r59834 | georg.brandl | 2008-01-07 19:47:44 +0100 (Mon, 07 Jan 2008) | 2 lines #467924, patch by Alan McIntyre: Add ZipFile.extract and ZipFile.extractall. ........ r59835 | raymond.hettinger | 2008-01-07 19:52:19 +0100 (Mon, 07 Jan 2008) | 1 line Fix inconsistent title levels -- it made the whole doc build crash horribly. ........ r59836 | georg.brandl | 2008-01-07 19:57:03 +0100 (Mon, 07 Jan 2008) | 2 lines Fix two further doc build warnings. ........ r59837 | georg.brandl | 2008-01-07 20:17:10 +0100 (Mon, 07 Jan 2008) | 2 lines Clarify metaclass docs and add example. ........ r59838 | vinay.sajip | 2008-01-07 20:40:10 +0100 (Mon, 07 Jan 2008) | 1 line Added section about adding contextual information to log output. ........ r59839 | christian.heimes | 2008-01-07 20:58:41 +0100 (Mon, 07 Jan 2008) | 1 line Fixed indention problem that caused the second TIPC test to run on systems without TIPC ........ r59840 | raymond.hettinger | 2008-01-07 21:07:38 +0100 (Mon, 07 Jan 2008) | 1 line Cleanup named tuple subclassing example. ........
This commit is contained in:
parent
0625e89771
commit
790c823201
21 changed files with 1293 additions and 122 deletions
|
@ -14,6 +14,11 @@ from test.test_support import TESTFN, run_unittest
|
|||
TESTFN2 = TESTFN + "2"
|
||||
FIXEDTEST_SIZE = 1000
|
||||
|
||||
SMALL_TEST_DATA = [('_ziptest1', '1q2w3e4r5t'),
|
||||
('ziptest2dir/_ziptest2', 'qawsedrftg'),
|
||||
('/ziptest2dir/ziptest3dir/_ziptest3', 'azsxdcfvgb'),
|
||||
('ziptest2dir/ziptest3dir/ziptest4dir/_ziptest3', '6y7u8i9o0p')]
|
||||
|
||||
class TestsWithSourceFile(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.line_gen = (bytes("Zipfile test line %d. random float: %f" %
|
||||
|
@ -289,6 +294,57 @@ class TestsWithSourceFile(unittest.TestCase):
|
|||
self.assertRaises(RuntimeError, zipf.write, TESTFN)
|
||||
zipf.close()
|
||||
|
||||
def testExtract(self):
|
||||
zipfp = zipfile.ZipFile(TESTFN2, "w", zipfile.ZIP_STORED)
|
||||
for fpath, fdata in SMALL_TEST_DATA:
|
||||
zipfp.writestr(fpath, fdata)
|
||||
zipfp.close()
|
||||
|
||||
zipfp = zipfile.ZipFile(TESTFN2, "r")
|
||||
for fpath, fdata in SMALL_TEST_DATA:
|
||||
writtenfile = zipfp.extract(fpath)
|
||||
|
||||
# make sure it was written to the right place
|
||||
if os.path.isabs(fpath):
|
||||
correctfile = os.path.join(os.getcwd(), fpath[1:])
|
||||
else:
|
||||
correctfile = os.path.join(os.getcwd(), fpath)
|
||||
|
||||
self.assertEqual(writtenfile, correctfile)
|
||||
|
||||
# make sure correct data is in correct file
|
||||
self.assertEqual(fdata.encode(), open(writtenfile, "rb").read())
|
||||
|
||||
os.remove(writtenfile)
|
||||
|
||||
zipfp.close()
|
||||
|
||||
# remove the test file subdirectories
|
||||
shutil.rmtree(os.path.join(os.getcwd(), 'ziptest2dir'))
|
||||
|
||||
def testExtractAll(self):
|
||||
zipfp = zipfile.ZipFile(TESTFN2, "w", zipfile.ZIP_STORED)
|
||||
for fpath, fdata in SMALL_TEST_DATA:
|
||||
zipfp.writestr(fpath, fdata)
|
||||
zipfp.close()
|
||||
|
||||
zipfp = zipfile.ZipFile(TESTFN2, "r")
|
||||
zipfp.extractall()
|
||||
for fpath, fdata in SMALL_TEST_DATA:
|
||||
if os.path.isabs(fpath):
|
||||
outfile = os.path.join(os.getcwd(), fpath[1:])
|
||||
else:
|
||||
outfile = os.path.join(os.getcwd(), fpath)
|
||||
|
||||
self.assertEqual(fdata.encode(), open(outfile, "rb").read())
|
||||
|
||||
os.remove(outfile)
|
||||
|
||||
zipfp.close()
|
||||
|
||||
# remove the test file subdirectories
|
||||
shutil.rmtree(os.path.join(os.getcwd(), 'ziptest2dir'))
|
||||
|
||||
def tearDown(self):
|
||||
os.remove(TESTFN)
|
||||
os.remove(TESTFN2)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue