Decorator to inject requirements into a function. The decorated function is called with a named argument for each specified requirement containing the exported instances.
(**requirements)
| 107 | |
| 108 | |
| 109 | def require(**requirements): |
| 110 | ''' Decorator to inject requirements into a function. |
| 111 | |
| 112 | The decorated function is called with a named argument for each |
| 113 | specified requirement containing the exported instances. |
| 114 | ''' |
| 115 | |
| 116 | exports = {name : Export.load(requirement) |
| 117 | for name, requirement |
| 118 | in requirements.iteritems()} |
| 119 | |
| 120 | def wrapper(func): |
| 121 | def wrapped(*args, **kwargs): |
| 122 | # Update the keyword arguments with the required instances |
| 123 | kwargs.update({name : export.instance |
| 124 | for name, export |
| 125 | in exports.iteritems() |
| 126 | if name not in kwargs}) |
| 127 | |
| 128 | return func(*args, |
| 129 | **kwargs) |
| 130 | |
| 131 | wrapped.__name__ = func.__name__ |
| 132 | |
| 133 | return wrapped |
| 134 | return wrapper |
| 135 | |
| 136 | |
| 137 |
no test coverage detected