diff -r ec6f64ba8d93 django/test/testcases.py
a
|
b
|
|
55 | 55 | """Tries to do a 'xml-comparision' of want and got. Plain string |
56 | 56 | comparision doesn't always work because, for example, attribute |
57 | 57 | ordering should not be important. |
58 | | |
| 58 | |
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 | 61 | |
65 | 62 | _norm_whitespace_re = re.compile(r'[ \t\n][ \t\n]+') |
66 | 63 | def norm_whitespace(v): |
67 | 64 | 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 | 65 | |
74 | 66 | def child_text(element): |
75 | 67 | return ''.join([c.data for c in element.childNodes |
… |
… |
|
104 | 96 | want, got = self._strip_quotes(want, got) |
105 | 97 | want = want.replace('\\n','\n') |
106 | 98 | 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 |
112 | 107 | |
113 | 108 | # Parse the want and got strings, and compare the parsings. |
114 | 109 | try: |
… |
… |
|
181 | 176 | """Performs any pre-test setup. This includes: |
182 | 177 | |
183 | 178 | * 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 |
185 | 180 | named fixtures. |
186 | 181 | * If the Test Case class has a 'urls' member, replace the |
187 | 182 | ROOT_URLCONF with it. |