Fixed #25191 -- Added string diff to SimpleTestCase.assertXMLEqual() message.

This commit is contained in:
Caio Ariede 2015-08-02 17:07:31 -03:00 committed by Tim Graham
parent c6c00fbfbb
commit 62d4074005
2 changed files with 20 additions and 0 deletions

View File

@ -784,6 +784,13 @@ class SimpleTestCase(unittest.TestCase):
else: else:
if not result: if not result:
standardMsg = '%s != %s' % (safe_repr(xml1, True), safe_repr(xml2, True)) 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)) self.fail(self._formatMessage(msg, standardMsg))
def assertXMLNotEqual(self, xml1, xml2, msg=None): def assertXMLNotEqual(self, xml1, xml2, msg=None):

View File

@ -710,6 +710,19 @@ class XMLEqualTests(SimpleTestCase):
with self.assertRaises(AssertionError): with self.assertRaises(AssertionError):
self.assertXMLEqual(xml1, xml2) 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): def test_simple_not_equal(self):
xml1 = "<elem attr1='a' attr2='c' />" xml1 = "<elem attr1='a' attr2='c' />"
xml2 = "<elem attr1='a' attr2='b' />" xml2 = "<elem attr1='a' attr2='b' />"