﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
31250	assertXMLEqual() crashes on processing instructions.	Matt Fisher	Yuri Savin	"Similar bug to https://code.djangoproject.com/ticket/30497, so I've based this report on that one.

Prepare Django project:
{{{
$ python -m venv env
$ . ./env/bin/activate
$ pip install django
$ django-admin startproject p1
$ cd p1
}}}

Create p1/tests.py, with xml taken from [https://www.w3.org/TR/xml-model/#d0e679 W3 xml-model] and [https://www.w3.org/TR/2010/REC-xml-stylesheet-20101028/ W3 xml-stylesheet] examples:
{{{
from django.test import TestCase

class MyTestCase(TestCase):
    def test_assert_xml_equal_xml_model(self):
        xml1 = '''
            <?xml version=""1.0""?>
            <?xml-model href=""http://www.docbook.org/xml/5.0/rng/docbook.rng""?>
            <?xml-model href=""http://www.docbook.org/xml/5.0/xsd/docbook.xsd""?>
            <book xmlns=""http://docbook.org/ns/docbook"">
            </book>
        '''
        self.assertXMLEqual(xml1, xml1)

    def test_assert_xml_equal_stylesheet(self):
        xml = '''
            <?xml-stylesheet href=""common.css""?>
            <?xml-stylesheet href=""default.css"" title=""Default style""?>
            <?xml-stylesheet alternate=""yes"" href=""alt.css"" title=""Alternative style""?>
            <?xml-stylesheet href=""single-col.css"" media=""all and (max-width: 30em)""?>
            <html xmlns=""http://www.w3.org/1999/xhtml"">
                <head>
                    <title>Example with xml-stylesheet processing instructions</title>
                 </head>
                 <body>
                 </body>
            </html>
        '''
        self.assertXMLEqual(xml, xml)
}}}
Run the tests:
{{{
$ ./manage.py test
Creating test database for alias 'default'...
System check identified no issues (0 silenced).
FF
======================================================================
FAIL: test_assert_xml_equal_stylesheet (tests.MyTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "".../dev/django/env/lib/python3.7/site-packages/django/test/testcases.py"", line 843, in assertXMLEqual
    result = compare_xml(xml1, xml2)
  File "".../dev/django/env/lib/python3.7/site-packages/django/test/utils.py"", line 596, in compare_xml
    return check_element(want_root, got_root)
AttributeError: 'ProcessingInstruction' object has no attribute 'tagName'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "".../dev/django/p1/tests.py"", line 28, in test_assert_xml_equal_stylesheet
    self.assertXMLEqual(xml, xml)
  File "".../dev/django/env/lib/python3.7/site-packages/django/test/testcases.py"", line 846, in assertXMLEqual
    self.fail(self._formatMessage(msg, standardMsg))
AssertionError: First or second argument is not valid XML
'ProcessingInstruction' object has no attribute 'tagName'

======================================================================
FAIL: test_assert_xml_equal_xml_model (tests.MyTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "".../dev/django/env/lib/python3.7/site-packages/django/test/testcases.py"", line 843, in assertXMLEqual
    result = compare_xml(xml1, xml2)
  File "".../dev/django/env/lib/python3.7/site-packages/django/test/utils.py"", line 596, in compare_xml
    return check_element(want_root, got_root)
AttributeError: 'ProcessingInstruction' object has no attribute 'tagName'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "".../dev/django/p1/tests.py"", line 12, in test_assert_xml_equal_xml_model
    self.assertXMLEqual(xml1, xml1)
  File "".../dev/django/env/lib/python3.7/site-packages/django/test/testcases.py"", line 846, in assertXMLEqual
    self.fail(self._formatMessage(msg, standardMsg))
AssertionError: First or second argument is not valid XML
'ProcessingInstruction' object has no attribute 'tagName'

----------------------------------------------------------------------
Ran 2 tests in 0.007s

FAILED (failures=2)
Destroying test database for alias 'default'...
}}}

As discussed in [https://github.com/django/django/pull/11402 the PR for the previous fix], assertXMLEqual probably shouldn't compare what's outside the root, so ignoring `Node.PROCESSING_INSTRUCTION_NODE` in [https://github.com/django/django/blob/3.0.3/django/test/utils.py#L577-L580 first_node] would probably do the job (tests pass after this change)."	Bug	closed	Testing framework	dev	Normal	fixed			Ready for checkin	1	0	0	0	1	0
