Ticket #7441: 7441_wrapper_for_xml_outputchecker.diff

File 7441_wrapper_for_xml_outputchecker.diff, 2.2 KB (added by Leo Soto M., 16 years ago)
  • django/test/testcases.py

    diff -r ec6f64ba8d93 django/test/testcases.py
    a b  
    5555        """Tries to do a 'xml-comparision' of want and got.  Plain string
    5656        comparision doesn't always work because, for example, attribute
    5757        ordering should not be important.
    58        
     58
    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) ')
    6461
    6562        _norm_whitespace_re = re.compile(r'[ \t\n][ \t\n]+')
    6663        def norm_whitespace(v):
    6764            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))
    7365
    7466        def child_text(element):
    7567            return ''.join([c.data for c in element.childNodes
     
    10496        want, got = self._strip_quotes(want, got)
    10597        want = want.replace('\\n','\n')
    10698        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
     99
     100        # If the string is not a complete xml document, we may need to add a
     101        # root element
     102        if not (want.startswith('<?xml') or got.startswith('<?xml')):
     103            wrapper = '<root>%s</root>' # This allow us to compare fragments, like
     104                                        # "<foo/><bar/>"
     105            want = wrapper % want
     106            got = wrapper % got
    112107
    113108        # Parse the want and got strings, and compare the parsings.
    114109        try:
     
    181176        """Performs any pre-test setup. This includes:
    182177
    183178            * Flushing the database.
    184             * If the Test Case class has a 'fixtures' member, installing the 
     179            * If the Test Case class has a 'fixtures' member, installing the
    185180              named fixtures.
    186181            * If the Test Case class has a 'urls' member, replace the
    187182              ROOT_URLCONF with it.
Back to Top