# HG changeset patch # User Dan Villiom Podlaski Christiansen # Date 1277236704 -7200 # Node ID 3e18cdcb6e00f3212d3f7d270e7acb494b7d04dc # Parent 8acae2416ec16d3e2a92d60dfae302adb6453b5b test_util: add assertMultiLineEqual() method. This method is based on code from the CPython py3k branch; it prints out a diff on failure. diff --git a/tests/test_util.py b/tests/test_util.py --- a/tests/test_util.py +++ b/tests/test_util.py @@ -298,6 +298,22 @@ class TestBase(unittest.TestCase): copy = ctx[dest].renamed() self.assertEqual(copy[0], source) + def assertMultiLineEqual(self, first, second, msg=None): + """Assert that two multi-line strings are equal. (Based on Py3k code.) + """ + self.assert_(isinstance(first, str), + ('First argument is not a string')) + self.assert_(isinstance(second, str), + ('Second argument is not a string')) + + if first != second: + diff = ''.join(difflib.unified_diff(first.splitlines(True), + second.splitlines(True), + fromfile='a', + tofile='b')) + msg = '%s\n%s' % (msg or '', diff) + raise self.failureException, msg + def draw(self, repo): """Helper function displaying a repository graph, especially useful when debugging comprehensive tests.