changeset 548:2148eb4b4da4

test_util: add assertStringEqual to output diff output for string checks
author Augie Fackler <durin42@gmail.com>
date Sat, 06 Feb 2010 10:57:06 -0600
parents 9e6499c415a9
children b97f5734e5a8
files tests/test_util.py
diffstat 1 files changed, 12 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/tests/test_util.py
+++ b/tests/test_util.py
@@ -1,4 +1,5 @@
 import StringIO
+import difflib
 import errno
 import gettext
 import imp
@@ -180,6 +181,17 @@ class TestBase(unittest.TestCase):
         os.chdir(self.oldwd)
         setattr(ui.ui, self.patch[0].func_name, self.patch[0])
 
+    def assertStringEqual(self, l, r):
+        try:
+            self.assertEqual(l, r, 'failed string equality check, see stdout for details')
+        except:
+            add_nl = lambda li: map(lambda x: x+'\n', li)
+            print 'failed expectation:'
+            print ''.join(difflib.unified_diff(
+                add_nl(l.splitlines()), add_nl(r.splitlines()),
+                fromfile='expected', tofile='got'))
+            raise
+
     def _load_fixture_and_fetch(self, fixture_name, subdir=None, stupid=False, layout='auto'):
         if layout == 'single':
             if subdir is None: