MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_write_to_text_file

Method test_write_to_text_file

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

Source from the content-addressed store, hash-verified

4268 self.assertEqual(f.read(), b"<site>\xc3\xb8</site>")
4269
4270 def test_write_to_text_file(self):
4271 self.addCleanup(os_helper.unlink, TESTFN)
4272 tree = ET.ElementTree(ET.XML('''<site>\xf8</site>'''))
4273 with open(TESTFN, 'w', encoding='utf-8') as f:
4274 tree.write(f, encoding='unicode')
4275 self.assertFalse(f.closed)
4276 with open(TESTFN, 'rb') as f:
4277 self.assertEqual(f.read(), b'''<site>\xc3\xb8</site>''')
4278
4279 with open(TESTFN, 'w', encoding='ascii', errors='xmlcharrefreplace') as f:
4280 tree.write(f, encoding='unicode')
4281 self.assertFalse(f.closed)
4282 with open(TESTFN, 'rb') as f:
4283 self.assertEqual(f.read(), b'''<site>&#248;</site>''')
4284
4285 with open(TESTFN, 'w', encoding='ISO-8859-1') as f:
4286 tree.write(f, encoding='unicode')
4287 self.assertFalse(f.closed)
4288 with open(TESTFN, 'rb') as f:
4289 self.assertEqual(f.read(), b'''<site>\xf8</site>''')
4290
4291 def test_write_to_binary_file(self):
4292 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