Skip to content

Commit

Permalink
Get lxml treewalker outputting attrs in source order again
Browse files Browse the repository at this point in the history
Mostly so we have test coverage here on < 3.7
  • Loading branch information
gsnedders committed Jun 17, 2020
1 parent 38ec086 commit b2b08cc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 6 additions & 2 deletions html5lib/tests/test_treewalkers.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ def test_lxml_xml():

@pytest.mark.parametrize("treeName",
[pytest.param(treeName, marks=[getattr(pytest.mark, treeName),
pytest.mark.skipif(sys.version_info < (3, 7), reason="dict order undef")])
pytest.mark.skipif(
treeName != "lxml" or
sys.version_info < (3, 7), reason="dict order undef")])
for treeName in sorted(treeTypes.keys())])
def test_maintain_attribute_order(treeName):
treeAPIs = treeTypes[treeName]
Expand Down Expand Up @@ -172,7 +174,9 @@ def test_maintain_attribute_order(treeName):

@pytest.mark.parametrize("treeName",
[pytest.param(treeName, marks=[getattr(pytest.mark, treeName),
pytest.mark.skipif(sys.version_info < (3, 7), reason="dict order undef")])
pytest.mark.skipif(
treeName != "lxml" or
sys.version_info < (3, 7), reason="dict order undef")])
for treeName in sorted(treeTypes.keys())])
def test_maintain_attribute_order_adjusted(treeName):
treeAPIs = treeTypes[treeName]
Expand Down
4 changes: 3 additions & 1 deletion html5lib/treewalkers/etree_lxml.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from __future__ import absolute_import, division, unicode_literals
from six import text_type

from collections import OrderedDict

from lxml import etree
from ..treebuilders.etree import tag_regexp

Expand Down Expand Up @@ -163,7 +165,7 @@ def getNodeDetails(self, node):
else:
namespace = None
tag = ensure_str(node.tag)
attrs = {}
attrs = OrderedDict()
for name, value in list(node.attrib.items()):
name = ensure_str(name)
value = ensure_str(value)
Expand Down

0 comments on commit b2b08cc

Please sign in to comment.