Close #14377: Add a new parameter to ElementTree.write and some module-level

serialization functions - short_empty_elements. It controls how elements
without contents are emitted.

Patch by Serhiy Storchaka. Feature initially proposed by Ariel Poliak.
This commit is contained in:
Eli Bendersky 2013-01-13 06:04:43 -08:00
parent a50ff1887d
commit a9a2ef5550
4 changed files with 56 additions and 14 deletions

View file

@ -2380,6 +2380,18 @@ class IOTest(unittest.TestCase):
ET.tostring(root, 'utf-16'),
b''.join(ET.tostringlist(root, 'utf-16')))
def test_short_empty_elements(self):
root = ET.fromstring('<tag>a<x />b<y></y>c</tag>')
self.assertEqual(
ET.tostring(root, 'unicode'),
'<tag>a<x />b<y />c</tag>')
self.assertEqual(
ET.tostring(root, 'unicode', short_empty_elements=True),
'<tag>a<x />b<y />c</tag>')
self.assertEqual(
ET.tostring(root, 'unicode', short_empty_elements=False),
'<tag>a<x></x>b<y></y>c</tag>')
class ParseErrorTest(unittest.TestCase):
def test_subclass(self):