コード例 #1
0
ファイル: newinterpret.py プロジェクト: blockspacer/xtok
    def visit_Compare(self, comp):
        left = comp.left
        left_explanation, left_result = self.visit(left)
        for op, next_op in zip(comp.ops, comp.comparators):
            next_explanation, next_result = self.visit(next_op)
            op_symbol = operator_map[op.__class__]
            explanation = "%s %s %s" % (left_explanation, op_symbol,
                                        next_explanation)
            source = "__exprinfo_left %s __exprinfo_right" % (op_symbol,)
            co = self._compile(source)
            try:
                result = self.frame.eval(co, __exprinfo_left=left_result,
                                         __exprinfo_right=next_result)
            except Exception:
                raise Failure(explanation)
            try:
                if not self.frame.is_true(result):
                    break
            except KeyboardInterrupt:
                raise
            except:
                break
            left_explanation, left_result = next_explanation, next_result

        if util._reprcompare is not None:
            res = util._reprcompare(op_symbol, left_result, next_result)
            if res:
                explanation = res
        return explanation, result
コード例 #2
0
 def format_diff(self) -> str:
     # Pytest internal pretty comparison magic
     from _pytest.assertion import util
     compare_result = util._reprcompare('==', self._test_obj,
                                        self._canon_obj)
     verbose = self._context._request.config.getoption('verbose') > 0
     add_test_name = '' if verbose else f'[{self._context._nodeid}]\n'
     return f'{add_test_name}{compare_result}'
コード例 #3
0
def _call_reprcompare(ops, results, expls, each_obj):
    for i, res, expl in zip(range(len(ops)), results, expls):
        try:
            done = not res
        except Exception:
            done = True
        if done:
            break
    if util._reprcompare is not None:
        custom = util._reprcompare(ops[i], each_obj[i], each_obj[i + 1])
        if custom is not None:
            return custom
    return expl
コード例 #4
0
ファイル: rewrite.py プロジェクト: Don-Tan/pypy
def _call_reprcompare(ops, results, expls, each_obj):
    for i, res, expl in zip(range(len(ops)), results, expls):
        try:
            done = not res
        except Exception:
            done = True
        if done:
            break
    if util._reprcompare is not None:
        custom = util._reprcompare(ops[i], each_obj[i], each_obj[i + 1])
        if custom is not None:
            return custom
    return expl