summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryura <savin@nekidaem.ru>2020-02-12 13:38:06 +0300
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-02-13 11:03:54 +0100
commit54b7af7eb4107f933d14da0737b539bbe38d0fc8 (patch)
tree3fc611351603cc1e11f0913420fc642980860e1f
parent4070d6ceb055c35ca610629bd8f9604c0e530cf5 (diff)
Fixed #31250 -- Ignored processing instructions in assertXMLEqual()/assertXMLNotEqual().
-rw-r--r--django/test/utils.py10
-rw-r--r--docs/topics/testing/tools.txt4
-rw-r--r--tests/test_utils/tests.py15
3 files changed, 24 insertions, 5 deletions
diff --git a/django/test/utils.py b/django/test/utils.py
index 4dc1eac733..e626667b09 100644
--- a/django/test/utils.py
+++ b/django/test/utils.py
@@ -537,8 +537,8 @@ def compare_xml(want, got):
"""
Try 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. Ignore comment nodes, document type node, and leading and
- trailing whitespaces.
+ important. Ignore comment nodes, processing instructions, document type
+ node, and leading and trailing whitespaces.
Based on https://github.com/lxml/lxml/blob/master/src/lxml/doctestcompare.py
"""
@@ -576,7 +576,11 @@ def compare_xml(want, got):
def first_node(document):
for node in document.childNodes:
- if node.nodeType not in (Node.COMMENT_NODE, Node.DOCUMENT_TYPE_NODE):
+ if node.nodeType not in (
+ Node.COMMENT_NODE,
+ Node.DOCUMENT_TYPE_NODE,
+ Node.PROCESSING_INSTRUCTION_NODE,
+ ):
return node
want = want.strip().replace('\\n', '\n')
diff --git a/docs/topics/testing/tools.txt b/docs/topics/testing/tools.txt
index 59f36d44b8..02433bbf5e 100644
--- a/docs/topics/testing/tools.txt
+++ b/docs/topics/testing/tools.txt
@@ -1613,8 +1613,8 @@ your test suite.
syntax differences. When invalid XML is passed in any parameter, an
``AssertionError`` is always raised, even if both string are identical.
- XML declaration, document type, and comments are ignored. Only the root
- element and its children are compared.
+ XML declaration, document type, processing instructions, and comments are
+ ignored. Only the root element and its children are compared.
Output in case of error can be customized with the ``msg`` argument.
diff --git a/tests/test_utils/tests.py b/tests/test_utils/tests.py
index 8d7e6e4889..59f8ddd26b 100644
--- a/tests/test_utils/tests.py
+++ b/tests/test_utils/tests.py
@@ -926,6 +926,21 @@ class XMLEqualTests(SimpleTestCase):
xml2 = '<?xml version="1.0"?><!DOCTYPE root SYSTEM "example2.dtd"><root />'
self.assertXMLEqual(xml1, xml2)
+ def test_processing_instruction(self):
+ xml1 = (
+ '<?xml version="1.0"?>'
+ '<?xml-model href="http://www.example1.com"?><root />'
+ )
+ xml2 = (
+ '<?xml version="1.0"?>'
+ '<?xml-model href="http://www.example2.com"?><root />'
+ )
+ self.assertXMLEqual(xml1, xml2)
+ self.assertXMLEqual(
+ '<?xml-stylesheet href="style1.xslt" type="text/xsl"?><root />',
+ '<?xml-stylesheet href="style2.xslt" type="text/xsl"?><root />',
+ )
+
class SkippingExtraTests(TestCase):
fixtures = ['should_not_be_loaded.json']