MCPcopy Index your code
hub / github.com/RustPython/RustPython / assertMultiLineEqual

Method assertMultiLineEqual

Lib/unittest/case.py:1263–1296  ·  view source on GitHub ↗

Assert that two multi-line strings are equal.

(self, first, second, msg=None)

Source from the content-addressed store, hash-verified

1261 self.fail(msg)
1262
1263 def assertMultiLineEqual(self, first, second, msg=None):
1264 """Assert that two multi-line strings are equal."""
1265 self.assertIsInstance(first, str, "First argument is not a string")
1266 self.assertIsInstance(second, str, "Second argument is not a string")
1267
1268 if first != second:
1269 # Don't use difflib if the strings are too long
1270 if (len(first) > self._diffThreshold or
1271 len(second) > self._diffThreshold):
1272 self._baseAssertEqual(first, second, msg)
1273
1274 # Append \n to both strings if either is missing the \n.
1275 # This allows the final ndiff to show the \n difference. The
1276 # exception here is if the string is empty, in which case no
1277 # \n should be added
1278 first_presplit = first
1279 second_presplit = second
1280 if first and second:
1281 if first[-1] != '\n' or second[-1] != '\n':
1282 first_presplit += '\n'
1283 second_presplit += '\n'
1284 elif second and second[-1] != '\n':
1285 second_presplit += '\n'
1286 elif first and first[-1] != '\n':
1287 first_presplit += '\n'
1288
1289 firstlines = first_presplit.splitlines(keepends=True)
1290 secondlines = second_presplit.splitlines(keepends=True)
1291
1292 # Generate the message and diff, then raise the exception
1293 standardMsg = '%s != %s' % _common_shorten_repr(first, second)
1294 diff = '\n' + ''.join(difflib.ndiff(firstlines, secondlines))
1295 standardMsg = self._truncateMessage(standardMsg, diff)
1296 self.fail(self._formatMessage(msg, standardMsg))
1297
1298 def assertLess(self, a, b, msg=None):
1299 """Just like self.assertTrue(a < b), but with a nicer default message."""

Calls 9

assertIsInstanceMethod · 0.95
_baseAssertEqualMethod · 0.95
_truncateMessageMethod · 0.95
failMethod · 0.95
_formatMessageMethod · 0.95
lenFunction · 0.85
_common_shorten_reprFunction · 0.85
splitlinesMethod · 0.45
joinMethod · 0.45