diff options
| author | Mattia Larentis <mattia@larentis.eu> | 2015-11-07 14:31:25 +0100 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2015-11-09 15:53:30 -0500 |
| commit | 2085d8d5bc2625076983d3be14b30ea684c3f0d5 (patch) | |
| tree | f396ed6cf5ddfc8bbcf81169b7f0860ce9f23432 | |
| parent | 7862cbda86cdbced5fbfe4f0056105e657c1f92c (diff) | |
Fixed #25170 -- Made assertXMLEqual()/assertXMLNotEqual() ignore leading and trailing whitespace.
Thanks Jacek Bzdak for indepdently contributing a similar fix.
| -rw-r--r-- | AUTHORS | 2 | ||||
| -rw-r--r-- | django/test/utils.py | 6 | ||||
| -rw-r--r-- | tests/test_utils/tests.py | 10 |
3 files changed, 15 insertions, 3 deletions
@@ -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> diff --git a/django/test/utils.py b/django/test/utils.py index 95757dbf1b..e665ea1ec3 100644 --- a/django/test/utils.py +++ b/django/test/utils.py @@ -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/>" diff --git a/tests/test_utils/tests.py b/tests/test_utils/tests.py index 00c9c0fa2b..a495ff1010 100644 --- a/tests/test_utils/tests.py +++ b/tests/test_utils/tests.py @@ -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'] |
