mirror of https://github.com/python/cpython
Preserve the invariant tostring(elem) == b''.join(tostringlist(elem)) and add a test to make sure it keeps working
This commit is contained in:
parent
daa4c6b2e6
commit
426e248feb
|
@ -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):
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue