Kaydet (Commit) 2085d8d5 authored tarafından Mattia Larentis's avatar Mattia Larentis Kaydeden (comit) Tim Graham

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

Thanks Jacek Bzdak for indepdently contributing a similar fix.
üst 7862cbda
...@@ -234,6 +234,7 @@ answer newbie questions, and generally made Django that much better: ...@@ -234,6 +234,7 @@ answer newbie questions, and generally made Django that much better:
Fabrice Aneche <akh@nobugware.com> Fabrice Aneche <akh@nobugware.com>
favo@exoweb.net favo@exoweb.net
fdr <drfarina@gmail.com> fdr <drfarina@gmail.com>
Federico Capoano <nemesis@ninux.org>
Filip Noetzel <http://filip.noetzel.co.uk/> Filip Noetzel <http://filip.noetzel.co.uk/>
Filip Wasilewski <filip.wasilewski@gmail.com> Filip Wasilewski <filip.wasilewski@gmail.com>
Finn Gruwier Larsen <finn@gruwier.dk> Finn Gruwier Larsen <finn@gruwier.dk>
...@@ -483,6 +484,7 @@ answer newbie questions, and generally made Django that much better: ...@@ -483,6 +484,7 @@ answer newbie questions, and generally made Django that much better:
Matt McClanahan <http://mmcc.cx/> Matt McClanahan <http://mmcc.cx/>
Matt Riggott Matt Riggott
Matt Robenolt <m@robenolt.com> Matt Robenolt <m@robenolt.com>
Mattia Larentis <mattia@laretis.eu>
mattycakes@gmail.com mattycakes@gmail.com
Max Burstein <http://maxburstein.com> Max Burstein <http://maxburstein.com>
Max Derkachev <mderk@yandex.ru> Max Derkachev <mderk@yandex.ru>
......
...@@ -293,7 +293,7 @@ def compare_xml(want, got): ...@@ -293,7 +293,7 @@ def compare_xml(want, got):
"""Tries to do a 'xml-comparison' of want and got. Plain string """Tries to do a 'xml-comparison' of want and got. Plain string
comparison doesn't always work because, for example, attribute comparison doesn't always work because, for example, attribute
ordering should not be important. Comment nodes are not considered in the 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 Based on http://codespeak.net/svn/lxml/trunk/src/lxml/doctestcompare.py
""" """
...@@ -338,8 +338,8 @@ def compare_xml(want, got): ...@@ -338,8 +338,8 @@ def compare_xml(want, got):
return node return node
want, got = strip_quotes(want, got) want, got = strip_quotes(want, got)
want = want.replace('\\n', '\n') want = want.strip().replace('\\n', '\n')
got = got.replace('\\n', '\n') got = got.strip().replace('\\n', '\n')
# If the string is not a complete xml document, we may need to add a # 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/>" # root element. This allow us to compare fragments, like "<foo/><bar/>"
......
...@@ -753,6 +753,16 @@ class XMLEqualTests(SimpleTestCase): ...@@ -753,6 +753,16 @@ class XMLEqualTests(SimpleTestCase):
xml2 = "<?xml version='1.0'?><!-- comment2 --><elem attr2='b' attr1='a' />" xml2 = "<?xml version='1.0'?><!-- comment2 --><elem attr2='b' attr1='a' />"
self.assertXMLEqual(xml1, xml2) 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): class SkippingExtraTests(TestCase):
fixtures = ['should_not_be_loaded.json'] fixtures = ['should_not_be_loaded.json']
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment