Preserve the invariant tostring(elem) == b''.join(tostringlist(elem)) and add a test to make sure it keeps working

This commit is contained in:
Eli Bendersky 2012-07-17 05:45:11 +03:00
parent daa4c6b2e6
commit 426e248feb
2 changed files with 15 additions and 0 deletions

View File

@ -2286,6 +2286,15 @@ class IOTest(unittest.TestCase):
'''<?xml version='1.0' encoding='utf-16'?>\n'''
'''<site />'''.encode("utf-16"))
def test_tostringlist_invariant(self):
root = ET.fromstring('<tag>foo</tag>')
self.assertEqual(
ET.tostring(root, 'unicode'),
''.join(ET.tostringlist(root, 'unicode')))
self.assertEqual(
ET.tostring(root, 'utf-16'),
b''.join(ET.tostringlist(root, 'utf-16')))
class ParseErrorTest(unittest.TestCase):
def test_subclass(self):

View File

@ -1190,9 +1190,15 @@ def tostringlist(element, encoding=None, method=None):
def writable(self):
return True
def seekable(self):
return True
def write(self, b):
data.append(b)
def tell(self):
return len(data)
ElementTree(element).write(DataStream(), encoding, method=method)
return data