]> granicus.if.org Git - python/commitdiff
bpo-34160: Preserve user specified order of Element attributes in html. (GH-10190)
authorSerhiy Storchaka <storchaka@gmail.com>
Mon, 29 Oct 2018 17:31:04 +0000 (19:31 +0200)
committerGitHub <noreply@github.com>
Mon, 29 Oct 2018 17:31:04 +0000 (19:31 +0200)
Lib/test/test_xml_etree.py
Lib/xml/etree/ElementTree.py

index 9988dad86384e0f58b8e559a8ebd335b5c3d8f82..8a7ec0076ff03684c3c93806a75190a17c993a15 100644 (file)
@@ -5,7 +5,6 @@
 # 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
@@ -1056,13 +1055,10 @@ class ElementTreeTest(unittest.TestCase):
     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" />')
+        self.assertEqual(serialize(root),
+                         '<cirriculum status="public" company="example" />')
+        self.assertEqual(serialize(root, method='html'),
+                '<cirriculum status="public" company="example"></cirriculum>')
 
 
 class XMLPullParserTest(unittest.TestCase):
index d4df83fb51ccd97db7488673b80ecdadd84fb16b..c1cf483cf56bb26a94c26d7f4f05e5874f24f1a6 100644 (file)
@@ -979,7 +979,7 @@ def _serialize_html(write, elem, qnames, namespaces, **kwargs):
                             k,
                             _escape_attrib(v)
                             ))
-                for k, v in sorted(items):  # lexical order
+                for k, v in items:
                     if isinstance(k, QName):
                         k = k.text
                     if isinstance(v, QName):