comparison tests/test_util.py @ 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 d96aa92d9ad9
children 8e621dbb82d4
comparison
equal deleted inserted replaced
620:8acae2416ec1 621:3e18cdcb6e00
296 self.assertEqual(ctx[dest].data(), data) 296 self.assertEqual(ctx[dest].data(), data)
297 if dest != source: 297 if dest != source:
298 copy = ctx[dest].renamed() 298 copy = ctx[dest].renamed()
299 self.assertEqual(copy[0], source) 299 self.assertEqual(copy[0], source)
300 300
301 def assertMultiLineEqual(self, first, second, msg=None):
302 """Assert that two multi-line strings are equal. (Based on Py3k code.)
303 """
304 self.assert_(isinstance(first, str),
305 ('First argument is not a string'))
306 self.assert_(isinstance(second, str),
307 ('Second argument is not a string'))
308
309 if first != second:
310 diff = ''.join(difflib.unified_diff(first.splitlines(True),
311 second.splitlines(True),
312 fromfile='a',
313 tofile='b'))
314 msg = '%s\n%s' % (msg or '', diff)
315 raise self.failureException, msg
316
301 def draw(self, repo): 317 def draw(self, repo):
302 """Helper function displaying a repository graph, especially 318 """Helper function displaying a repository graph, especially
303 useful when debugging comprehensive tests. 319 useful when debugging comprehensive tests.
304 """ 320 """
305 # Could be more elegant, but it works with stock hg 321 # Could be more elegant, but it works with stock hg