[py-svn] r18208 - in py/dist/py/magic: . testing
jan at codespeak.net
jan at codespeak.net
Thu Oct 6 02:13:11 CEST 2005
Author: jan
Date: Thu Oct 6 02:13:10 2005
New Revision: 18208
Modified:
py/dist/py/magic/exprinfo.py
py/dist/py/magic/testing/test_exprinfo.py
Log:
issue21
escape newlines in reinterpretations of assert statements
Modified: py/dist/py/magic/exprinfo.py
==============================================================================
--- py/dist/py/magic/exprinfo.py (original)
+++ py/dist/py/magic/exprinfo.py Thu Oct 6 02:13:10 2005
@@ -47,7 +47,15 @@
def nice_explanation(self):
# uck! See CallFunc for where \n{ and \n} escape sequences are used
- lines = (self.explanation or '').split('\n')
+ raw_lines = (self.explanation or '').split('\n')
+ # escape newlines not followed by { and }
+ lines = [raw_lines[0]]
+ for l in raw_lines[1:]:
+ if l.startswith('{') or l.startswith('}'):
+ lines.append(l)
+ else:
+ lines[-1] += '\\n' + l
+
result = lines[:1]
stack = [0]
stackcnt = [0]
Modified: py/dist/py/magic/testing/test_exprinfo.py
==============================================================================
--- py/dist/py/magic/testing/test_exprinfo.py (original)
+++ py/dist/py/magic/testing/test_exprinfo.py Thu Oct 6 02:13:10 2005
@@ -84,6 +84,17 @@
msg = getmsg(excinfo)
assert msg == 'assert 66 == 67\n + where 66 = global_f(v=11)'
+def test_interpretable_escapes_newlines():
+ class X(object):
+ def __repr__(self):
+ return '1\n2'
+ def g():
+ assert X() == 'XXX'
+
+ excinfo = getexcinfo(AssertionError, g)
+ msg = getmsg(excinfo)
+ assert msg == "assert 1\\n2 == 'XXX'\n + where 1\\n2 = <class 'py.__.magic.testing.test_exprinfo.X'>()"
+
def test_keyboard_interrupt():
# XXX this test is slightly strange because it is not
# clear that "interpret" should execute "raise" statements
More information about the pytest-commit
mailing list