defer a number of other compiles to frame.eval (patch from Amaury on trunk/pypy fork, thanks)
--HG-- branch : trunk
This commit is contained in:
parent
3b30c5b67a
commit
77a7d576ec
|
@ -37,10 +37,12 @@ Bug fixes / Maintenance
|
||||||
- fix issue105 assignment on the same line as a failing assertion
|
- fix issue105 assignment on the same line as a failing assertion
|
||||||
- fix issue104 proper escaping for test names in junitxml plugin
|
- fix issue104 proper escaping for test names in junitxml plugin
|
||||||
- fix issue57 -f|--looponfail to work with xpassing tests
|
- fix issue57 -f|--looponfail to work with xpassing tests
|
||||||
|
- fix py.code.compile(source) to generate unique filenames
|
||||||
|
- fix assertion re-interp problems on PyPy, by defering code
|
||||||
|
compilation to the (overridable) Frame.eval class.
|
||||||
- fix pyimport() to work with directories
|
- fix pyimport() to work with directories
|
||||||
- streamline py.path.local.mkdtemp implementation and usage
|
- streamline py.path.local.mkdtemp implementation and usage
|
||||||
- don't print empty lines when showing junitxml-filename
|
- don't print empty lines when showing junitxml-filename
|
||||||
- fix py.code.compile(source) to generate unique filenames
|
|
||||||
- add optional boolean ignore_errors parameter to py.path.local.remove
|
- add optional boolean ignore_errors parameter to py.path.local.remove
|
||||||
- fix terminal writing on win32/python2.4
|
- fix terminal writing on win32/python2.4
|
||||||
|
|
||||||
|
|
|
@ -138,28 +138,28 @@ class Name(Interpretable):
|
||||||
__view__ = ast.Name
|
__view__ = ast.Name
|
||||||
|
|
||||||
def is_local(self, frame):
|
def is_local(self, frame):
|
||||||
co = compile('%r in locals() is not globals()' % self.name, '?', 'eval')
|
source = '%r in locals() is not globals()' % self.name
|
||||||
try:
|
try:
|
||||||
return frame.is_true(frame.eval(co))
|
return frame.is_true(frame.eval(source))
|
||||||
except passthroughex:
|
except passthroughex:
|
||||||
raise
|
raise
|
||||||
except:
|
except:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def is_global(self, frame):
|
def is_global(self, frame):
|
||||||
co = compile('%r in globals()' % self.name, '?', 'eval')
|
source = '%r in globals()' % self.name
|
||||||
try:
|
try:
|
||||||
return frame.is_true(frame.eval(co))
|
return frame.is_true(frame.eval(source))
|
||||||
except passthroughex:
|
except passthroughex:
|
||||||
raise
|
raise
|
||||||
except:
|
except:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def is_builtin(self, frame):
|
def is_builtin(self, frame):
|
||||||
co = compile('%r not in locals() and %r not in globals()' % (
|
source = '%r not in locals() and %r not in globals()' % (
|
||||||
self.name, self.name), '?', 'eval')
|
self.name, self.name)
|
||||||
try:
|
try:
|
||||||
return frame.is_true(frame.eval(co))
|
return frame.is_true(frame.eval(source))
|
||||||
except passthroughex:
|
except passthroughex:
|
||||||
raise
|
raise
|
||||||
except:
|
except:
|
||||||
|
@ -187,7 +187,8 @@ class Compare(Interpretable):
|
||||||
expr.explanation, operation, expr2.explanation)
|
expr.explanation, operation, expr2.explanation)
|
||||||
source = "__exprinfo_left %s __exprinfo_right" % operation
|
source = "__exprinfo_left %s __exprinfo_right" % operation
|
||||||
try:
|
try:
|
||||||
self.result = frame.eval(source, __exprinfo_left=expr.result,
|
self.result = frame.eval(source,
|
||||||
|
__exprinfo_left=expr.result,
|
||||||
__exprinfo_right=expr2.result)
|
__exprinfo_right=expr2.result)
|
||||||
except passthroughex:
|
except passthroughex:
|
||||||
raise
|
raise
|
||||||
|
@ -234,14 +235,14 @@ for astclass, astpattern in {
|
||||||
class UnaryArith(Interpretable):
|
class UnaryArith(Interpretable):
|
||||||
__view__ = astclass
|
__view__ = astclass
|
||||||
|
|
||||||
def eval(self, frame, astpattern=astpattern,
|
def eval(self, frame, astpattern=astpattern):
|
||||||
co=compile(astpattern, '?', 'eval')):
|
|
||||||
expr = Interpretable(self.expr)
|
expr = Interpretable(self.expr)
|
||||||
expr.eval(frame)
|
expr.eval(frame)
|
||||||
self.explanation = astpattern.replace('__exprinfo_expr',
|
self.explanation = astpattern.replace('__exprinfo_expr',
|
||||||
expr.explanation)
|
expr.explanation)
|
||||||
try:
|
try:
|
||||||
self.result = frame.eval(co, __exprinfo_expr=expr.result)
|
self.result = frame.eval(astpattern,
|
||||||
|
__exprinfo_expr=expr.result)
|
||||||
except passthroughex:
|
except passthroughex:
|
||||||
raise
|
raise
|
||||||
except:
|
except:
|
||||||
|
@ -262,8 +263,7 @@ for astclass, astpattern in {
|
||||||
class BinaryArith(Interpretable):
|
class BinaryArith(Interpretable):
|
||||||
__view__ = astclass
|
__view__ = astclass
|
||||||
|
|
||||||
def eval(self, frame, astpattern=astpattern,
|
def eval(self, frame, astpattern=astpattern):
|
||||||
co=compile(astpattern, '?', 'eval')):
|
|
||||||
left = Interpretable(self.left)
|
left = Interpretable(self.left)
|
||||||
left.eval(frame)
|
left.eval(frame)
|
||||||
right = Interpretable(self.right)
|
right = Interpretable(self.right)
|
||||||
|
@ -272,7 +272,8 @@ for astclass, astpattern in {
|
||||||
.replace('__exprinfo_left', left .explanation)
|
.replace('__exprinfo_left', left .explanation)
|
||||||
.replace('__exprinfo_right', right.explanation))
|
.replace('__exprinfo_right', right.explanation))
|
||||||
try:
|
try:
|
||||||
self.result = frame.eval(co, __exprinfo_left=left.result,
|
self.result = frame.eval(astpattern,
|
||||||
|
__exprinfo_left=left.result,
|
||||||
__exprinfo_right=right.result)
|
__exprinfo_right=right.result)
|
||||||
except passthroughex:
|
except passthroughex:
|
||||||
raise
|
raise
|
||||||
|
@ -286,9 +287,10 @@ class CallFunc(Interpretable):
|
||||||
__view__ = ast.CallFunc
|
__view__ = ast.CallFunc
|
||||||
|
|
||||||
def is_bool(self, frame):
|
def is_bool(self, frame):
|
||||||
co = compile('isinstance(__exprinfo_value, bool)', '?', 'eval')
|
source = 'isinstance(__exprinfo_value, bool)'
|
||||||
try:
|
try:
|
||||||
return frame.is_true(frame.eval(co, __exprinfo_value=self.result))
|
return frame.is_true(frame.eval(source,
|
||||||
|
__exprinfo_value=self.result))
|
||||||
except passthroughex:
|
except passthroughex:
|
||||||
raise
|
raise
|
||||||
except:
|
except:
|
||||||
|
@ -335,9 +337,8 @@ class CallFunc(Interpretable):
|
||||||
if source.endswith(','):
|
if source.endswith(','):
|
||||||
source = source[:-1]
|
source = source[:-1]
|
||||||
source += ')'
|
source += ')'
|
||||||
co = compile(source, '?', 'eval')
|
|
||||||
try:
|
try:
|
||||||
self.result = frame.eval(co, **vars)
|
self.result = frame.eval(source, **vars)
|
||||||
except passthroughex:
|
except passthroughex:
|
||||||
raise
|
raise
|
||||||
except:
|
except:
|
||||||
|
@ -352,21 +353,20 @@ class Getattr(Interpretable):
|
||||||
def eval(self, frame):
|
def eval(self, frame):
|
||||||
expr = Interpretable(self.expr)
|
expr = Interpretable(self.expr)
|
||||||
expr.eval(frame)
|
expr.eval(frame)
|
||||||
co = compile('__exprinfo_expr.%s' % self.attrname, '?', 'eval')
|
source = '__exprinfo_expr.%s' % self.attrname
|
||||||
try:
|
try:
|
||||||
self.result = frame.eval(co, __exprinfo_expr=expr.result)
|
self.result = frame.eval(source, __exprinfo_expr=expr.result)
|
||||||
except passthroughex:
|
except passthroughex:
|
||||||
raise
|
raise
|
||||||
except:
|
except:
|
||||||
raise Failure(self)
|
raise Failure(self)
|
||||||
self.explanation = '%s.%s' % (expr.explanation, self.attrname)
|
self.explanation = '%s.%s' % (expr.explanation, self.attrname)
|
||||||
# if the attribute comes from the instance, its value is interesting
|
# if the attribute comes from the instance, its value is interesting
|
||||||
co = compile('hasattr(__exprinfo_expr, "__dict__") and '
|
source = ('hasattr(__exprinfo_expr, "__dict__") and '
|
||||||
'%r in __exprinfo_expr.__dict__' % self.attrname,
|
'%r in __exprinfo_expr.__dict__' % self.attrname)
|
||||||
'?', 'eval')
|
|
||||||
try:
|
try:
|
||||||
from_instance = frame.is_true(
|
from_instance = frame.is_true(
|
||||||
frame.eval(co, __exprinfo_expr=expr.result))
|
frame.eval(source, __exprinfo_expr=expr.result))
|
||||||
except passthroughex:
|
except passthroughex:
|
||||||
raise
|
raise
|
||||||
except:
|
except:
|
||||||
|
|
Loading…
Reference in New Issue