Commit ebfb2f46 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

Add test utility to count calls to function

In some cases it's nice to verify a function has been called exactly N
times. This is going to be used in tests for remote commands.
Signed-off-by: default avatarMichael Hanselmann <>
Reviewed-by: default avatarIustin Pop <>
parent ecd11bb0
......@@ -223,3 +223,32 @@ def UnifyValueType(data):
for (key, value) in data.iteritems()])
return data
class CallCounter(object):
"""Utility class to count number of calls to a function/method.
def __init__(self, fn):
"""Initializes this class.
@type fn: Callable
self._fn = fn
self._count = 0
def __call__(self, *args, **kwargs):
"""Calls wrapped function with given parameters.
self._count += 1
return self._fn(*args, **kwargs)
def Count(self):
"""Returns number of calls.
@rtype: number
return self._count
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment