some tweaks to allow pypy apptests to use newinterpret

This commit is contained in:
Benjamin Peterson 2011-06-12 17:07:49 -05:00
parent 8f6477f695
commit 57a3d4d6d8
1 changed files with 14 additions and 17 deletions

View File

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