Changeset 8003 for django/trunk/django/test/testcases.py
- Timestamp:
- 07/20/08 00:46:41 (6 months ago)
- Files:
-
- django/trunk/django/test/testcases.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/test/testcases.py
r7981 r8003 59 59 Based on http://codespeak.net/svn/lxml/trunk/src/lxml/doctestcompare.py 60 60 """ 61 62 # We use this to distinguish the output of repr() from an XML element:63 _repr_re = re.compile(r'^<[^>]+ (at|object) ')64 65 61 _norm_whitespace_re = re.compile(r'[ \t\n][ \t\n]+') 66 62 def norm_whitespace(v): 67 63 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))73 64 74 65 def child_text(element): … … 105 96 want = want.replace('\\n','\n') 106 97 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 113 106 # Parse the want and got strings, and compare the parsings. 114 107 try:
