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

Delta Between Two Patch Sets: Lib/test/test_zipfile.py

Issue 22217: Reprs for zipfile classes
Left Patch Set: Created 5 years, 5 months ago
Right Patch Set: Created 5 years, 5 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:
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | Lib/zipfile.py » ('j') | Lib/zipfile.py » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 import io 1 import io
2 import os 2 import os
3 import sys 3 import sys
4 import importlib.util 4 import importlib.util
5 import time 5 import time
6 import struct 6 import struct
7 import zipfile 7 import zipfile
8 import unittest 8 import unittest
9 9
10 10
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 while zipopen.read(100): 318 while zipopen.read(100):
319 pass 319 pass
320 320
321 fp = io.BytesIO(zipfiledata) 321 fp = io.BytesIO(zipfiledata)
322 with zipfile.ZipFile(fp) as zipf: 322 with zipfile.ZipFile(fp) as zipf:
323 with zipf.open('strfile') as zipopen: 323 with zipf.open('strfile') as zipopen:
324 fp.truncate(end_offset - 20) 324 fp.truncate(end_offset - 20)
325 with self.assertRaises(EOFError): 325 with self.assertRaises(EOFError):
326 while zipopen.read1(100): 326 while zipopen.read1(100):
327 pass 327 pass
328
329 def test_repr(self):
330 fname = 'file.name'
331 for f in get_files(self):
332 with zipfile.ZipFile(f, 'w', self.compression) as zipfp:
333 zipfp.write(TESTFN, fname)
334 r = repr(zipfp)
335 self.assertIn("mode='w'", r)
336
337 with zipfile.ZipFile(f, 'r') as zipfp:
338 r = repr(zipfp)
339 if isinstance(f, str):
340 self.assertIn('filename=%r' % f, r)
341 else:
342 self.assertIn('file=%r' % f, r)
343 self.assertIn("mode='r'", r)
344 r = repr(zipfp.getinfo(fname))
345 self.assertIn('filename=%r' % fname, r)
346 self.assertIn('filemode=', r)
347 self.assertIn('file_size=', r)
348 if self.compression != zipfile.ZIP_STORED:
349 self.assertIn('compress_type=', r)
350 self.assertIn('compress_size=', r)
351 with zipfp.open(fname) as zipopen:
352 r = repr(zipopen)
353 self.assertIn('name=%r' % fname, r)
354 self.assertIn("mode='r'", r)
355 if self.compression != zipfile.ZIP_STORED:
356 self.assertIn('compress_type=', r)
357 self.assertIn('[closed]', repr(zipopen))
358 self.assertIn('[closed]', repr(zipfp))
328 359
329 def tearDown(self): 360 def tearDown(self):
330 unlink(TESTFN) 361 unlink(TESTFN)
331 unlink(TESTFN2) 362 unlink(TESTFN2)
332 363
333 364
334 class StoredTestsWithSourceFile(AbstractTestsWithSourceFile, 365 class StoredTestsWithSourceFile(AbstractTestsWithSourceFile,
335 unittest.TestCase): 366 unittest.TestCase):
336 compression = zipfile.ZIP_STORED 367 compression = zipfile.ZIP_STORED
337 test_low_compression = None 368 test_low_compression = None
(...skipping 1436 matching lines...) Expand 10 before | Expand all | Expand 10 after
1774 unittest.TestCase): 1805 unittest.TestCase):
1775 compression = zipfile.ZIP_BZIP2 1806 compression = zipfile.ZIP_BZIP2
1776 1807
1777 @requires_lzma 1808 @requires_lzma
1778 class LzmaUniversalNewlineTests(AbstractUniversalNewlineTests, 1809 class LzmaUniversalNewlineTests(AbstractUniversalNewlineTests,
1779 unittest.TestCase): 1810 unittest.TestCase):
1780 compression = zipfile.ZIP_LZMA 1811 compression = zipfile.ZIP_LZMA
1781 1812
1782 if __name__ == "__main__": 1813 if __name__ == "__main__":
1783 unittest.main() 1814 unittest.main()
LEFTRIGHT
« no previous file | Lib/zipfile.py » ('j') | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

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