Fix collapse false to look at unescaped braces only

Sometimes the repr of an object can contain the "\n{" sequence which is
used as a formatting language, so they are escaped to "\\n{".  But the
collapse-false code needs to look for the real "\n{" token instead of
simply "{" as otherwise it may get unbalanced braces from the object's
repr (sometimes caused by the collapsing of long reprs by saferepr).

Fixes issue #731.

--HG--
branch : pytest-2.7
This commit is contained in:
Floris Bruynooghe
2015-04-30 02:31:12 +01:00
parent e94f5727c4
commit 7f554f50e3
3 changed files with 29 additions and 2 deletions

View File

@@ -665,3 +665,24 @@ class TestAssertionRewriteHookDetails(object):
result.stdout.fnmatch_lines([
"* 1 passed*",
])
def test_issue731(testdir):
testdir.makepyfile("""
class LongReprWithBraces(object):
def __repr__(self):
return 'LongReprWithBraces({' + ('a' * 80) + '}' + ('a' * 120) + ')'
def some_method(self):
return False
def test_long_repr():
obj = LongReprWithBraces()
assert obj.some_method()
""")
result = testdir.runpytest()
assert 'unbalanced braces' not in result.stdout.str()
def test_collapse_false_unbalanced_braces():
util._collapse_false('some text{ False\n{False = some more text\n}')