1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Fixed assertXMLEqual when first node was a comment

This commit is contained in:
Claude Paroz
2012-10-15 22:18:47 +02:00
parent 1636b03382
commit 6b0a836c9c
2 changed files with 16 additions and 5 deletions

View File

@@ -227,9 +227,10 @@ class override_settings(object):
def compare_xml(want, got):
"""Tries to do a 'xml-comparision' of want and got. Plain string
comparision doesn't always work because, for example, attribute
ordering should not be important.
"""Tries to do a 'xml-comparison' of want and got. Plain string
comparison doesn't always work because, for example, attribute
ordering should not be important. Comment nodes are not considered in the
comparison.
Based on http://codespeak.net/svn/lxml/trunk/src/lxml/doctestcompare.py
"""
@@ -267,6 +268,11 @@ def compare_xml(want, got):
return False
return True
def first_node(document):
for node in document.childNodes:
if node.nodeType != Node.COMMENT_NODE:
return node
want, got = strip_quotes(want, got)
want = want.replace('\\n','\n')
got = got.replace('\\n','\n')
@@ -279,8 +285,8 @@ def compare_xml(want, got):
got = wrapper % got
# Parse the want and got strings, and compare the parsings.
want_root = parseString(want).firstChild
got_root = parseString(got).firstChild
want_root = first_node(parseString(want))
got_root = first_node(parseString(got))
return check_element(want_root, got_root)