summaryrefslogtreecommitdiff
path: root/django/test/utils.py
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2012-10-15 22:18:47 +0200
committerClaude Paroz <claude@2xlibre.net>2012-10-15 23:05:40 +0200
commit6b0a836c9c4a311440c2259af9c689933e70703a (patch)
treeb7ec4a22546c824278dbacaa8425c98e1f891c0b /django/test/utils.py
parent1636b0338273290e762f83baffe4bbe375163319 (diff)
downloaddjango-6b0a836c9c4a311440c2259af9c689933e70703a.tar.gz
Fixed assertXMLEqual when first node was a comment
Diffstat (limited to 'django/test/utils.py')
-rw-r--r--django/test/utils.py16
1 files changed, 11 insertions, 5 deletions
diff --git a/django/test/utils.py b/django/test/utils.py
index 71252eaac8..f10d388227 100644
--- a/django/test/utils.py
+++ b/django/test/utils.py
@@ -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)