Merged in tomviner/pytest/format_boolop_percent6 (pull request #231)
fix for issue #615: _format_boolop must escape %
This commit is contained in:
commit
1d15bb2880
1
AUTHORS
1
AUTHORS
|
@ -45,3 +45,4 @@ Andy Freeland
|
||||||
Trevor Bekolay
|
Trevor Bekolay
|
||||||
David Mohr
|
David Mohr
|
||||||
Nicolas Delaby
|
Nicolas Delaby
|
||||||
|
Tom Viner
|
||||||
|
|
|
@ -382,7 +382,12 @@ def _should_repr_global_name(obj):
|
||||||
return not hasattr(obj, "__name__") and not py.builtin.callable(obj)
|
return not hasattr(obj, "__name__") and not py.builtin.callable(obj)
|
||||||
|
|
||||||
def _format_boolop(explanations, is_or):
|
def _format_boolop(explanations, is_or):
|
||||||
return "(" + (is_or and " or " or " and ").join(explanations) + ")"
|
explanation = "(" + (is_or and " or " or " and ").join(explanations) + ")"
|
||||||
|
if py.builtin._istext(explanation):
|
||||||
|
t = py.builtin.text
|
||||||
|
else:
|
||||||
|
t = py.builtin.bytes
|
||||||
|
return explanation.replace(t('%'), t('%%'))
|
||||||
|
|
||||||
def _call_reprcompare(ops, results, expls, each_obj):
|
def _call_reprcompare(ops, results, expls, each_obj):
|
||||||
for i, res, expl in zip(range(len(ops)), results, expls):
|
for i, res, expl in zip(range(len(ops)), results, expls):
|
||||||
|
|
|
@ -270,15 +270,13 @@ class TestAssertionRewrite:
|
||||||
assert not 5 % 4
|
assert not 5 % 4
|
||||||
assert getmsg(f) == "assert not (5 % 4)"
|
assert getmsg(f) == "assert not (5 % 4)"
|
||||||
|
|
||||||
@pytest.mark.xfail(reason='unfixed')
|
def test_boolop_percent(self):
|
||||||
def test_and_or_percent(self):
|
|
||||||
# issue 615 - ValueError on compound assert with percent
|
|
||||||
def f():
|
def f():
|
||||||
assert 3 % 2 or False
|
assert 3 % 2 and False
|
||||||
assert getmsg(f) == "assert (3 % 2) or False"
|
assert getmsg(f) == "assert ((3 % 2) and False)"
|
||||||
def f():
|
def f():
|
||||||
assert True and 7 % 3
|
assert False or 4 % 2
|
||||||
assert getmsg(f) == "assert True and (7 % 3)"
|
assert getmsg(f) == "assert (False or (4 % 2))"
|
||||||
|
|
||||||
def test_call(self):
|
def test_call(self):
|
||||||
def g(a=42, *args, **kwargs):
|
def g(a=42, *args, **kwargs):
|
||||||
|
|
Loading…
Reference in New Issue