diff options
author | Raymond Hettinger <rhettinger@users.noreply.github.com> | 2018-10-28 18:18:22 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-28 18:18:22 (GMT) |
commit | e3685fd5fdd8808acda81bfc12fb9702d4b59a60 (patch) | |
tree | 930b05ba14510edd10fbec2840ee3e953cae7e39 /Lib/test/test_xml_etree.py | |
parent | 18d57b4d6262bf96b5ac307bd84837c29ea04083 (diff) | |
download | cpython-e3685fd5fdd8808acda81bfc12fb9702d4b59a60.zip cpython-e3685fd5fdd8808acda81bfc12fb9702d4b59a60.tar.gz cpython-e3685fd5fdd8808acda81bfc12fb9702d4b59a60.tar.bz2 |
bpo-34160: Preserve user specified order of Element attributes (GH-10163)
Diffstat (limited to 'Lib/test/test_xml_etree.py')
-rw-r--r-- | Lib/test/test_xml_etree.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py index 8b16905..9988dad 100644 --- a/Lib/test/test_xml_etree.py +++ b/Lib/test/test_xml_etree.py @@ -5,6 +5,7 @@ # For this purpose, the module-level "ET" symbol is temporarily # monkey-patched when running the "test_xml_etree_c" test suite. +import contextlib import copy import functools import html @@ -1044,6 +1045,25 @@ class ElementTreeTest(unittest.TestCase): method='html') self.assertEqual(serialized, expected) + def test_dump_attribute_order(self): + # See BPO 34160 + e = ET.Element('cirriculum', status='public', company='example') + with support.captured_stdout() as stdout: + ET.dump(e) + self.assertEqual(stdout.getvalue(), + '<cirriculum status="public" company="example" />\n') + + def test_tree_write_attribute_order(self): + # See BPO 34160 + root = ET.Element('cirriculum', status='public', company='example') + tree = ET.ElementTree(root) + f = io.BytesIO() + with contextlib.redirect_stdout(f): + tree.write(f, encoding='utf-8', xml_declaration=True) + self.assertEqual(f.getvalue(), + b"<?xml version='1.0' encoding='utf-8'?>\n" + b'<cirriculum status="public" company="example" />') + class XMLPullParserTest(unittest.TestCase): |