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

Method test_reconfigure_write

Lib/test/test_io/test_textio.py:1225–1244  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1223 self.assertEqual(raw.getvalue(), b'foo\n\xc3\xa9\n')
1224
1225 def test_reconfigure_write(self):
1226 # latin -> utf8
1227 raw = self.BytesIO()
1228 txt = self.TextIOWrapper(raw, encoding='latin1', newline='\n')
1229 txt.write('abc\xe9\n')
1230 txt.reconfigure(encoding='utf-8')
1231 self.assertEqual(raw.getvalue(), b'abc\xe9\n')
1232 txt.write('d\xe9f\n')
1233 txt.flush()
1234 self.assertEqual(raw.getvalue(), b'abc\xe9\nd\xc3\xa9f\n')
1235
1236 # ascii -> utf-8-sig: ensure that no BOM is written in the middle of
1237 # the file
1238 raw = self.BytesIO()
1239 txt = self.TextIOWrapper(raw, encoding='ascii', newline='\n')
1240 txt.write('abc\n')
1241 txt.reconfigure(encoding='utf-8-sig')
1242 txt.write('d\xe9f\n')
1243 txt.flush()
1244 self.assertEqual(raw.getvalue(), b'abc\nd\xc3\xa9f\n')
1245
1246 def test_reconfigure_write_non_seekable(self):
1247 raw = self.BytesIO()

Callers

nothing calls this directly

Calls 5

writeMethod · 0.95
reconfigureMethod · 0.95
getvalueMethod · 0.95
flushMethod · 0.95
assertEqualMethod · 0.45

Tested by

no test coverage detected