Wrap a function to detect and flag when it gets called. This is a decorator which takes a function and wraps it in a function with a 'called' attribute. wrapper.called is initialized to False. The wrapper.called attribute is set to False right before each call to the wrapped functi
(func)
| 22 | #----------------------------------------------------------------------------- |
| 23 | |
| 24 | def flag_calls(func): |
| 25 | """Wrap a function to detect and flag when it gets called. |
| 26 | |
| 27 | This is a decorator which takes a function and wraps it in a function with |
| 28 | a 'called' attribute. wrapper.called is initialized to False. |
| 29 | |
| 30 | The wrapper.called attribute is set to False right before each call to the |
| 31 | wrapped function, so if the call fails it remains False. After the call |
| 32 | completes, wrapper.called is set to True and the output is returned. |
| 33 | |
| 34 | Testing for truth in wrapper.called allows you to determine if a call to |
| 35 | func() was attempted and succeeded.""" |
| 36 | |
| 37 | # don't wrap twice |
| 38 | if hasattr(func, 'called'): |
| 39 | return func |
| 40 | |
| 41 | def wrapper(*args,**kw): |
| 42 | wrapper.called = False |
| 43 | out = func(*args,**kw) |
| 44 | wrapper.called = True |
| 45 | return out |
| 46 | |
| 47 | wrapper.called = False |
| 48 | wrapper.__doc__ = func.__doc__ |
| 49 | return wrapper |
| 50 | |
| 51 | def undoc(func): |
| 52 | """Mark a function or class as undocumented. |
no outgoing calls
no test coverage detected