From 117e99511e0985701780ed1bcd3afd456e244ae3 Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Sat, 6 Oct 2012 13:14:11 +0200 Subject: Added assertXML[Not]Equal assertions This is especially needed to compare XML when hash randomization is on, as attribute order may vary. Refs #17758, #19038. Thanks Taylor Mitchell for the initial patch, and Ian Clelland for review and cleanup. --- docs/releases/1.5.txt | 5 +++++ docs/topics/testing.txt | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+) (limited to 'docs') diff --git a/docs/releases/1.5.txt b/docs/releases/1.5.txt index d87ec36204..e99b2fd578 100644 --- a/docs/releases/1.5.txt +++ b/docs/releases/1.5.txt @@ -198,6 +198,11 @@ Django 1.5 also includes several smaller improvements worth noting: * The loaddata management command now supports an `ignorenonexistent` option to ignore data for fields that no longer exist. +* :meth:`~django.test.SimpleTestCase.assertXMLEqual` and + :meth:`~django.test.SimpleTestCase.assertXMLNotEqual` new assertions allow + you to test equality for XML content at a semantic level, without caring for + syntax differences (spaces, attribute order, etc.). + Backwards incompatible changes in 1.5 ===================================== diff --git a/docs/topics/testing.txt b/docs/topics/testing.txt index 3950e1c917..895e721ef5 100644 --- a/docs/topics/testing.txt +++ b/docs/topics/testing.txt @@ -1783,6 +1783,25 @@ your test suite. ``html1`` and ``html2`` must be valid HTML. An ``AssertionError`` will be raised if one of them cannot be parsed. +.. method:: SimpleTestCase.assertXMLEqual(xml1, xml2, msg=None) + + .. versionadded:: 1.5 + + Asserts that the strings ``xml1`` and ``xml2`` are equal. The + comparison is based on XML semantics. Similarily to + :meth:`~SimpleTestCase.assertHTMLEqual`, the comparison is + made on parsed content, hence only semantic differences are considered, not + syntax differences. When unvalid XML is passed in any parameter, an + ``AssertionError`` is always raised, even if both string are identical. + +.. method:: SimpleTestCase.assertXMLNotEqual(xml1, xml2, msg=None) + + .. versionadded:: 1.5 + + Asserts that the strings ``xml1`` and ``xml2`` are *not* equal. The + comparison is based on XML semantics. See + :meth:`~SimpleTestCase.assertXMLEqual` for details. + .. _topics-testing-email: Email services -- cgit v1.3