Escape newlines in repr for assertion rewriting

The assertion formatting mini-language depends on newlines being
escaped.  Unfortunately if the repr of an object contained
newlines the rewriting module did not escape those, which is now
fixed.

Fixes issue453.
This commit is contained in:
Floris Bruynooghe
2014-08-18 20:07:38 +02:00
parent 9232b88df3
commit 424479cf0f
3 changed files with 23 additions and 1 deletions

View File

@@ -313,6 +313,17 @@ class TestAssertionRewrite:
assert "%test" == "test"
assert getmsg(f).startswith("assert '%test' == 'test'")
def test_custom_repr(self):
def f():
class Foo(object):
a = 1
def __repr__(self):
return "\n{ \n~ \n}"
f = Foo()
assert 0 == f.a
assert r"where 1 = \n{ \n~ \n}.a" in util._format_lines([getmsg(f)])[0]
class TestRewriteOnImport: