Commits

Augie Fackler  committed 2148eb4

test_util: add assertStringEqual to output diff output for string checks

  • Participants
  • Parent commits 9e6499c

Comments (0)

Files changed (1)

File tests/test_util.py

 import StringIO
+import difflib
 import errno
 import gettext
 import imp
         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: