Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix tests on Windows.
  • Loading branch information
serhiy-storchaka committed Apr 27, 2022
commit 9d215498c3329315b7ed3dd25cdc36f3917813d4
15 changes: 9 additions & 6 deletions Lib/test/test_xml_etree.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ def newtest(*args, **kwargs):
return newtest
return decorator

def convlinesep(data):
return data.replace(b'\n', os.linesep.encode())


class ModuleTest(unittest.TestCase):
def test_sanity(self):
Expand Down Expand Up @@ -3722,9 +3725,9 @@ def test_write_to_filename_with_encoding(self):

tree.write(TESTFN, encoding='ISO-8859-1')
with open(TESTFN, 'rb') as f:
self.assertEqual(f.read(),
self.assertEqual(f.read(), convlinesep(
b'''<?xml version='1.0' encoding='ISO-8859-1'?>\n'''
b'''<site>\xf8</site>''')
b'''<site>\xf8</site>'''))

def test_write_to_filename_as_unicode(self):
self.addCleanup(os_helper.unlink, TESTFN)
Expand Down Expand Up @@ -3759,17 +3762,17 @@ def test_write_to_text_file(self):
tree.write(f, encoding='unicode')
self.assertFalse(f.closed)
with open(TESTFN, 'rb') as f:
self.assertEqual(f.read(),
self.assertEqual(f.read(), convlinesep(
b'''<?xml version='1.0' encoding='ascii'?>\n'''
b'''<site>&#248;</site>''')
b'''<site>&#248;</site>'''))

with open(TESTFN, 'w', encoding='ISO-8859-1') as f:
tree.write(f, encoding='unicode')
self.assertFalse(f.closed)
with open(TESTFN, 'rb') as f:
self.assertEqual(f.read(),
self.assertEqual(f.read(), convlinesep(
b'''<?xml version='1.0' encoding='ISO-8859-1'?>\n'''
b'''<site>\xf8</site>''')
b'''<site>\xf8</site>'''))

def test_write_to_binary_file(self):
self.addCleanup(os_helper.unlink, TESTFN)
Expand Down