handle comparison results which raise when asked for their truth value
This commit is contained in:
parent
f5decc90ca
commit
0bb84abca7
|
@ -25,7 +25,11 @@ def _format_boolop(operands, explanations, is_or):
|
|||
|
||||
def _call_reprcompare(ops, results, expls, each_obj):
|
||||
for i, res, expl in zip(range(len(ops)), results, expls):
|
||||
if not res:
|
||||
try:
|
||||
done = not res
|
||||
except Exception:
|
||||
done = True
|
||||
if done:
|
||||
break
|
||||
if py.code._reprcompare is not None:
|
||||
custom = py.code._reprcompare(ops[i], each_obj[i], each_obj[i + 1])
|
||||
|
|
|
@ -239,3 +239,17 @@ class TestAssertionRewrite:
|
|||
def f():
|
||||
assert 1 < 3 < 5 <= 4 < 7
|
||||
assert getmsg(f) == "assert 5 <= 4"
|
||||
|
||||
def test_assert_raising_nonzero_in_comparison(self):
|
||||
def f():
|
||||
class A(object):
|
||||
def __nonzero__(self):
|
||||
raise ValueError(42)
|
||||
def __lt__(self, other):
|
||||
return A()
|
||||
def __repr__(self):
|
||||
return "<MY42 object>"
|
||||
def myany(x):
|
||||
return False
|
||||
assert myany(A() < 0)
|
||||
assert "<MY42 object> < 0" in getmsg(f)
|
||||
|
|
Loading…
Reference in New Issue