Skip to content

Commit

Permalink
Fixed #25191 -- Added string diff to SimpleTestCase.assertXMLEqual() …
Browse files Browse the repository at this point in the history
…message.
  • Loading branch information
caioariede authored and timgraham committed Aug 4, 2015
1 parent c6c00fb commit 62d4074
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
7 changes: 7 additions & 0 deletions django/test/testcases.py
Expand Up @@ -784,6 +784,13 @@ def assertXMLEqual(self, xml1, xml2, msg=None):
else:
if not result:
standardMsg = '%s != %s' % (safe_repr(xml1, True), safe_repr(xml2, True))
diff = ('\n' + '\n'.join(
difflib.ndiff(
six.text_type(xml1).splitlines(),
six.text_type(xml2).splitlines(),
)
))
standardMsg = self._truncateMessage(standardMsg, diff)
self.fail(self._formatMessage(msg, standardMsg))

def assertXMLNotEqual(self, xml1, xml2, msg=None):
Expand Down
13 changes: 13 additions & 0 deletions tests/test_utils/tests.py
Expand Up @@ -710,6 +710,19 @@ def test_simple_equal_raise(self):
with self.assertRaises(AssertionError):
self.assertXMLEqual(xml1, xml2)

def test_simple_equal_raises_message(self):
xml1 = "<elem attr1='a' />"
xml2 = "<elem attr2='b' attr1='a' />"

msg = '''{xml1} != {xml2}
- <elem attr1='a' />
+ <elem attr2='b' attr1='a' />
? ++++++++++
'''.format(xml1=repr(xml1), xml2=repr(xml2))

with self.assertRaisesMessage(AssertionError, msg):
self.assertXMLEqual(xml1, xml2)

def test_simple_not_equal(self):
xml1 = "<elem attr1='a' attr2='c' />"
xml2 = "<elem attr1='a' attr2='b' />"
Expand Down

0 comments on commit 62d4074

Please sign in to comment.