| 2942 | |
| 2943 | class UnseekableTests(unittest.TestCase): |
| 2944 | def test_writestr(self): |
| 2945 | for wrapper in (lambda f: f), Tellable, Unseekable: |
| 2946 | with self.subTest(wrapper=wrapper): |
| 2947 | f = io.BytesIO() |
| 2948 | f.write(b'abc') |
| 2949 | bf = io.BufferedWriter(f) |
| 2950 | with zipfile.ZipFile(wrapper(bf), 'w', zipfile.ZIP_STORED) as zipfp: |
| 2951 | zipfp.writestr('ones', b'111') |
| 2952 | zipfp.writestr('twos', b'222') |
| 2953 | self.assertEqual(f.getvalue()[:5], b'abcPK') |
| 2954 | with zipfile.ZipFile(f, mode='r') as zipf: |
| 2955 | with zipf.open('ones') as zopen: |
| 2956 | self.assertEqual(zopen.read(), b'111') |
| 2957 | with zipf.open('twos') as zopen: |
| 2958 | self.assertEqual(zopen.read(), b'222') |
| 2959 | |
| 2960 | def test_write(self): |
| 2961 | for wrapper in (lambda f: f), Tellable, Unseekable: |