Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(28)

Side by Side Diff: Lib/test/test_zipfile.py

Issue 14315: zipfile.ZipFile() unable to open zip File
Patch Set: Created 7 years, 8 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 import io 1 import io
2 import os 2 import os
3 import sys 3 import sys
4 import imp 4 import imp
5 import time 5 import time
6 import shutil 6 import shutil
7 import struct 7 import struct
8 import zipfile 8 import zipfile
9 import unittest 9 import unittest
10 10
(...skipping 1253 matching lines...) Expand 10 before | Expand all | Expand 10 after
1264 # Issue 1710703: Check that opening a file with less than 22 bytes 1264 # Issue 1710703: Check that opening a file with less than 22 bytes
1265 # raises a BadZipFile exception (rather than the previously unhelpful 1265 # raises a BadZipFile exception (rather than the previously unhelpful
1266 # IOError) 1266 # IOError)
1267 f = open(TESTFN, 'w') 1267 f = open(TESTFN, 'w')
1268 f.close() 1268 f.close()
1269 self.assertRaises(zipfile.BadZipFile, zipfile.ZipFile, TESTFN, 'r') 1269 self.assertRaises(zipfile.BadZipFile, zipfile.ZipFile, TESTFN, 'r')
1270 1270
1271 def test_create_zipinfo_before_1980(self): 1271 def test_create_zipinfo_before_1980(self):
1272 self.assertRaises(ValueError, 1272 self.assertRaises(ValueError,
1273 zipfile.ZipInfo, 'seventies', (1979, 1, 1, 0, 0, 0)) 1273 zipfile.ZipInfo, 'seventies', (1979, 1, 1, 0, 0, 0))
1274
1275 def test_padded_zipfile(self):
1276 zipdata = (
1277 b'PK\x03\x04\x14\x00\x00\x00\x00\x00\x93\x9b\xad@\x8b\x9e'
1278 b'\xd9\xd3\x01\x00\x00\x00\x01\x00\x00\x00\x03\x00\x03\x00ab'
1279 b'c\x00\x00\x00APK\x01\x02\x14\x03\x14\x00\x00\x00\x00'
1280 b'\x00\x93\x9b\xad@\x8b\x9e\xd9\xd3\x01\x00\x00\x00\x01\x00\x00'
1281 b'\x00\x03\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81\x00'
1282 b'\x00\x00\x00abc\x00\x00PK\x05\x06\x00\x00\x00\x00'
1283 b'\x01\x00\x01\x003\x00\x00\x00%\x00\x00\x00\x00\x00'
1284 )
1285 with zipfile.ZipFile(io.BytesIO(zipdata), 'r') as zipf:
1286 # testzip returns the name of the first corrupt file, or None
1287 self.assertIsNone(zipf.testzip())
1274 1288
1275 def tearDown(self): 1289 def tearDown(self):
1276 unlink(TESTFN) 1290 unlink(TESTFN)
1277 unlink(TESTFN2) 1291 unlink(TESTFN2)
1278 1292
1279 1293
1280 class DecryptionTests(unittest.TestCase): 1294 class DecryptionTests(unittest.TestCase):
1281 """Check that ZIP decryption works. Since the library does not 1295 """Check that ZIP decryption works. Since the library does not
1282 support encryption at the moment, we use a pre-generated encrypted 1296 support encryption at the moment, we use a pre-generated encrypted
1283 ZIP file.""" 1297 ZIP file."""
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after
1759 1773
1760 1774
1761 def test_main(): 1775 def test_main():
1762 run_unittest(TestsWithSourceFile, TestZip64InSmallFiles, OtherTests, 1776 run_unittest(TestsWithSourceFile, TestZip64InSmallFiles, OtherTests,
1763 PyZipFileTests, DecryptionTests, TestsWithMultipleOpens, 1777 PyZipFileTests, DecryptionTests, TestsWithMultipleOpens,
1764 TestWithDirectory, UniversalNewlineTests, 1778 TestWithDirectory, UniversalNewlineTests,
1765 TestsWithRandomBinaryFiles) 1779 TestsWithRandomBinaryFiles)
1766 1780
1767 if __name__ == "__main__": 1781 if __name__ == "__main__":
1768 test_main() 1782 test_main()
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+