diff options
author | Ronny Pfannschmidt <ronny.pfannschmidt@redhat.com> | 2016-07-06 11:51:48 +0200 |
---|---|---|
committer | Ronny Pfannschmidt <ronny.pfannschmidt@redhat.com> | 2016-07-06 11:51:48 +0200 |
commit | b9a91dc112efa64c5723912234e5ebd074821068 (patch) | |
tree | a921c30e533973381f76b8aba8d3bb11c269d41c /_pytest/assertion | |
parent | f31c31a73c4bfccf02589423e6c9f0d7175112b5 (diff) | |
parent | cc0920ceb105b832cef1aec6d4422226ffbaf473 (diff) | |
download | pytest-b9a91dc112efa64c5723912234e5ebd074821068.tar.gz |
merge from master to features
Diffstat (limited to '_pytest/assertion')
-rw-r--r-- | _pytest/assertion/rewrite.py | 5 | ||||
-rw-r--r-- | _pytest/assertion/util.py | 33 |
2 files changed, 5 insertions, 33 deletions
diff --git a/_pytest/assertion/rewrite.py b/_pytest/assertion/rewrite.py index 921d17a10..06944b016 100644 --- a/_pytest/assertion/rewrite.py +++ b/_pytest/assertion/rewrite.py @@ -1,6 +1,7 @@ """Rewrite assertion AST to produce nice error messages""" import ast +import _ast import errno import itertools import imp @@ -876,6 +877,8 @@ class AssertionRewriter(ast.NodeVisitor): def visit_Compare(self, comp): self.push_format_context() left_res, left_expl = self.visit(comp.left) + if isinstance(comp.left, (_ast.Compare, _ast.BoolOp)): + left_expl = "({0})".format(left_expl) res_variables = [self.variable() for i in range(len(comp.ops))] load_names = [ast.Name(v, ast.Load()) for v in res_variables] store_names = [ast.Name(v, ast.Store()) for v in res_variables] @@ -885,6 +888,8 @@ class AssertionRewriter(ast.NodeVisitor): results = [left_res] for i, op, next_operand in it: next_res, next_expl = self.visit(next_operand) + if isinstance(next_operand, (_ast.Compare, _ast.BoolOp)): + next_expl = "({0})".format(next_expl) results.append(next_res) sym = binop_map[op.__class__] syms.append(ast.Str(sym)) diff --git a/_pytest/assertion/util.py b/_pytest/assertion/util.py index 8bf425caf..2481cf34c 100644 --- a/_pytest/assertion/util.py +++ b/_pytest/assertion/util.py @@ -38,44 +38,11 @@ def format_explanation(explanation): displaying diffs. """ explanation = ecu(explanation) - explanation = _collapse_false(explanation) lines = _split_explanation(explanation) result = _format_lines(lines) return u('\n').join(result) -def _collapse_false(explanation): - """Collapse expansions of False - - So this strips out any "assert False\n{where False = ...\n}" - blocks. - """ - where = 0 - while True: - start = where = explanation.find("False\n{False = ", where) - if where == -1: - break - level = 0 - prev_c = explanation[start] - for i, c in enumerate(explanation[start:]): - if prev_c + c == "\n{": - level += 1 - elif prev_c + c == "\n}": - level -= 1 - if not level: - break - prev_c = c - else: - raise AssertionError("unbalanced braces: %r" % (explanation,)) - end = start + i - where = end - if explanation[end - 1] == '\n': - explanation = (explanation[:start] + explanation[start+15:end-1] + - explanation[end+1:]) - where -= 17 - return explanation - - def _split_explanation(explanation): """Return a list of individual lines in the explanation |