| 3110 | self.assertEqual(zopen.read(), b'222') |
| 3111 | |
| 3112 | def test_open_write(self): |
| 3113 | for wrapper in (lambda f: f), Tellable, Unseekable: |
| 3114 | with self.subTest(wrapper=wrapper): |
| 3115 | f = io.BytesIO() |
| 3116 | f.write(b'abc') |
| 3117 | bf = io.BufferedWriter(f) |
| 3118 | with zipfile.ZipFile(wrapper(bf), 'w', zipfile.ZIP_STORED) as zipf: |
| 3119 | with zipf.open('ones', 'w') as zopen: |
| 3120 | zopen.write(b'111') |
| 3121 | with zipf.open('twos', 'w') as zopen: |
| 3122 | zopen.write(b'222') |
| 3123 | self.assertEqual(f.getvalue()[:5], b'abcPK') |
| 3124 | with zipfile.ZipFile(f) as zipf: |
| 3125 | self.assertEqual(zipf.read('ones'), b'111') |
| 3126 | self.assertEqual(zipf.read('twos'), b'222') |
| 3127 | |
| 3128 | |
| 3129 | @requires_zlib() |