summaryrefslogtreecommitdiff
path: root/django/test/testcases.py
diff options
context:
space:
mode:
authorRussell Keith-Magee <russell@keith-magee.com>2008-07-20 05:46:41 +0000
committerRussell Keith-Magee <russell@keith-magee.com>2008-07-20 05:46:41 +0000
commit2f49d180711ffaac7080d473b2ef86d911015e53 (patch)
tree4b3c5dd065d257ef578dc9a3f65e1e57a21d88bb /django/test/testcases.py
parent55ebc2b594243063afd315311b590bef04d7b61b (diff)
Fixed #7441 -- Removed some of the shortcuts in the doctest output comparators, and added a wrapper to allow comparison of xml fragments. Thanks to Leo Soto for the report and fix.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@8003 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/test/testcases.py')
-rw-r--r--django/test/testcases.py21
1 files changed, 7 insertions, 14 deletions
diff --git a/django/test/testcases.py b/django/test/testcases.py
index 3c851f4bd4..dcab078553 100644
--- a/django/test/testcases.py
+++ b/django/test/testcases.py
@@ -58,19 +58,10 @@ class OutputChecker(doctest.OutputChecker):
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
if c.nodeType == Node.TEXT_NODE])
@@ -104,12 +95,14 @@ class OutputChecker(doctest.OutputChecker):
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. This allow us to compare fragments, like "<foo/><bar/>"
+ if not want.startswith('<?xml'):
+ wrapper = '<root>%s</root>'
+ want = wrapper % want
+ got = wrapper % got
+
# Parse the want and got strings, and compare the parsings.
try:
want_root = parseString(want).firstChild