From ef63510f4257e8db04ce14176ce84da34f47509f Mon Sep 17 00:00:00 2001 From: fijal Date: Mon, 13 Apr 2009 01:39:00 +0200 Subject: [PATCH] [svn r64007] port 64001-64004 to trunk --HG-- branch : trunk --- py/code/frame.py | 2 ++ py/code/testing/test_frame.py | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/py/code/frame.py b/py/code/frame.py index 221fcd72b..e56f83b71 100644 --- a/py/code/frame.py +++ b/py/code/frame.py @@ -13,6 +13,8 @@ class Frame(object): self.raw = frame def statement(self): + if self.code.fullsource is None: + return py.code.Source("") return self.code.fullsource.getstatement(self.lineno) statement = property(statement, None, None, "statement this frame is at") diff --git a/py/code/testing/test_frame.py b/py/code/testing/test_frame.py index edd49cdd0..e063a5a27 100644 --- a/py/code/testing/test_frame.py +++ b/py/code/testing/test_frame.py @@ -9,6 +9,18 @@ def test_frame_getsourcelineno_myself(): source, lineno = f.code.fullsource, f.lineno 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(): co = py.code.Code(test_frame_getsourcelineno_myself) assert co.firstlineno