diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2014-10-29 20:42:06 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2014-10-29 20:42:06 (GMT) |
commit | 51a43703afa0f4de9c2fb2ff4ce3a75e499c5e4e (patch) | |
tree | 0384ead9fd97245a4b3bde37757a1fef5a405a2c /Lib/test/test_zipfile.py | |
parent | 659dd625b4c3489fbefe9fa866d87bc2b5e14366 (diff) | |
download | cpython-51a43703afa0f4de9c2fb2ff4ce3a75e499c5e4e.zip cpython-51a43703afa0f4de9c2fb2ff4ce3a75e499c5e4e.tar.gz cpython-51a43703afa0f4de9c2fb2ff4ce3a75e499c5e4e.tar.bz2 |
Issue #22217: Implemented reprs of classes in the zipfile module.
Diffstat (limited to 'Lib/test/test_zipfile.py')
-rw-r--r-- | Lib/test/test_zipfile.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/Lib/test/test_zipfile.py b/Lib/test/test_zipfile.py index a17eaaa..7f2f1ec 100644 --- a/Lib/test/test_zipfile.py +++ b/Lib/test/test_zipfile.py @@ -326,6 +326,37 @@ class AbstractTestsWithSourceFile: 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) |