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

Method test_write_to_text_file

Lib/test/test_xml_etree.py:4307–4326  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

4305 self.assertEqual(f.read(), b"<site>\xc3\xb8</site>")
4306
4307 def test_write_to_text_file(self):
4308 self.addCleanup(os_helper.unlink, TESTFN)
4309 tree = ET.ElementTree(ET.XML('''<site>\xf8</site>'''))
4310 with open(TESTFN, 'w', encoding='utf-8') as f:
4311 tree.write(f, encoding='unicode')
4312 self.assertFalse(f.closed)
4313 with open(TESTFN, 'rb') as f:
4314 self.assertEqual(f.read(), b'''<site>\xc3\xb8</site>''')
4315
4316 with open(TESTFN, 'w', encoding='ascii', errors='xmlcharrefreplace') as f:
4317 tree.write(f, encoding='unicode')
4318 self.assertFalse(f.closed)
4319 with open(TESTFN, 'rb') as f:
4320 self.assertEqual(f.read(), b'''<site>&#248;</site>''')
4321
4322 with open(TESTFN, 'w', encoding='ISO-8859-1') as f:
4323 tree.write(f, encoding='unicode')
4324 self.assertFalse(f.closed)
4325 with open(TESTFN, 'rb') as f:
4326 self.assertEqual(f.read(), b'''<site>\xf8</site>''')
4327
4328 def test_write_to_binary_file(self):
4329 self.addCleanup(os_helper.unlink, TESTFN)

Callers

nothing calls this directly

Calls 6

writeMethod · 0.95
addCleanupMethod · 0.80
assertFalseMethod · 0.80
openFunction · 0.50
assertEqualMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected