[Django] #30497: assertXMLEqual chokes on document type declaration

7 views
Skip to first unread message

Django

unread,
May 22, 2019, 2:54:17 AM5/22/19
to django-...@googlegroups.com
#30497: assertXMLEqual chokes on document type declaration
---------------------------------------------+------------------------
Reporter: Yuri Kanivetsky | Owner: nobody
Type: Bug | Status: new
Component: Testing framework | Version: 2.2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
---------------------------------------------+------------------------
Prepare Django project:

{{{
$ python -m venv env
$ . ./env/bin/activate
$ pip install django
$ django-admin startproject p1
$ cd p1
}}}

Create `p1/tests.py`:

{{{
#!python
from django.test import TestCase

class MyTestCase(TestCase):
def test_assert_xml_equal(self):
xml1 = '''
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE example SYSTEM "example.dtd">
<root />
'''
xml2 = '''
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE example SYSTEM "example.dtd">
<root />
'''
self.assertXMLEqual(xml1, xml2)
}}}

Run the tests:

{{{
$ ./manage.py test
Creating test database for alias 'default'...
F
======================================================================
FAIL: test_assert_xml_equal (p1.tests.MyTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/yuri/_/1/env/lib/python3.7/site-
packages/django/test/testcases.py", line 843, in assertXMLEqual
result = compare_xml(xml1, xml2)
File "/home/yuri/_/1/env/lib/python3.7/site-
packages/django/test/utils.py", line 598, in compare_xml
return check_element(want_root, got_root)
AttributeError: 'DocumentType' object has no attribute 'tagName'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/yuri/_/1/p1/p1/tests.py", line 15, in test_assert_xml_equal
self.assertXMLEqual(xml1, xml2)
File "/home/yuri/_/1/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
'DocumentType' object has no attribute 'tagName'

----------------------------------------------------------------------
Ran 1 test in 0.002s

FAILED (failures=1)
Destroying test database for alias 'default'...
System check identified no issues (0 silenced).
}}}

That happens because `django.utils` expects first
[https://github.com/django/django/blob/2.2.1/django/test/utils.py#L595-L596
non-comment] element to be the
[https://github.com/django/django/blob/2.2.1/django/test/utils.py#L579-L582
root] element. Which is generally not the case.

--
Ticket URL: <https://code.djangoproject.com/ticket/30497>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
May 22, 2019, 2:57:29 AM5/22/19
to django-...@googlegroups.com
#30497: assertXMLEqual chokes on document type declaration
-----------------------------------+--------------------------------------

Reporter: Yuri Kanivetsky | Owner: nobody
Type: Bug | Status: new
Component: Testing framework | Version: 2.2
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------
Description changed by Yuri Kanivetsky:

Old description:

New description:

Prepare Django project:

{{{
$ python -m venv env
$ . ./env/bin/activate
$ pip install django
$ django-admin startproject p1
$ cd p1
}}}

Create `p1/tests.py`:

{{{
#!python
from django.test import TestCase

class MyTestCase(TestCase):
def test_assert_xml_equal(self):
xml1 = '''
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE root SYSTEM "example.dtd">


<root />
'''
xml2 = '''
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE root SYSTEM "example.dtd">
<root />
'''
self.assertXMLEqual(xml1, xml2)
}}}

Run the tests:

--

--
Ticket URL: <https://code.djangoproject.com/ticket/30497#comment:1>

Django

unread,
May 22, 2019, 4:10:28 AM5/22/19
to django-...@googlegroups.com
#30497: assertXMLEqual fails on document type declaration.
-----------------------------------+------------------------------------

Reporter: Yuri Kanivetsky | Owner: nobody
Type: Bug | Status: new
Component: Testing framework | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+------------------------------------
Changes (by felixxm):

* version: 2.2 => master
* stage: Unreviewed => Accepted


Comment:

Thanks for this report. We should probably omit `Node.DOCUMENT_TYPE_NODE`
when looking for a `root` element and compare document types separately.

--
Ticket URL: <https://code.djangoproject.com/ticket/30497#comment:2>

Django

unread,
May 22, 2019, 8:37:41 AM5/22/19
to django-...@googlegroups.com
#30497: assertXMLEqual fails on document type declaration.
-----------------------------------+---------------------------------------
Reporter: Yuri Kanivetsky | Owner: Caio Ariede
Type: Bug | Status: assigned

Component: Testing framework | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+---------------------------------------
Changes (by Caio Ariede):

* owner: nobody => Caio Ariede
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/30497#comment:3>

Django

unread,
May 22, 2019, 9:42:05 AM5/22/19
to django-...@googlegroups.com
#30497: assertXMLEqual fails on document type declaration.
-----------------------------------+---------------------------------------
Reporter: Yuri Kanivetsky | Owner: Caio Ariede
Type: Bug | Status: assigned
Component: Testing framework | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+---------------------------------------

Comment (by Caio Ariede):

PR: https://github.com/django/django/pull/11402

--
Ticket URL: <https://code.djangoproject.com/ticket/30497#comment:4>

Django

unread,
May 22, 2019, 1:24:21 PM5/22/19
to django-...@googlegroups.com
#30497: assertXMLEqual fails on document type declaration.
-----------------------------------+---------------------------------------
Reporter: Yuri Kanivetsky | Owner: Caio Ariede
Type: Bug | Status: assigned
Component: Testing framework | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+---------------------------------------
Changes (by felixxm):

* has_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/30497#comment:5>

Django

unread,
May 24, 2019, 2:24:16 AM5/24/19
to django-...@googlegroups.com
#30497: assertXMLEqual fails on document type declaration.
-----------------------------------+---------------------------------------
Reporter: Yuri Kanivetsky | Owner: Caio Ariede
Type: Bug | Status: closed

Component: Testing framework | Version: master
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+---------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"753b67c58de8021487af7cafa4241e8326aa5508" 753b67c]:
{{{
#!CommitTicketReference repository=""
revision="753b67c58de8021487af7cafa4241e8326aa5508"
Fixed #30497 -- Ignored document type in
assertXMLEqual()/assertXMLNotEqual().
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/30497#comment:6>

Reply all
Reply to author
Forward
0 new messages