MCPcopy Index your code
hub / github.com/python/cpython / test_writestr

Method test_writestr

Lib/test/test_zipfile/test_core.py:3075–3089  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

3073
3074class UnseekableTests(unittest.TestCase):
3075 def test_writestr(self):
3076 for wrapper in (lambda f: f), Tellable, Unseekable:
3077 with self.subTest(wrapper=wrapper):
3078 f = io.BytesIO()
3079 f.write(b'abc')
3080 bf = io.BufferedWriter(f)
3081 with zipfile.ZipFile(wrapper(bf), 'w', zipfile.ZIP_STORED) as zipfp:
3082 zipfp.writestr('ones', b'111')
3083 zipfp.writestr('twos', b'222')
3084 self.assertEqual(f.getvalue()[:5], b'abcPK')
3085 with zipfile.ZipFile(f, mode='r') as zipf:
3086 with zipf.open('ones') as zopen:
3087 self.assertEqual(zopen.read(), b'111')
3088 with zipf.open('twos') as zopen:
3089 self.assertEqual(zopen.read(), b'222')
3090
3091 def test_write(self):
3092 for wrapper in (lambda f: f), Tellable, Unseekable:

Callers

nothing calls this directly

Calls 8

writeMethod · 0.95
getvalueMethod · 0.95
writestrMethod · 0.80
wrapperFunction · 0.50
subTestMethod · 0.45
assertEqualMethod · 0.45
openMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected