Opened 9 years ago
Closed 9 years ago
#25170 closed Bug (fixed)
assertXMLEqual fails when white space is present outside XML fragment
Reported by: | Sergiy Kuzmenko | Owned by: | Kamil Warguła |
---|---|---|---|
Component: | Testing framework | Version: | dev |
Severity: | Normal | Keywords: | test |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
Currently this test fails:
class MyTestCase(TestCase): def test_xml(self): self.assertXMLEqual('<greeting>hello</greeting>', '<greeting>hello</greeting>\n')
I believe this is a bug because white space outside root tag should not matter. It makes testing rather confusing when reading XML documents from files (which may or may not have trailing new line characters).
Change History (12)
comment:1 by , 9 years ago
Triage Stage: | Unreviewed → Accepted |
---|---|
Version: | 1.8 → master |
comment:2 by , 9 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:3 by , 9 years ago
At the time of analyzing the issue, I didn't notice that the issue is already assigned. Anyway, just because the fix seems so simple, and there is no pull request yet, I published my own solution as a PR.
The fixed branch is available here: https://github.com/mishunika/django/tree/ticket_25170
And the PR is here: https://github.com/django/django/pull/5049
comment:4 by , 9 years ago
I started working on this bug after assigned.
This is PR for this issue: https://github.com/django/django/pull/5052
Resolution of this bug is different then @mishunika.
comment:5 by , 9 years ago
Has patch: | set |
---|
comment:6 by , 9 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
comment:7 by , 9 years ago
Patch needs improvement: | set |
---|---|
Triage Stage: | Ready for checkin → Accepted |
comment:8 by , 9 years ago
Whitespace around tags is indeed siginificant --- technically following documents *are* different
<foo></foo>
and
<foo> </foo>
however for most practical purposes this difference is insignificant, as most of XML-based formats ignore whitespace altogether (like html). Despite that I think that in unittesting framework we should rather assume pessimistic case that whitespace does matter.
comment:9 by , 9 years ago
According to https://tools.ietf.org/html/rfc3470#section-4.16
In XML instances all white space is considered significant and is by default visible to processing applications
So, I think that @jbzdak is right.
comment:10 by , 9 years ago
Patch needs improvement: | unset |
---|
The fixed branch is available here: https://github.com/nostalgiaz/django/tree/pull_25170
And the PR is here: https://github.com/django/django/pull/5580
comment:11 by , 9 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
Contained white-space should really be considered significant in the HTML case.
If I remember correctly it affect display: inline
elements in some way (or it did in the past).
Stripping leading and trailing white space makes sense to me.
Seems reasonable as the docstring says "Whitespace in most cases is ignored".