summaryrefslogtreecommitdiffstats
path: root/src/mock/trace_decorator.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/mock/trace_decorator.py')
-rwxr-xr-xsrc/mock/trace_decorator.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/mock/trace_decorator.py b/src/mock/trace_decorator.py
new file mode 100755
index 0000000..9e9b691
--- /dev/null
+++ b/src/mock/trace_decorator.py
@@ -0,0 +1,33 @@
+# vim:expandtab:autoindent:tabstop=4:shiftwidth=4:filetype=python:textwidth=0:
+
+import types
+from decorator import decorator
+
+import logging
+log = logging.getLogger("function_tracing")
+
+#@decorator
+@decorator
+def trace(f, *args, **kw):
+ log.debug("ENTER: %s(%s, %s)\n" % (f.func_name, args, kw))
+ try:
+ result = "Bad exception raised: Exception was not a derived class of 'Exception'"
+ try:
+ result = f(*args, **kw)
+ except Exception, e:
+ result = "EXCEPTION RAISED"
+ log.debug( "EXCEPTION: %s\n" % e, exc_info=1)
+ raise
+ finally:
+ log.debug( "LEAVE %s --> %s\n\n" % (f.func_name, result))
+
+ return result
+
+# helper function so we can use back-compat format but not be ugly
+def decorateAllFunctions(module):
+ methods = [ method for method in dir(module)
+ if isinstance(getattr(module, method), types.FunctionType)
+ ]
+ for i in methods:
+ setattr(module, i, trace(getattr(module,i)))
+