File tree 3 files changed +29
-2
lines changed 3 files changed +29
-2
lines changed Original file line number Diff line number Diff line change 55
55
2.7.1.dev (compared to 2.7.0)
56
56
-----------------------------
57
57
58
+ - fix issue731: do not get confused by the braces which may be present
59
+ and unbalanced in an object's repr while collapsing False
60
+ explanations. Thanks Carl Meyer for the report and test case.
61
+
58
62
- fix issue553: properly handling inspect.getsourcelines failures in
59
63
FixtureLookupError which would lead to to an internal error,
60
64
obfuscating the original problem. Thanks talljosh for initial
Original file line number Diff line number Diff line change @@ -45,13 +45,15 @@ def _collapse_false(explanation):
45
45
if where == - 1 :
46
46
break
47
47
level = 0
48
+ prev_c = explanation [start ]
48
49
for i , c in enumerate (explanation [start :]):
49
- if c == "{" :
50
+ if prev_c + c == "\n {" :
50
51
level += 1
51
- elif c == "}" :
52
+ elif prev_c + c == "\n }" :
52
53
level -= 1
53
54
if not level :
54
55
break
56
+ prev_c = c
55
57
else :
56
58
raise AssertionError ("unbalanced braces: %r" % (explanation ,))
57
59
end = start + i
Original file line number Diff line number Diff line change @@ -663,3 +663,24 @@ def test_loader():
663
663
result .stdout .fnmatch_lines ([
664
664
"* 1 passed*" ,
665
665
])
666
+
667
+
668
+ def test_issue731 (testdir ):
669
+ testdir .makepyfile ("""
670
+ class LongReprWithBraces(object):
671
+ def __repr__(self):
672
+ return 'LongReprWithBraces({' + ('a' * 80) + '}' + ('a' * 120) + ')'
673
+
674
+ def some_method(self):
675
+ return False
676
+
677
+ def test_long_repr():
678
+ obj = LongReprWithBraces()
679
+ assert obj.some_method()
680
+ """ )
681
+ result = testdir .runpytest ()
682
+ assert 'unbalanced braces' not in result .stdout .str ()
683
+
684
+
685
+ def test_collapse_false_unbalanced_braces ():
686
+ util ._collapse_false ('some text{ False\n {False = some more text\n }' )
You can’t perform that action at this time.
0 commit comments