'assertEqual with internal newlines collapsed to single, and
trailing whitespace removed.'

def assertEqualCollapsed(self, a, b):

    collapse = (lambda x: re.sub(u'\\n+', u'\n', x).rstrip())
    self.assertEqual(collapse(a), collapse(b))
