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

Method test_write

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

Source from the content-addressed store, hash-verified

3089 self.assertEqual(zopen.read(), b'222')
3090
3091 def test_write(self):
3092 for wrapper in (lambda f: f), Tellable, Unseekable:
3093 with self.subTest(wrapper=wrapper):
3094 f = io.BytesIO()
3095 f.write(b'abc')
3096 bf = io.BufferedWriter(f)
3097 with zipfile.ZipFile(wrapper(bf), 'w', zipfile.ZIP_STORED) as zipfp:
3098 self.addCleanup(unlink, TESTFN)
3099 with open(TESTFN, 'wb') as f2:
3100 f2.write(b'111')
3101 zipfp.write(TESTFN, 'ones')
3102 with open(TESTFN, 'wb') as f2:
3103 f2.write(b'222')
3104 zipfp.write(TESTFN, 'twos')
3105 self.assertEqual(f.getvalue()[:5], b'abcPK')
3106 with zipfile.ZipFile(f, mode='r') as zipf:
3107 with zipf.open('ones') as zopen:
3108 self.assertEqual(zopen.read(), b'111')
3109 with zipf.open('twos') as zopen:
3110 self.assertEqual(zopen.read(), b'222')
3111
3112 def test_open_write(self):
3113 for wrapper in (lambda f: f), Tellable, Unseekable:

Callers

nothing calls this directly

Calls 10

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

Tested by

no test coverage detected