diff -r ec6f64ba8d93 django/test/testcases.py
--- a/django/test/testcases.py Sat Jul 19 18:28:36 2008 -0400
+++ b/django/test/testcases.py Sat Jul 19 19:32:44 2008 -0400
@@ -55,21 +55,13 @@
"""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.
-
+
Based on http://codespeak.net/svn/lxml/trunk/src/lxml/doctestcompare.py
"""
-
- # We use this to distinguish the output of repr() from an XML element:
- _repr_re = re.compile(r'^<[^>]+ (at|object) ')
_norm_whitespace_re = re.compile(r'[ \t\n][ \t\n]+')
def norm_whitespace(v):
return _norm_whitespace_re.sub(' ', v)
-
- def looks_like_xml(s):
- s = s.strip()
- return (s.startswith('<')
- and not _repr_re.search(s))
def child_text(element):
return ''.join([c.data for c in element.childNodes
@@ -104,11 +96,14 @@
want, got = self._strip_quotes(want, got)
want = want.replace('\\n','\n')
got = got.replace('\\n','\n')
-
- # If what we want doesn't look like markup, don't bother trying
- # to parse it.
- if not looks_like_xml(want):
- return False
+
+ # If the string is not a complete xml document, we may need to add a
+ # root element
+ if not (want.startswith('%s' # This allow us to compare fragments, like
+ # ""
+ want = wrapper % want
+ got = wrapper % got
# Parse the want and got strings, and compare the parsings.
try:
@@ -181,7 +176,7 @@
"""Performs any pre-test setup. This includes:
* Flushing the database.
- * If the Test Case class has a 'fixtures' member, installing the
+ * If the Test Case class has a 'fixtures' member, installing the
named fixtures.
* If the Test Case class has a 'urls' member, replace the
ROOT_URLCONF with it.