Skip to content

Commit

Permalink
Merge pull request #4 from nimiq/master
Browse files Browse the repository at this point in the history
NEW Add wrapped function's original args and kwargs
  • Loading branch information
snelis committed Jan 26, 2016
2 parents c092276 + 3f2c505 commit d37d7e3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
30 changes: 30 additions & 0 deletions tests/test_time_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,33 @@ def go():

for metric in self._query_influx(go.fqn):
self.assertEqual(metric['exception_message'], 'test exception')

def test_time_execution_with_func_args(self):
param = 'foo'

def hook(response, exception, metric, func_args, func_kwargs):
self.assertEqual(func_args[0], param)
return metric

configure(backends=[self.backend], hooks=[hook])

@time_execution
def go(param1):
return '200 OK'

go(param)

def test_time_execution_with_func_kwargs(self):
param = 'foo'

def hook(response, exception, metric, func_args, func_kwargs):
self.assertEqual(func_kwargs['param1'], param)
return metric

configure(backends=[self.backend], hooks=[hook])

@time_execution
def go(param1):
return '200 OK'

go(param1=param)
4 changes: 3 additions & 1 deletion time_execution/time_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ def __call__(self, *args, **kwargs):
metadata = _apply_hooks(
response=response,
exception=exception,
metric=metric
metric=metric,
func_args=args,
func_kwargs=kwargs
)

metric.update(metadata)
Expand Down

0 comments on commit d37d7e3

Please sign in to comment.