[Lldb-commits] [lldb] r117949 - /lldb/trunk/test/lldbtest.py
Johnny Chen
johnny.chen at apple.com
Mon Nov 1 13:35:01 PDT 2010
Author: johnny
Date: Mon Nov 1 15:35:01 2010
New Revision: 117949
URL: http://llvm.org/viewvc/llvm-project?rev=117949&view=rev
Log:
Replace the two call sites of inspect.getsource(obj) with a utility function
getsource_if_available(obj) which also handles the exception if it occurs.
Modified:
lldb/trunk/test/lldbtest.py
Modified: lldb/trunk/test/lldbtest.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lldbtest.py?rev=117949&r1=117948&r2=117949&view=diff
==============================================================================
--- lldb/trunk/test/lldbtest.py (original)
+++ lldb/trunk/test/lldbtest.py Mon Nov 1 15:35:01 2010
@@ -292,6 +292,17 @@
raise CalledProcessError(retcode, cmd)
return output
+def getsource_if_available(obj):
+ """
+ Return the text of the source code for an object if available. Otherwise,
+ a print representation is returned.
+ """
+ import inspect
+ try:
+ return inspect.getsource(obj)
+ except:
+ return repr(obj)
+
class TestBase(unittest2.TestCase):
"""
This abstract base class is meant to be subclassed. It provides default
@@ -536,8 +547,7 @@
"""
if callable(hook):
with recording(self, traceAlways) as sbuf:
- import inspect
- print >> sbuf, "Adding tearDown hook:", inspect.getsource(hook)
+ print >> sbuf, "Adding tearDown hook:", getsource_if_available(hook)
self.hooks.append(hook)
def tearDown(self):
@@ -547,8 +557,7 @@
# Check and run any hook functions.
for hook in self.hooks:
with recording(self, traceAlways) as sbuf:
- import inspect
- print >> sbuf, "Executing tearDown hook:", inspect.getsource(hook)
+ print >> sbuf, "Executing tearDown hook:", getsource_if_available(hook)
hook()
# Terminate the current process being debugged, if any.
More information about the lldb-commits
mailing list