1
0
mirror of https://github.com/django/django.git synced 2024-12-22 09:05:43 +00:00

Fixed #25170 -- Made assertXMLEqual()/assertXMLNotEqual() ignore leading and trailing whitespace.

Thanks Jacek Bzdak for indepdently contributing a similar fix.
This commit is contained in:
Mattia Larentis 2015-11-07 14:31:25 +01:00 committed by Tim Graham
parent 7862cbda86
commit 2085d8d5bc
3 changed files with 15 additions and 3 deletions

View File

@ -234,6 +234,7 @@ answer newbie questions, and generally made Django that much better:
Fabrice Aneche <akh@nobugware.com>
favo@exoweb.net
fdr <drfarina@gmail.com>
Federico Capoano <nemesis@ninux.org>
Filip Noetzel <http://filip.noetzel.co.uk/>
Filip Wasilewski <filip.wasilewski@gmail.com>
Finn Gruwier Larsen <finn@gruwier.dk>
@ -483,6 +484,7 @@ answer newbie questions, and generally made Django that much better:
Matt McClanahan <http://mmcc.cx/>
Matt Riggott
Matt Robenolt <m@robenolt.com>
Mattia Larentis <mattia@laretis.eu>
mattycakes@gmail.com
Max Burstein <http://maxburstein.com>
Max Derkachev <mderk@yandex.ru>

View File

@ -293,7 +293,7 @@ def compare_xml(want, got):
"""Tries to do a 'xml-comparison' of want and got. Plain string
comparison doesn't always work because, for example, attribute
ordering should not be important. Comment nodes are not considered in the
comparison.
comparison. Leading and trailing whitespace is ignored on both chunks.
Based on http://codespeak.net/svn/lxml/trunk/src/lxml/doctestcompare.py
"""
@ -338,8 +338,8 @@ def compare_xml(want, got):
return node
want, got = strip_quotes(want, got)
want = want.replace('\\n', '\n')
got = got.replace('\\n', '\n')
want = want.strip().replace('\\n', '\n')
got = got.strip().replace('\\n', '\n')
# 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/>"

View File

@ -753,6 +753,16 @@ class XMLEqualTests(SimpleTestCase):
xml2 = "<?xml version='1.0'?><!-- comment2 --><elem attr2='b' attr1='a' />"
self.assertXMLEqual(xml1, xml2)
def test_simple_equal_with_leading_or_trailing_whitespace(self):
xml1 = "<elem>foo</elem> \t\n"
xml2 = " \t\n<elem>foo</elem>"
self.assertXMLEqual(xml1, xml2)
def test_simple_not_equal_with_whitespace_in_the_middle(self):
xml1 = "<elem>foo</elem><elem>bar</elem>"
xml2 = "<elem>foo</elem> <elem>bar</elem>"
self.assertXMLNotEqual(xml1, xml2)
class SkippingExtraTests(TestCase):
fixtures = ['should_not_be_loaded.json']