changeset 621:3e18cdcb6e00

test_util: add assertMultiLineEqual() method. This method is based on code from the CPython py3k branch; it prints out a diff on failure.
author Dan Villiom Podlaski Christiansen <danchr@gmail.com>
date Tue, 22 Jun 2010 21:58:24 +0200
parents 8acae2416ec1
children 25714b4954b7
files tests/test_util.py
diffstat 1 files changed, 16 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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.