Instead of printing the rewrite chain, append it to the assertion message.

parent 51666c36
...@@ -45,15 +45,25 @@ class RulesTestCase(unittest.TestCase): ...@@ -45,15 +45,25 @@ class RulesTestCase(unittest.TestCase):
for i, exp in enumerate(rewrite_chain[:-1]): for i, exp in enumerate(rewrite_chain[:-1]):
self.assertMultiLineEqual(str(rewrite(exp)), self.assertMultiLineEqual(str(rewrite(exp)),
str(rewrite_chain[i + 1])) str(rewrite_chain[i + 1]))
except AssertionError: # pragma: nocover except AssertionError as e: # pragma: nocover
print 'rewrite failed: "%s" -> "%s"' \ msg = e.args[0]
% (str(exp), str(rewrite_chain[i + 1]))
print 'rewrite chain index: %d' % i
print 'rewrite chain: ---'
for i, c in enumerate(rewrite_chain): msg += '-' * 30 + '\n'
print '%2d %s' % (i, str(c))
print '-' * 30 msg += 'rewrite failed: "%s" -> "%s"\n' \
% (str(exp), str(rewrite_chain[i + 1]))
msg += 'rewrite chain: ---\n'
chain = []
for j, c in enumerate(rewrite_chain):
if i == j:
chain.append('%2d %s <-- error' % (j, str(c)))
else:
chain.append('%2d %s' % (j, str(c)))
e.message = msg + '\n'.join(chain)
e.args = (e.message,) + e.args[1:]
raise raise
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment