Back to index

python3.2  3.2.2
Classes | Functions
test.test_decorators Namespace Reference

Classes

class  MiscDecorators
class  DbcheckError
class  TestDecorators
class  TestClassDecorators

Functions

def funcattrs
def dbcheck
def countcalls
def memoize
def test_main

Function Documentation

Definition at line 40 of file test_decorators.py.

00040 
00041 def countcalls(counts):
00042     "Decorator to count calls to a function"
00043     def decorate(func):
00044         func_name = func.__name__
00045         counts[func_name] = 0
00046         def call(*args, **kwds):
00047             counts[func_name] += 1
00048             return func(*args, **kwds)
00049         call.__name__ = func_name
00050         return call
00051     return decorate
00052 
00053 # -----------------------------------------------

Here is the call graph for this function:

Here is the caller graph for this function:

def test.test_decorators.dbcheck (   exprstr,
  globals = None,
  locals = None 
)

Definition at line 27 of file test_decorators.py.

00027 
00028 def dbcheck(exprstr, globals=None, locals=None):
00029     "Decorator to implement debugging assertions"
00030     def decorate(func):
00031         expr = compile(exprstr, "dbcheck-%s" % func.__name__, "eval")
00032         def check(*args, **kwds):
00033             if not eval(expr, globals, locals):
00034                 raise DbcheckError(exprstr, func, args, kwds)
00035             return func(*args, **kwds)
00036         return check
00037     return decorate
00038 
00039 # -----------------------------------------------

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 4 of file test_decorators.py.

00004 
00005 def funcattrs(**kwds):
00006     def decorate(func):
00007         func.__dict__.update(kwds)
00008         return func
00009     return decorate

Here is the caller graph for this function:

Definition at line 54 of file test_decorators.py.

00054 
00055 def memoize(func):
00056     saved = {}
00057     def call(*args):
00058         try:
00059             return saved[args]
00060         except KeyError:
00061             res = func(*args)
00062             saved[args] = res
00063             return res
00064         except TypeError:
00065             # Unhashable argument
00066             return func(*args)
00067     call.__name__ = func.__name__
00068     return call
00069 
00070 # -----------------------------------------------

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 304 of file test_decorators.py.

00304 
00305 def test_main():
00306     support.run_unittest(TestDecorators)
00307     support.run_unittest(TestClassDecorators)