some tweaks to allow pypy apptests to use newinterpret
This commit is contained in:
		
							parent
							
								
									8f6477f695
								
							
						
					
					
						commit
						57a3d4d6d8
					
				| 
						 | 
				
			
			@ -60,21 +60,18 @@ def run(offending_line, frame=None):
 | 
			
		|||
        frame = py.code.Frame(sys._getframe(1))
 | 
			
		||||
    return interpret(offending_line, frame)
 | 
			
		||||
 | 
			
		||||
def getfailure(failure):
 | 
			
		||||
    explanation = util.format_explanation(failure.explanation)
 | 
			
		||||
    value = failure.cause[1]
 | 
			
		||||
def getfailure(e):
 | 
			
		||||
    explanation = util.format_explanation(e.explanation)
 | 
			
		||||
    value = e.cause[1]
 | 
			
		||||
    if str(value):
 | 
			
		||||
        lines = explanation.splitlines()
 | 
			
		||||
        if not lines:
 | 
			
		||||
            lines.append("")
 | 
			
		||||
        lines[0] += " << %s" % (value,)
 | 
			
		||||
        explanation = "\n".join(lines)
 | 
			
		||||
    text = "%s: %s" % (failure.cause[0].__name__, explanation)
 | 
			
		||||
    if text.startswith("AssertionError: assert "):
 | 
			
		||||
        lines = explanation.split('\n')
 | 
			
		||||
        lines[0] += "  << %s" % (e.value,)
 | 
			
		||||
        explanation = '\n'.join(lines)
 | 
			
		||||
    text = "%s: %s" % (e.cause[0].__name__, explanation)
 | 
			
		||||
    if text.startswith('AssertionError: assert '):
 | 
			
		||||
        text = text[16:]
 | 
			
		||||
    return text
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
operator_map = {
 | 
			
		||||
    ast.BitOr : "|",
 | 
			
		||||
    ast.BitXor : "^",
 | 
			
		||||
| 
						 | 
				
			
			@ -156,7 +153,7 @@ class DebugInterpreter(ast.NodeVisitor):
 | 
			
		|||
        except Exception:
 | 
			
		||||
            # have to assume it isn't
 | 
			
		||||
            local = False
 | 
			
		||||
        if not local:
 | 
			
		||||
        if not self.frame.is_true(local):
 | 
			
		||||
            return name.id, result
 | 
			
		||||
        return explanation, result
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -176,7 +173,7 @@ class DebugInterpreter(ast.NodeVisitor):
 | 
			
		|||
            except Exception:
 | 
			
		||||
                raise Failure(explanation)
 | 
			
		||||
            try:
 | 
			
		||||
                if not result:
 | 
			
		||||
                if not self.frame.is_true(result):
 | 
			
		||||
                    break
 | 
			
		||||
            except KeyboardInterrupt:
 | 
			
		||||
                raise
 | 
			
		||||
| 
						 | 
				
			
			@ -302,8 +299,8 @@ class DebugInterpreter(ast.NodeVisitor):
 | 
			
		|||
        try:
 | 
			
		||||
            from_instance = self.frame.eval(co, __exprinfo_expr=source_result)
 | 
			
		||||
        except Exception:
 | 
			
		||||
            from_instance = True
 | 
			
		||||
        if from_instance:
 | 
			
		||||
            from_instance = None
 | 
			
		||||
        if from_instance is None or self.frame.is_true(from_instance):
 | 
			
		||||
            rep = self.frame.repr(result)
 | 
			
		||||
            pattern = "%s\n{%s = %s\n}"
 | 
			
		||||
            explanation = pattern % (rep, rep, explanation)
 | 
			
		||||
| 
						 | 
				
			
			@ -312,10 +309,10 @@ class DebugInterpreter(ast.NodeVisitor):
 | 
			
		|||
    def visit_Assert(self, assrt):
 | 
			
		||||
        test_explanation, test_result = self.visit(assrt.test)
 | 
			
		||||
        if test_explanation.startswith("False\n{False =") and \
 | 
			
		||||
                test_explanation.endswith("\n"):
 | 
			
		||||
                test_explanation.endswith("\n}"):
 | 
			
		||||
            test_explanation = test_explanation[15:-2]
 | 
			
		||||
        explanation = "assert %s" % (test_explanation,)
 | 
			
		||||
        if not test_result:
 | 
			
		||||
        if not self.frame.is_true(test_result):
 | 
			
		||||
            try:
 | 
			
		||||
                raise BuiltinAssertionError
 | 
			
		||||
            except Exception:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue