Django

Code

Show
Ignore:
Timestamp:
07/20/08 00:46:41 (6 months ago)
Author:
russellm
Message:

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.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/test/testcases.py

    r7981 r8003  
    5959        Based on http://codespeak.net/svn/lxml/trunk/src/lxml/doctestcompare.py 
    6060        """ 
    61          
    62         # We use this to distinguish the output of repr() from an XML element: 
    63         _repr_re = re.compile(r'^<[^>]+ (at|object) ') 
    64  
    6561        _norm_whitespace_re = re.compile(r'[ \t\n][ \t\n]+') 
    6662        def norm_whitespace(v): 
    6763            return _norm_whitespace_re.sub(' ', v) 
    68  
    69         def looks_like_xml(s): 
    70             s = s.strip() 
    71             return (s.startswith('<') 
    72                     and not _repr_re.search(s)) 
    7364 
    7465        def child_text(element): 
     
    10596        want = want.replace('\\n','\n') 
    10697        got = got.replace('\\n','\n') 
    107          
    108         # If what we want doesn't look like markup, don't bother trying 
    109         # to parse it. 
    110         if not looks_like_xml(want): 
    111             return False 
    112  
     98 
     99        # If the string is not a complete xml document, we may need to add a 
     100        # root element. This allow us to compare fragments, like "<foo/><bar/>" 
     101        if not want.startswith('<?xml'): 
     102            wrapper = '<root>%s</root>' 
     103            want = wrapper % want 
     104            got = wrapper % got 
     105             
    113106        # Parse the want and got strings, and compare the parsings. 
    114107        try: