[svn r64007] port 64001-64004 to trunk

--HG--
branch : trunk
This commit is contained in:
fijal 2009-04-13 01:39:00 +02:00
parent 9c6e5aa7eb
commit ef63510f42
2 changed files with 14 additions and 0 deletions

View File

@ -13,6 +13,8 @@ class Frame(object):
self.raw = frame self.raw = frame
def statement(self): def statement(self):
if self.code.fullsource is None:
return py.code.Source("")
return self.code.fullsource.getstatement(self.lineno) return self.code.fullsource.getstatement(self.lineno)
statement = property(statement, None, None, statement = property(statement, None, None,
"statement this frame is at") "statement this frame is at")

View File

@ -9,6 +9,18 @@ def test_frame_getsourcelineno_myself():
source, lineno = f.code.fullsource, f.lineno source, lineno = f.code.fullsource, f.lineno
assert source[lineno].startswith(" return sys._getframe(0)") assert source[lineno].startswith(" return sys._getframe(0)")
def test_getstatement_empty_fullsource():
def func():
return sys._getframe(0)
f = func()
f = py.code.Frame(f)
prop = f.code.__class__.fullsource
try:
f.code.__class__.fullsource = None
assert f.statement == py.code.Source("")
finally:
f.code.__class__.fullsource = prop
def test_code_from_func(): def test_code_from_func():
co = py.code.Code(test_frame_getsourcelineno_myself) co = py.code.Code(test_frame_getsourcelineno_myself)
assert co.firstlineno assert co.firstlineno