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

Unified Diff: Lib/test/test_zipfile.py

Issue 22217: Reprs for zipfile classes
Patch Set: Created 5 years, 5 months ago
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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | Lib/zipfile.py » ('j') | Lib/zipfile.py » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
--- a/Lib/test/test_zipfile.py Tue Aug 19 18:20:48 2014 +0300
+++ b/Lib/test/test_zipfile.py Thu Aug 21 09:47:10 2014 +0300
@@ -326,6 +326,37 @@
while zipopen.read1(100):
pass
+ def test_repr(self):
+ fname = 'file.name'
+ for f in get_files(self):
+ with zipfile.ZipFile(f, 'w', self.compression) as zipfp:
+ zipfp.write(TESTFN, fname)
+ r = repr(zipfp)
+ self.assertIn("mode='w'", r)
+
+ with zipfile.ZipFile(f, 'r') as zipfp:
+ r = repr(zipfp)
+ if isinstance(f, str):
+ self.assertIn('filename=%r' % f, r)
+ else:
+ self.assertIn('file=%r' % f, r)
+ self.assertIn("mode='r'", r)
+ r = repr(zipfp.getinfo(fname))
+ self.assertIn('filename=%r' % fname, r)
+ self.assertIn('filemode=', r)
+ self.assertIn('file_size=', r)
+ if self.compression != zipfile.ZIP_STORED:
+ self.assertIn('compress_type=', r)
+ self.assertIn('compress_size=', r)
+ with zipfp.open(fname) as zipopen:
+ r = repr(zipopen)
+ self.assertIn('name=%r' % fname, r)
+ self.assertIn("mode='r'", r)
+ if self.compression != zipfile.ZIP_STORED:
+ self.assertIn('compress_type=', r)
+ self.assertIn('[closed]', repr(zipopen))
+ self.assertIn('[closed]', repr(zipfp))
+
def tearDown(self):
unlink(TESTFN)
unlink(TESTFN2)
« no previous file with comments | « no previous file | Lib/zipfile.py » ('j') | Lib/zipfile.py » ('J')

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