Kaydet (Commit) 62d40740 authored tarafından Caio Ariede's avatar Caio Ariede Kaydeden (comit) Tim Graham

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

üst c6c00fbf
...@@ -784,6 +784,13 @@ class SimpleTestCase(unittest.TestCase): ...@@ -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):
......
...@@ -710,6 +710,19 @@ class XMLEqualTests(SimpleTestCase): ...@@ -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' />"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment